From f39f461918371f3d8bc22cb7adfa23da7f195bcd Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Thu, 17 Mar 2016 11:04:26 -0700 Subject: Handle windows socket error codes in BrokerConnection --- kafka/conn.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kafka/conn.py b/kafka/conn.py index 015bf23..65451f9 100644 --- a/kafka/conn.py +++ b/kafka/conn.py @@ -90,9 +90,10 @@ class BrokerConnection(object): pass self.last_attempt = time.time() - if not ret or ret is errno.EISCONN: + if not ret or ret == errno.EISCONN: self.state = ConnectionStates.CONNECTED - elif ret in (errno.EINPROGRESS, errno.EALREADY): + # WSAEINVAL == 10022, but errno.WSAEINVAL is not available on non-win systems + elif ret in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK, 10022): self.state = ConnectionStates.CONNECTING else: log.error('Connect attempt to %s returned error %s.' @@ -114,9 +115,10 @@ class BrokerConnection(object): ret = self._sock.connect_ex((self.host, self.port)) except socket.error as ret: pass - if not ret or ret is errno.EISCONN: + if not ret or ret == errno.EISCONN: self.state = ConnectionStates.CONNECTED - elif ret is not errno.EALREADY: + # WSAEINVAL == 10022, but errno.WSAEINVAL is not available on non-win systems + elif ret not in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK, 10022): log.error('Connect attempt to %s returned error %s.' ' Disconnecting.', self, ret) self.close() -- cgit v1.2.1