From f13a050d3976863b3f0c447f133a9457580038a5 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Mon, 27 Dec 2010 12:06:11 +0100 Subject: [PATCH] Added connection timeout to the RPC socket (default 30s). --- sjrpc/client/simple.py | 4 ++-- sjrpc/core/rpcconnection.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sjrpc/client/simple.py b/sjrpc/client/simple.py index efa8bf5..54bf61a 100644 --- a/sjrpc/client/simple.py +++ b/sjrpc/client/simple.py @@ -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) diff --git a/sjrpc/core/rpcconnection.py b/sjrpc/core/rpcconnection.py index c5b1daa..daa290e 100644 --- a/sjrpc/core/rpcconnection.py +++ b/sjrpc/core/rpcconnection.py @@ -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) -- GitLab