Check if self._sock exists before trying to close it. Fixes #2839.

This commit is contained in:
junglecow 2006-12-27 20:44:21 +00:00
parent 5f16eb633b
commit e816b38a0f
1 changed files with 9 additions and 7 deletions

View File

@ -366,13 +366,15 @@ class NonBlockingTcp(PlugIn, IdleObject):
self.remove_timeout()
self._owner.disconnected()
self.idlequeue.unplug_idle(self.fd)
try:
self._sock.shutdown(socket.SHUT_RDWR)
except socket.error, e:
if e[0] != errno.ENOTCONN:
log.error("Error shutting down socket for %s:", self.getName(), exc_info=True)
try: self._sock.close()
except: log.error("Error closing socket for %s:", self.getName(), exc_info=True)
sock = getattr(self, '_sock', None)
if sock:
try:
sock.shutdown(socket.SHUT_RDWR)
except socket.error, e:
if e[0] != errno.ENOTCONN:
log.error("Error shutting down socket for %s:", self.getName(), exc_info=True)
try: sock.close()
except: log.error("Error closing socket for %s:", self.getName(), exc_info=True)
# socket descriptor cannot be (un)plugged anymore
self.fd = -1
if self.on_disconnect: