Commit ce608653 authored by Julien Muchembled's avatar Julien Muchembled

Fix error handling when setting up a listening connector

getAddress (via __repr__) raised EBADF on closed connectors.
parent 1a070186
...@@ -127,6 +127,7 @@ class SocketConnector(object): ...@@ -127,6 +127,7 @@ class SocketConnector(object):
self._bind(self.addr) self._bind(self.addr)
self.socket.listen(self.SOMAXCONN) self.socket.listen(self.SOMAXCONN)
except socket.error, e: except socket.error, e:
self.is_closed = True
self.socket.close() self.socket.close()
self._error('listen', e) self._error('listen', e)
...@@ -220,12 +221,13 @@ class SocketConnector(object): ...@@ -220,12 +221,13 @@ class SocketConnector(object):
def __repr__(self): def __repr__(self):
if self.is_closed is None: if self.is_closed is None:
state = 'never opened' state = ', never opened'
else: else:
if self.is_closed: if self.is_closed:
state = 'closed ' state = ', closed '
else: else:
state = 'opened ' state = ' fileno %s %s, opened ' % (
self.socket_fd, self.getAddress())
if self.is_server is None: if self.is_server is None:
state += 'listening' state += 'listening'
else: else:
...@@ -234,9 +236,7 @@ class SocketConnector(object): ...@@ -234,9 +236,7 @@ class SocketConnector(object):
else: else:
state += 'to ' state += 'to '
state += str(self.addr) state += str(self.addr)
return '<%s at 0x%x fileno %s %s, %s>' % (self.__class__.__name__, return '<%s at 0x%x%s>' % (self.__class__.__name__, id(self), state)
id(self), '?' if self.is_closed else self.socket_fd,
self.getAddress(), state)
class SocketConnectorIPv4(SocketConnector): class SocketConnectorIPv4(SocketConnector):
" Wrapper for IPv4 sockets" " Wrapper for IPv4 sockets"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment