diff options
author | micah <micah@riseup.net> | 2013-08-27 08:28:42 -0700 |
---|---|---|
committer | micah <micah@riseup.net> | 2013-08-27 08:28:42 -0700 |
commit | cc9578338f5af84672d4ac672a4e6a6dd9f23c00 (patch) | |
tree | ef55d71cbda7a6d6ef178bd7f6cc5a1bb9e38bd7 /src/leap/common/events/server.py | |
parent | 9070d74a47158f5749c5e16b8d9d9e62a55d07df (diff) | |
parent | aef677558b3aab7e0c69ed7bc318cabad841e245 (diff) |
Merge pull request #61 from kalikaneko/debian-0.3.1
Debian 0.3.1
Diffstat (limited to 'src/leap/common/events/server.py')
-rw-r--r-- | src/leap/common/events/server.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/leap/common/events/server.py b/src/leap/common/events/server.py index 59f3454..861cb4f 100644 --- a/src/leap/common/events/server.py +++ b/src/leap/common/events/server.py @@ -77,18 +77,32 @@ def ensure_server(port=SERVER_PORT): s.connect(('localhost', port)) s.close() # port is taken, check if there's a server running there - response = ping(port) - if response is not None and response.status == proto.EventResponse.OK: - logger.info('A server is already running on port %d.', port) - return None - # port is taken, and not by an events server - logger.info('Port %d is taken by something not an events server.', port) - raise PortAlreadyTaken(port) + ping(port, + reqcbk=lambda req, res: process_ping(port, req, res), + timeout=10) 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.info('Port %d is taken by something not an events server.', port) + raise PortAlreadyTaken(port) + def ping(port=SERVER_PORT, reqcbk=None, timeout=1000): """ |