Commit 2cc58316 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Define the close() method on BaseConnection instead of Connection to allow close

a listening connection (as requested in the storage when connecting to the
primary master).


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@731 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 24a4b289
...@@ -91,6 +91,19 @@ class BaseConnection(object): ...@@ -91,6 +91,19 @@ class BaseConnection(object):
def writable(self): def writable(self):
raise NotImplementedError raise NotImplementedError
def close(self):
"""Close the connection."""
em = self.em
if self.connector is not None:
em.removeReader(self)
em.removeWriter(self)
em.unregister(self)
self.connector.shutdown()
self.connector.close()
self.connector = None
__del__ = close
def getHandler(self): def getHandler(self):
return self.handler return self.handler
...@@ -129,7 +142,7 @@ class ListeningConnection(BaseConnection): ...@@ -129,7 +142,7 @@ class ListeningConnection(BaseConnection):
self.handler.connectionAccepted(self, new_s, addr) self.handler.connectionAccepted(self, new_s, addr)
except ConnectorTryAgainException: except ConnectorTryAgainException:
pass pass
def isListeningConnection(self): def isListeningConnection(self):
return True return True
...@@ -167,26 +180,15 @@ class Connection(BaseConnection): ...@@ -167,26 +180,15 @@ class Connection(BaseConnection):
return next_id return next_id
def close(self): def close(self):
"""Close the connection.""" logging.debug('closing a connector for %s (%s:%d)',
em = self.em dump(self.uuid), *(self.addr))
if self.connector is not None: BaseConnection.close(self)
logging.debug('closing a connector for %s (%s:%d)', for event in self.event_dict.itervalues():
dump(self.uuid), *(self.addr)) em.removeIdleEvent(event)
em.removeReader(self) self.event_dict.clear()
em.removeWriter(self)
em.unregister(self)
self.connector.shutdown()
self.connector.close()
self.connector = None
for event in self.event_dict.itervalues():
em.removeIdleEvent(event)
self.event_dict.clear()
self.write_buf = "" self.write_buf = ""
self.read_buf = "" self.read_buf = ""
def __del__(self):
self.close()
def abort(self): def abort(self):
"""Abort dealing with this connection.""" """Abort dealing with this connection."""
logging.debug('aborting a connector for %s (%s:%d)', logging.debug('aborting a connector for %s (%s:%d)',
......
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