Simplify the keepalive code a bit

Should not change behavior.
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2011-10-27 16:56:18 +02:00
parent cbec8bb5b2
commit f6f8fc8528
2 changed files with 10 additions and 17 deletions

View File

@ -389,42 +389,35 @@ class IMAPServer:
to be invoked in a separate thread, which should be join()'d after to be invoked in a separate thread, which should be join()'d after
the event is set.""" the event is set."""
self.ui.debug('imap', 'keepalive thread started') self.ui.debug('imap', 'keepalive thread started')
while 1: while not event.isSet():
self.ui.debug('imap', 'keepalive: top of loop')
if event.isSet():
self.ui.debug('imap', 'keepalive: event is set; exiting')
return
self.ui.debug('imap', 'keepalive: acquiring connectionlock')
self.connectionlock.acquire() self.connectionlock.acquire()
numconnections = len(self.assignedconnections) + \ numconnections = len(self.assignedconnections) + \
len(self.availableconnections) len(self.availableconnections)
self.connectionlock.release() self.connectionlock.release()
self.ui.debug('imap', 'keepalive: connectionlock released')
threads = []
threads = []
for i in range(numconnections): for i in range(numconnections):
self.ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections)) self.ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections))
if len(self.idlefolders) > i: if len(self.idlefolders) > i:
# IDLE thread
idler = IdleThread(self, self.idlefolders[i]) idler = IdleThread(self, self.idlefolders[i])
else: else:
# NOOP thread
idler = IdleThread(self) idler = IdleThread(self)
idler.start() idler.start()
threads.append(idler) threads.append(idler)
self.ui.debug('imap', 'keepalive: thread started')
self.ui.debug('imap', 'keepalive: waiting for timeout') self.ui.debug('imap', 'keepalive: waiting for timeout')
event.wait(timeout) event.wait(timeout)
self.ui.debug('imap', 'keepalive: after wait') self.ui.debug('imap', 'keepalive: after wait')
self.ui.debug('imap', 'keepalive: joining threads')
for idler in threads: for idler in threads:
# Make sure all the commands have completed. # Make sure all the commands have completed.
idler.stop() idler.stop()
idler.join() idler.join()
self.ui.debug('imap', 'keepalive: all threads joined')
self.ui.debug('imap', 'keepalive: bottom of loop') self.ui.debug('imap', 'keepalive: event is set; exiting')
return
def verifycert(self, cert, hostname): def verifycert(self, cert, hostname):
'''Verify that cert (in socket.getpeercert() format) matches hostname. '''Verify that cert (in socket.getpeercert() format) matches hostname.