Commit 6042488a authored by Grégory Wisniewski's avatar Grégory Wisniewski

Factorise connectionFailed() calls with _closure() implementation.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1876 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 06f46637
...@@ -371,10 +371,14 @@ class Connection(BaseConnection): ...@@ -371,10 +371,14 @@ 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): def _closure(self, was_connected=False):
assert self.connector is not None, self.whoSetConnector() assert self.connector is not None, self.whoSetConnector()
handler = self.getHandler()
self.close() self.close()
self.getHandler().connectionClosed(self) if was_connected:
handler.connectionFailed(self)
else:
handler.connectionClosed(self)
def _recv(self): def _recv(self):
"""Receive data from a connector.""" """Receive data from a connector."""
...@@ -389,8 +393,7 @@ class Connection(BaseConnection): ...@@ -389,8 +393,7 @@ class Connection(BaseConnection):
pass pass
except ConnectorConnectionRefusedException: except ConnectorConnectionRefusedException:
# should only occur while connecting # should only occur while connecting
self.close() self._closure(was_connected=True)
self.getHandler().connectionFailed(self)
except ConnectorConnectionClosedException: except ConnectorConnectionClosedException:
# 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
...@@ -526,12 +529,10 @@ class ClientConnection(Connection): ...@@ -526,12 +529,10 @@ class ClientConnection(Connection):
self.getHandler().connectionCompleted(self) self.getHandler().connectionCompleted(self)
event_manager.addReader(self) event_manager.addReader(self)
except ConnectorConnectionRefusedException: except ConnectorConnectionRefusedException:
handler.connectionFailed(self) self._closure(was_connected=True)
self.close()
except ConnectorException: except ConnectorException:
# unhandled connector exception # unhandled connector exception
handler.connectionFailed(self) self._closure(was_connected=True)
self.close()
raise raise
def writable(self): def writable(self):
...@@ -539,8 +540,7 @@ class ClientConnection(Connection): ...@@ -539,8 +540,7 @@ class ClientConnection(Connection):
if self.connecting: if self.connecting:
err = self.connector.getError() err = self.connector.getError()
if err: if err:
self.getHandler().connectionFailed(self) self._closure(was_connected=True)
self.close()
return return
else: else:
self.connecting = False self.connecting = False
......
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