Commit 749c2bd1 authored by Vincent Pelletier's avatar Vincent Pelletier

Replace method dynamically rather than doing a taken-once "if".

Also, factorise code to be executed when connection is established.
parent 87da8390
...@@ -689,9 +689,7 @@ class ClientConnection(Connection): ...@@ -689,9 +689,7 @@ class ClientConnection(Connection):
except ConnectorInProgressException: except ConnectorInProgressException:
event_manager.addWriter(self) event_manager.addWriter(self)
else: else:
self.connecting = False self._connectionCompleted()
self.updateTimeout(time())
self.getHandler().connectionCompleted(self)
except ConnectorConnectionRefusedException: except ConnectorConnectionRefusedException:
self._closure() self._closure()
except ConnectorException: except ConnectorException:
...@@ -701,18 +699,16 @@ class ClientConnection(Connection): ...@@ -701,18 +699,16 @@ class ClientConnection(Connection):
def writable(self): def writable(self):
"""Called when self is writable.""" """Called when self is writable."""
if self.connecting: if self.connector.getError():
err = self.connector.getError() self._closure()
if err:
self._closure()
else:
self.connecting = False
self.updateTimeout(time())
self.getHandler().connectionCompleted(self)
self.em.addReader(self)
else: else:
Connection.writable(self) self._connectionCompleted()
def _connectionCompleted(self):
self.writable = super(ClientConnection, self).writable
self.connecting = False
self.updateTimeout(time())
self.getHandler().connectionCompleted(self)
class ServerConnection(Connection): class ServerConnection(Connection):
"""A connection from a remote node to this node.""" """A connection from a remote node to this node."""
......
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