# HG changeset patch # User morrowa # Date 1245790348 25200 # Node ID 6d1392a3e0a604eac7eaea42aa358d06b3af6d0b # Parent e9f209a24d53ba1082d5050cae287698edaeea8e Moved _handleCloseRequest to a new method. Added warning messages. diff -r e9f209a24d53 -r 6d1392a3e0a6 Python/BLIP.py --- a/Python/BLIP.py Tue Jun 23 12:46:40 2009 -0700 +++ b/Python/BLIP.py Tue Jun 23 13:52:28 2009 -0700 @@ -161,6 +161,7 @@ log.debug("pendingResponses[%i] := %s",requestNo,response) return self._sendMessage(req) else: + log.warning("%s: Attempt to send a request after the connection has started closing: %s" % (self, req)) return False def _outQueueMessage(self, msg,isNew=True): @@ -292,21 +293,7 @@ def _dispatchMetaRequest(self, request): """Handles dispatching internal meta requests.""" if request['Profile'] == kMsgProfile_Bye: - shouldClose = True - if self.onCloseRequest: - shouldClose = self.onCloseRequest() - if not shouldClose: - log.debug("Sending resfusal to close...") - response = request.response - response.isError = True - response['Error-Domain'] = "BLIP" - response['Error-Code'] = 403 - response.body = "Close request denied" - response.send() - else: - log.debug("Sending permission to close...") - response = request.response - response.send() + self._handleCloseRequest(request) else: response = request.response response.isError = True @@ -317,6 +304,24 @@ ### CLOSING: + def _handleCloseRequest(self, request): + """Handles requests from a peer to close.""" + shouldClose = True + if self.onCloseRequest: + shouldClose = self.onCloseRequest() + if not shouldClose: + log.debug("Sending resfusal to close...") + response = request.response + response.isError = True + response['Error-Domain'] = "BLIP" + response['Error-Code'] = 403 + response.body = "Close request denied" + response.send() + else: + log.debug("Sending permission to close...") + response = request.response + response.send() + def close(self): """Publicly callable close method. Sends close request to peer.""" if self.status != kOpen: