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):
def writable(self):
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):
return self.handler
......@@ -129,7 +142,7 @@ class ListeningConnection(BaseConnection):
self.handler.connectionAccepted(self, new_s, addr)
except ConnectorTryAgainException:
pass
def isListeningConnection(self):
return True
......@@ -167,26 +180,15 @@ class Connection(BaseConnection):
return next_id
def close(self):
"""Close the connection."""
em = self.em
if self.connector is not None:
logging.debug('closing a connector for %s (%s:%d)',
dump(self.uuid), *(self.addr))
em.removeReader(self)
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()
logging.debug('closing a connector for %s (%s:%d)',
dump(self.uuid), *(self.addr))
BaseConnection.close(self)
for event in self.event_dict.itervalues():
em.removeIdleEvent(event)
self.event_dict.clear()
self.write_buf = ""
self.read_buf = ""
def __del__(self):
self.close()
def abort(self):
"""Abort dealing with this connection."""
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