Commit 2888f3be authored by Grégory Wisniewski's avatar Grégory Wisniewski

Potential bug fix: Handle connection closure in the same way.

A disconnection case was calling the handler method before the close(), fix
it and factorise connection closure.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1676 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 14c63144
...@@ -304,14 +304,17 @@ class Connection(BaseConnection): ...@@ -304,14 +304,17 @@ class Connection(BaseConnection):
def pending(self): def pending(self):
return self.connector is not None and self.write_buf return self.connector is not None and self.write_buf
def _closure(self):
self.close()
self.handler.connectionClosed(self)
def _recv(self): def _recv(self):
"""Receive data from a connector.""" """Receive data from a connector."""
try: try:
data = self.connector.receive() data = self.connector.receive()
if not data: if not data:
logging.debug('Connection %r closed in recv', self.connector) logging.debug('Connection %r closed in recv', self.connector)
self.close() self._closure()
self.handler.connectionClosed(self)
return return
self.read_buf += data self.read_buf += data
except ConnectorTryAgainException: except ConnectorTryAgainException:
...@@ -324,12 +327,10 @@ class Connection(BaseConnection): ...@@ -324,12 +327,10 @@ class Connection(BaseConnection):
# connection resetted by peer, according to the man, this error # connection resetted by peer, according to the man, this error
# should not occurs but it seems it's false # should not occurs but it seems it's false
logging.debug('Connection reset by peer: %r', self.connector) logging.debug('Connection reset by peer: %r', self.connector)
self.close() self._closure()
self.handler.connectionClosed(self)
except ConnectorException: except ConnectorException:
logging.debug('Unknown connection error: %r', self.connector) logging.debug('Unknown connection error: %r', self.connector)
self.close() self._closure()
self.handler.connectionClosed(self)
# unhandled connector exception # unhandled connector exception
raise raise
...@@ -341,8 +342,7 @@ class Connection(BaseConnection): ...@@ -341,8 +342,7 @@ class Connection(BaseConnection):
n = self.connector.send(self.write_buf) n = self.connector.send(self.write_buf)
if not n: if not n:
logging.debug('Connection %r closed in send', self.connector) logging.debug('Connection %r closed in send', self.connector)
self.handler.connectionClosed(self) self._closure()
self.close()
return return
self.write_buf = self.write_buf[n:] self.write_buf = self.write_buf[n:]
except ConnectorTryAgainException: except ConnectorTryAgainException:
...@@ -350,13 +350,11 @@ class Connection(BaseConnection): ...@@ -350,13 +350,11 @@ class Connection(BaseConnection):
except ConnectorConnectionClosedException: except ConnectorConnectionClosedException:
# connection resetted by peer # connection resetted by peer
logging.debug('Connection reset by peer: %r', self.connector) logging.debug('Connection reset by peer: %r', self.connector)
self.close() self._closure()
self.handler.connectionClosed(self)
except ConnectorException: except ConnectorException:
logging.debug('Unknown connection error: %r', self.connector) logging.debug('Unknown connection error: %r', self.connector)
# unhandled connector exception # unhandled connector exception
self.close() self._closure()
self.handler.connectionClosed(self)
raise raise
def _addPacket(self, packet): def _addPacket(self, packet):
......
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