[Neo-report] r1876 gregory - /trunk/neo/connection.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Mar 1 11:55:04 CET 2010
Author: gregory
Date: Mon Mar 1 11:55:04 2010
New Revision: 1876
Log:
Factorise connectionFailed() calls with _closure() implementation.
Modified:
trunk/neo/connection.py
Modified: trunk/neo/connection.py
==============================================================================
--- trunk/neo/connection.py [iso-8859-1] (original)
+++ trunk/neo/connection.py [iso-8859-1] Mon Mar 1 11:55:04 2010
@@ -371,10 +371,14 @@
def pending(self):
return self.connector is not None and self.write_buf
- def _closure(self):
+ def _closure(self, was_connected=False):
assert self.connector is not None, self.whoSetConnector()
+ handler = self.getHandler()
self.close()
- self.getHandler().connectionClosed(self)
+ if was_connected:
+ handler.connectionFailed(self)
+ else:
+ handler.connectionClosed(self)
def _recv(self):
"""Receive data from a connector."""
@@ -389,8 +393,7 @@
pass
except ConnectorConnectionRefusedException:
# should only occur while connecting
- self.close()
- self.getHandler().connectionFailed(self)
+ self._closure(was_connected=True)
except ConnectorConnectionClosedException:
# connection resetted by peer, according to the man, this error
# should not occurs but it seems it's false
@@ -526,12 +529,10 @@
self.getHandler().connectionCompleted(self)
event_manager.addReader(self)
except ConnectorConnectionRefusedException:
- handler.connectionFailed(self)
- self.close()
+ self._closure(was_connected=True)
except ConnectorException:
# unhandled connector exception
- handler.connectionFailed(self)
- self.close()
+ self._closure(was_connected=True)
raise
def writable(self):
@@ -539,8 +540,7 @@
if self.connecting:
err = self.connector.getError()
if err:
- self.getHandler().connectionFailed(self)
- self.close()
+ self._closure(was_connected=True)
return
else:
self.connecting = False
More information about the Neo-report
mailing list