don't disconnect after server inabillity to

receive long data. Unregister all handlers in
disconnect
This commit is contained in:
Dimitur Kirov 2006-03-15 19:39:27 +00:00
parent f65a5be6e5
commit c8b27da04f
2 changed files with 20 additions and 25 deletions

View File

@ -69,7 +69,7 @@ class NBCommonClient(CommonClient):
def set_idlequeue(self, idlequeue): def set_idlequeue(self, idlequeue):
self.idlequeue = idlequeue self.idlequeue = idlequeue
def disconnected(self): def disconnected(self):
''' Called on disconnection. Calls disconnect handlers and cleans things up. ''' ''' Called on disconnection. Calls disconnect handlers and cleans things up. '''
self.connected='' self.connected=''
@ -78,29 +78,21 @@ class NBCommonClient(CommonClient):
for i in self.disconnect_handlers: for i in self.disconnect_handlers:
i() i()
self.disconnect_handlers.reverse() 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() self.NonBlockingTLS.PlugOut()
if self.__dict__.has_key('NBHTTPPROXYsocket'):
self.NBHTTPPROXYsocket.PlugOut()
if self.__dict__.has_key('NonBlockingTcp'):
self.NonBlockingTcp.PlugOut()
def reconnectAndReauth(self): def reconnectAndReauth(self):
''' Example of reconnection method. In fact, it can be used to batch connection and auth as well. ''' ''' Just disconnect. We do reconnecting in connection.py '''
handlerssave=self.Dispatcher.dumpHandlers() self.disconnect()
self.Dispatcher.PlugOut() return ''
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
def connect(self,server=None,proxy=None, ssl=None, on_stream_start = None): 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. ''' ''' Make a tcp/ip connection, protect it with tls/ssl if possible and start XMPP stream. '''

View File

@ -264,8 +264,10 @@ class NonBlockingTcp(PlugIn, IdleObject):
# we are not waiting for write # we are not waiting for write
self._plug_idle() self._plug_idle()
self._on_send() self._on_send()
except Exception: except socket.error, e:
sys.exc_clear() sys.exc_clear()
if e[0] == socket.SSL_ERROR_WANT_WRITE:
return True
if self.state < 0: if self.state < 0:
self.disconnect() self.disconnect()
return return
@ -308,8 +310,9 @@ class NonBlockingTcp(PlugIn, IdleObject):
return True return True
def send(self, raw_data): def send(self, raw_data):
''' Writes raw outgoing data. Blocks until done. '''Append raw_data to the queue of messages to be send.
If supplied data is unicode string, encodes it to utf-8 before send. ''' If supplied data is unicode string, encode it to utf-8.
'''
if self.state <= 0: if self.state <= 0:
return return
r = raw_data r = raw_data
@ -352,7 +355,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
def getPort(self): def getPort(self):
''' Return the 'port' value that is connection is [will be] made to.''' ''' Return the 'port' value that is connection is [will be] made to.'''
return self._server[1] return self._server[1]
class NonBlockingTLS(PlugIn): class NonBlockingTLS(PlugIn):
''' TLS connection used to encrypts already estabilished tcp connection.''' ''' TLS connection used to encrypts already estabilished tcp connection.'''
def PlugIn(self, owner, now=0, on_tls_start = None): def PlugIn(self, owner, now=0, on_tls_start = None):