From e7697c1659b8c4c03b78da8c2bb0445a834d1f79 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Mon, 14 Feb 2011 13:56:06 +0100 Subject: [PATCH] [bug#3961] New argument appeared to set a global call timeout. --- sjrpc/client/simple.py | 7 +++++-- sjrpc/core/rpcconnection.py | 17 +++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/sjrpc/client/simple.py b/sjrpc/client/simple.py index 2a54135..ad6cfed 100644 --- a/sjrpc/client/simple.py +++ b/sjrpc/client/simple.py @@ -25,8 +25,8 @@ class SimpleRpcClient(ConnectionManager): self.register(self._connection) @classmethod - def from_addr(cls, addr, port, enable_ssl=False, cert=None, timeout=30.0, - default_handler=None, on_disconnect=None): + def from_addr(cls, addr, port, enable_ssl=False, cert=None, timeout=None, + conn_timeout=30.0, default_handler=None, on_disconnect=None): ''' Construct the instance of :class:`SimpleRpcClient` without providing the :class:`RpcConnection` object. The :class:`RpcConnection` is @@ -36,6 +36,8 @@ class SimpleRpcClient(ConnectionManager): :param addr: the target ip address :param port: the target port :param ssl: enable SSL + :param timeout: the global call timeout setting + :param conn_timeout: the connection operation timeout :param cert: is SSL is enabled, profile the filename of certificate to check. If None, don't check certificate. :param default_handler: the default handler to bind to the @@ -45,6 +47,7 @@ class SimpleRpcClient(ConnectionManager): ''' connection = RpcConnection.from_addr(addr, port, None, timeout=timeout, + conn_timeout=conn_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 679196e..43185bb 100644 --- a/sjrpc/core/rpcconnection.py +++ b/sjrpc/core/rpcconnection.py @@ -29,7 +29,7 @@ class RpcConnection(object): REQUEST_MESSAGE = {'id': None, 'method': None, 'args': [], 'kwargs': {}} RESPONSE_MESSAGE = {'id': None, 'return': None, 'error': None} - def __init__(self, sock, manager, handler=None): + def __init__(self, sock, manager, handler=None, timeout=None): # Sock of this connection: self._sock = sock @@ -58,9 +58,12 @@ class RpcConnection(object): # Is the RpcConnection connected to its peer: self._connected = True + # The global call timeout setting: + self._call_timeout = timeout + @classmethod - def from_addr(cls, addr, port, manager, enable_ssl=False, timeout=30.0, - cert=None, handler=None): + def from_addr(cls, addr, port, manager, enable_ssl=False, timeout=None, + conn_timeout=30.0,cert=None, handler=None): ''' Construct the instance of :class:`RpcConnection` without providing the :class:`socket` object. Socket is automatically created and passed @@ -70,6 +73,8 @@ class RpcConnection(object): :param port: the target port :param manager: manager of this connection :param enable_ssl: enable SSL + :param timeout: the global call timeout setting + :param conn_timeout: the connection operation timeout :param cert: is SSL is enabled, profile the filename of certificate to check. If None, don't check certificate. :param handler: Handler to attach to this :class:`RpcConnection` object @@ -81,10 +86,10 @@ 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.settimeout(conn_timeout) sock.connect((addr, port)) sock.setblocking(False) - return cls(sock, manager, handler) + return cls(sock, manager, handler, timeout=timeout) def __repr__(self): return '' @@ -261,7 +266,7 @@ class RpcConnection(object): timeout = kwargs['_timeout'] del kwargs['_timeout'] else: - timeout = None + timeout = self._call_timeout # Send the call to the peer: msg_id = self._send_call(method_name, *args, **kwargs) -- GitLab