Skip to content
Snippets Groups Projects
Commit e7697c16 authored by Antoine Millet's avatar Antoine Millet
Browse files

[bug#3961] New argument appeared to set a global call timeout.

parent 4c01cecf
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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 '<RpcConnection object>'
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment