Raise the event 'socket_error' when a socket error occurs.

Will be most useful for debugging and responding to failed
connection attempts.
This commit is contained in:
Lance Stout 2011-01-16 13:07:39 -05:00
parent ead3af3135
commit cb85d4a529

View file

@ -292,6 +292,7 @@ class XMLStream(object):
return True return True
except Socket.error as serr: except Socket.error as serr:
error_msg = "Could not connect to %s:%s. Socket Error #%s: %s" error_msg = "Could not connect to %s:%s. Socket Error #%s: %s"
self.event('socket_error', serr)
log.error(error_msg % (self.address[0], self.address[1], log.error(error_msg % (self.address[0], self.address[1],
serr.errno, serr.strerror)) serr.errno, serr.strerror))
time.sleep(1) time.sleep(1)
@ -327,7 +328,7 @@ class XMLStream(object):
self.filesocket.close() self.filesocket.close()
self.socket.shutdown(Socket.SHUT_RDWR) self.socket.shutdown(Socket.SHUT_RDWR)
except Socket.error as serr: except Socket.error as serr:
pass self.event('socket_error', serr)
finally: finally:
#clear your application state #clear your application state
self.event("disconnected", direct=True) self.event("disconnected", direct=True)
@ -734,7 +735,8 @@ class XMLStream(object):
except SystemExit: except SystemExit:
log.debug("SystemExit in _process") log.debug("SystemExit in _process")
self.stop.set() self.stop.set()
except Socket.error: except Socket.error as serr:
self.event('socket_error', serr)
log.exception('Socket Error') log.exception('Socket Error')
except: except:
if not self.stop.isSet(): if not self.stop.isSet():