From c8b27da04f5e19fe207cc3cdb03bfc46c5480d4e Mon Sep 17 00:00:00 2001 From: Dimitur Kirov Date: Wed, 15 Mar 2006 19:39:27 +0000 Subject: [PATCH] don't disconnect after server inabillity to receive long data. Unregister all handlers in disconnect --- src/common/xmpp/client_nb.py | 34 ++++++++++++-------------------- src/common/xmpp/transports_nb.py | 11 +++++++---- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/common/xmpp/client_nb.py b/src/common/xmpp/client_nb.py index 203a6c87e..1f1d2b584 100644 --- a/src/common/xmpp/client_nb.py +++ b/src/common/xmpp/client_nb.py @@ -69,7 +69,7 @@ class NBCommonClient(CommonClient): def set_idlequeue(self, idlequeue): self.idlequeue = idlequeue - + def disconnected(self): ''' Called on disconnection. Calls disconnect handlers and cleans things up. ''' self.connected='' @@ -78,29 +78,21 @@ class NBCommonClient(CommonClient): for i in self.disconnect_handlers: i() self.disconnect_handlers.reverse() - if self.__dict__.has_key('NonBlockingTLS'): + if self.__dict__.has_key('NonBlockingNonSASL'): + self.NonBlockingNonSASL.PlugOut() + if self.__dict__.has_key('SASL'): + self.SASL.PlugOut() + if self.__dict__.has_key('NonBlockingTLS'): self.NonBlockingTLS.PlugOut() + if self.__dict__.has_key('NBHTTPPROXYsocket'): + self.NBHTTPPROXYsocket.PlugOut() + if self.__dict__.has_key('NonBlockingTcp'): + self.NonBlockingTcp.PlugOut() def reconnectAndReauth(self): - ''' Example of reconnection method. In fact, it can be used to batch connection and auth as well. ''' - handlerssave=self.Dispatcher.dumpHandlers() - self.Dispatcher.PlugOut() - if self.__dict__.has_key('NonBlockingNonSASL'): - self.NonBlockingNonSASL.PlugOut() - if self.__dict__.has_key('SASL'): - self.SASL.PlugOut() - if self.__dict__.has_key('NonBlockingTLS'): - self.NonBlockingTLS.PlugOut() - if self.__dict__.has_key('NBHTTPPROXYsocket'): - self.NBHTTPPROXYsocket.PlugOut() - if self.__dict__.has_key('NonBlockingTcp'): - self.NonBlockingTcp.PlugOut() - if not self.connect(server=self._Server, proxy=self._Proxy): - return - if not self.auth(self._User, self._Password, self._Resource): - return - self.Dispatcher.restoreHandlers(handlerssave) - return self.connected + ''' Just disconnect. We do reconnecting in connection.py ''' + self.disconnect() + return '' def connect(self,server=None,proxy=None, ssl=None, on_stream_start = None): ''' Make a tcp/ip connection, protect it with tls/ssl if possible and start XMPP stream. ''' diff --git a/src/common/xmpp/transports_nb.py b/src/common/xmpp/transports_nb.py index 2a01288be..0b886114d 100644 --- a/src/common/xmpp/transports_nb.py +++ b/src/common/xmpp/transports_nb.py @@ -264,8 +264,10 @@ class NonBlockingTcp(PlugIn, IdleObject): # we are not waiting for write self._plug_idle() self._on_send() - except Exception: + except socket.error, e: sys.exc_clear() + if e[0] == socket.SSL_ERROR_WANT_WRITE: + return True if self.state < 0: self.disconnect() return @@ -308,8 +310,9 @@ class NonBlockingTcp(PlugIn, IdleObject): return True def send(self, raw_data): - ''' Writes raw outgoing data. Blocks until done. - If supplied data is unicode string, encodes it to utf-8 before send. ''' + '''Append raw_data to the queue of messages to be send. + If supplied data is unicode string, encode it to utf-8. + ''' if self.state <= 0: return r = raw_data @@ -352,7 +355,7 @@ class NonBlockingTcp(PlugIn, IdleObject): def getPort(self): ''' Return the 'port' value that is connection is [will be] made to.''' return self._server[1] - + class NonBlockingTLS(PlugIn): ''' TLS connection used to encrypts already estabilished tcp connection.''' def PlugIn(self, owner, now=0, on_tls_start = None):