From 322e112855c65f5bee46cbd367a8a9b5516e0a04 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Tue, 8 Feb 2011 13:07:06 +0100 Subject: [PATCH] Calls now raise an exception if RpcConnection is disconnected from its peer. --- sjrpc/core/rpcconnection.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sjrpc/core/rpcconnection.py b/sjrpc/core/rpcconnection.py index 4b0187c..b146656 100644 --- a/sjrpc/core/rpcconnection.py +++ b/sjrpc/core/rpcconnection.py @@ -55,6 +55,9 @@ class RpcConnection(object): # The manager of this connection self._manager = manager + # Is the RpcConnection connected to its peer: + self._connected = True + @classmethod def from_addr(cls, addr, port, manager, enable_ssl=False, timeout=30.0, cert=None, handler=None): @@ -163,6 +166,9 @@ class RpcConnection(object): Message must be a jsonisable structure. ''' + if not self._connected: + raise RpcError('SendError', 'disconnected from the peer') + logging.debug('Sending: %s', message) json_msg = json.dumps(message) size = struct.pack('!L', len(json_msg)) @@ -373,6 +379,8 @@ class RpcConnection(object): :type callback: :class:`str` or callable or None ''' + self._connected = False + try: self._sock.close() except socket.error as err: -- GitLab