don't disconnect after server inabillity to
receive long data. Unregister all handlers in disconnect
This commit is contained in:
parent
f65a5be6e5
commit
c8b27da04f
|
@ -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. '''
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue