Commit 322e1128 authored by Antoine Millet's avatar Antoine Millet

Calls now raise an exception if RpcConnection is disconnected from its peer.

parent 554b242b
...@@ -55,6 +55,9 @@ class RpcConnection(object): ...@@ -55,6 +55,9 @@ class RpcConnection(object):
# The manager of this connection # The manager of this connection
self._manager = manager self._manager = manager
# Is the RpcConnection connected to its peer:
self._connected = True
@classmethod @classmethod
def from_addr(cls, addr, port, manager, enable_ssl=False, timeout=30.0, def from_addr(cls, addr, port, manager, enable_ssl=False, timeout=30.0,
cert=None, handler=None): cert=None, handler=None):
...@@ -163,6 +166,9 @@ class RpcConnection(object): ...@@ -163,6 +166,9 @@ class RpcConnection(object):
Message must be a jsonisable structure. Message must be a jsonisable structure.
''' '''
if not self._connected:
raise RpcError('SendError', 'disconnected from the peer')
logging.debug('Sending: %s', message) logging.debug('Sending: %s', message)
json_msg = json.dumps(message) json_msg = json.dumps(message)
size = struct.pack('!L', len(json_msg)) size = struct.pack('!L', len(json_msg))
...@@ -373,6 +379,8 @@ class RpcConnection(object): ...@@ -373,6 +379,8 @@ class RpcConnection(object):
:type callback: :class:`str` or callable or None :type callback: :class:`str` or callable or None
''' '''
self._connected = False
try: try:
self._sock.close() self._sock.close()
except socket.error as err: except socket.error as err:
......
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