Allow Imapserver.releaseconnection() to drop a connection

If a connection is broken, we want to have it really dropped and not be
reused. So far, we are checking the .Terminate attribute for this, but
according to the imaplib2 author, it is only set on normal shutdown and
it is an undocumented attribute whose meaning could change any time.

This patch introduces the parameter drop_conn which allows to tell
releaseconnection() that we really want to connection being dropped from
the pool of available connections and properly destroy it.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-09-06 13:19:25 +02:00 committed by Nicolas Sebrecht
parent 0906d0db70
commit 9c678c9d6b

View File

@ -109,12 +109,15 @@ class IMAPServer:
return self.root
def releaseconnection(self, connection):
"""Releases a connection, returning it to the pool."""
def releaseconnection(self, connection, drop_conn=False):
"""Releases a connection, returning it to the pool.
:param drop_conn: If True, the connection will be released and
not be reused. This can be used to indicate broken connections."""
self.connectionlock.acquire()
self.assignedconnections.remove(connection)
# Don't reuse broken connections
if connection.Terminate:
if connection.Terminate or drop_conn:
connection.logout()
else:
self.availableconnections.append(connection)