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