Commit c9d2c07b authored by Grégory Wisniewski's avatar Grégory Wisniewski

Bug fix: Client now put fake packet in queue to release requesting thread, and

use Dispatcher.unregister() to avoid duplicates.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1113 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 63f617bb
......@@ -47,19 +47,10 @@ class BaseHandler(EventHandler):
def handleConnectionLost(self, conn, new_state):
"""
Put fake packets to task queues so that threads waiting for an
answer get notified of the disconnection.
"""
# XXX: not thread-safe !
queue_set = set()
conn_id = id(conn)
for key in self.dispatcher.message_table.keys():
if conn_id == key[0]:
queue = self.dispatcher.message_table.pop(key)
queue_set.add(queue)
for queue in queue_set:
queue.put((conn, None))
self.app.dispatcher.unregister(conn)
def connectionFailed(self, conn):
self.app.dispatcher.unregister(conn)
def unexpectedInAnswerHandler(*args, **kw):
......
......@@ -41,6 +41,7 @@ class Dispatcher:
def unregister(self, conn):
""" Unregister a connection and put fake packet in queues to unlock
threads bloking it them """
# XXX: not thread-safe !
for key in self.message_table.keys():
if id(conn) == key[0]:
queue = self.message_table.pop(key)
......@@ -48,9 +49,9 @@ class Dispatcher:
def registered(self, conn):
"""Check if a connection is registered into message table."""
# XXX: serch algorythm could be improved by improving data structure.
searched_id = id(conn)
for conn_id, msg_id in self.message_table.iterkeys():
if searched_id == conn_id:
return True
return False
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