Commit f13a050d authored by Antoine Millet's avatar Antoine Millet

Added connection timeout to the RPC socket (default 30s).

parent 9a9c114f
......@@ -26,7 +26,7 @@ class SimpleRpcClient(ConnectionManager):
self.register(self._connection)
@classmethod
def from_addr(cls, addr, port, enable_ssl=False, cert=None,
def from_addr(cls, addr, port, enable_ssl=False, cert=None, timeout=30.0,
default_handler=None, on_disconnect=None):
'''
Construct the instance of :class:`SimpleRpcClient` without providing
......@@ -45,7 +45,7 @@ class SimpleRpcClient(ConnectionManager):
disconnects.
'''
connection = RpcConnection.from_addr(addr, port, None,
connection = RpcConnection.from_addr(addr, port, None, timeout=timeout,
enable_ssl=enable_ssl, cert=cert)
client = cls(connection, default_handler=default_handler,
on_disconnect=on_disconnect)
......
......@@ -57,7 +57,7 @@ class RpcConnection(object):
self._manager = manager
@classmethod
def from_addr(cls, addr, port, manager, enable_ssl=False,
def from_addr(cls, addr, port, manager, enable_ssl=False, timeout=30.0,
cert=None, handler=None):
'''
Construct the instance of :class:`RpcConnection` without providing
......@@ -79,6 +79,7 @@ class RpcConnection(object):
req = ssl.CERT_NONE if cert is None else ssl.CERT_REQUIRED
sock = ssl.wrap_socket(sock, certfile=None, cert_reqs=req,
ssl_version=ssl.PROTOCOL_TLSv1)
sock.settimeout(timeout)
sock.connect((addr, port))
sock.setblocking(False)
return cls(sock, manager, handler)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment