summaryrefslogtreecommitdiff
path: root/src/leap/common
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2013-08-14 22:35:45 +0200
committerKali Kaneko <kali@leap.se>2013-08-14 22:35:45 +0200
commitfa530521c4d1d2b86481753058983d516155057d (patch)
tree0ee1bd3ec08cc0dbb4f91b0c933520c6388f60fb /src/leap/common
parent0e721b1b47c3b94f6d4d6709e34b6b816f9fd810 (diff)
parent85e00e17ab54af7f26d3c2c51e4bd72f8cc9b778 (diff)
Merge remote-tracking branch 'chiiph-github/bug/ensure_server_async' into develop
Diffstat (limited to 'src/leap/common')
-rw-r--r--src/leap/common/events/server.py28
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):
"""