remove listener on close too
This was failing to clean up after WrongPassword disconnects.
This commit is contained in:
parent
6a2cbf9014
commit
cfcd74db4b
|
@ -68,11 +68,15 @@ class Mailbox:
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def add_listener(self, handle, send_f, stop_f):
|
def add_listener(self, handle, send_f, stop_f):
|
||||||
|
#log.msg("add_listener", self._mailbox_id, handle)
|
||||||
self._listeners[handle] = (send_f, stop_f)
|
self._listeners[handle] = (send_f, stop_f)
|
||||||
|
#log.msg(" added", len(self._listeners))
|
||||||
return self.get_messages()
|
return self.get_messages()
|
||||||
|
|
||||||
def remove_listener(self, handle):
|
def remove_listener(self, handle):
|
||||||
|
#log.msg("remove_listener", self._mailbox_id, handle)
|
||||||
self._listeners.pop(handle, None)
|
self._listeners.pop(handle, None)
|
||||||
|
#log.msg(" removed", len(self._listeners))
|
||||||
|
|
||||||
def has_listeners(self):
|
def has_listeners(self):
|
||||||
return bool(self._listeners)
|
return bool(self._listeners)
|
||||||
|
|
|
@ -224,6 +224,9 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol):
|
||||||
def handle_close(self, msg, server_rx):
|
def handle_close(self, msg, server_rx):
|
||||||
if not self._mailbox:
|
if not self._mailbox:
|
||||||
raise Error("must open mailbox before closing")
|
raise Error("must open mailbox before closing")
|
||||||
|
if self._listening:
|
||||||
|
self._mailbox.remove_listener(self)
|
||||||
|
self._listening = False
|
||||||
self._mailbox.close(self._side, msg.get("mood"), server_rx)
|
self._mailbox.close(self._side, msg.get("mood"), server_rx)
|
||||||
self._mailbox = None
|
self._mailbox = None
|
||||||
self.send("closed")
|
self.send("closed")
|
||||||
|
@ -235,6 +238,7 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol):
|
||||||
self.sendMessage(payload, False)
|
self.sendMessage(payload, False)
|
||||||
|
|
||||||
def onClose(self, wasClean, code, reason):
|
def onClose(self, wasClean, code, reason):
|
||||||
|
#log.msg("onClose", self, self._mailbox, self._listening)
|
||||||
if self._mailbox and self._listening:
|
if self._mailbox and self._listening:
|
||||||
self._mailbox.remove_listener(self)
|
self._mailbox.remove_listener(self)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user