diff options
author | drebs <drebs@leap.se> | 2013-09-09 11:13:54 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2013-09-09 11:15:04 -0300 |
commit | ceff819d433764c303df42c00b0271084e414e4d (patch) | |
tree | 3e8692aa9363d7d01f4c714ee2f86411e284e184 /src/leap | |
parent | f25e9af5a9f5689fdc4b3ff009d20736ea5517d3 (diff) |
Fix events exception raising when ensuring server. Closes #3515.
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/common/events/server.py | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/src/leap/common/events/server.py b/src/leap/common/events/server.py index dc55551..41aede3 100644 --- a/src/leap/common/events/server.py +++ b/src/leap/common/events/server.py @@ -77,34 +77,20 @@ def ensure_server(port=SERVER_PORT): s.connect(('localhost', port)) s.close() # port is taken, check if there's a server running there - ping(port, - reqcbk=lambda req, res: process_ping(port, req, res), - timeout=10) + response = ping(port=port, timeout=1000) + if response is not None and response.status == proto.EventResponse.OK: + logger.info('A server is already running on port %d.', port) + return + # port is taken, and not by an events server + logger.warning( + 'Port %d is taken by something not an events server.', port) + raise PortAlreadyTaken(port) except socket.error: # port is available, run a server logger.info('Launching server on port %d.', port) return EventsServerDaemon.ensure(port) -def process_ping(port, request, response): - """ - Response callback for the ping event. - - :param port: Port that is trying to be used - :type port: int - :param request: Ping request made - :type request: proto.PingRequest - :param response: Response from the event - :type response: proto.EventResponse - """ - if response is not None and response.status == proto.EventResponse.OK: - logger.info('A server is already running on port %d.', port) - return - # port is taken, and not by an events server - logger.warning('Port %d is taken by something not an events server.', port) - raise PortAlreadyTaken(port) - - def ping(port=SERVER_PORT, reqcbk=None, timeout=1000): """ Ping the server. |