summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2016-03-17 11:04:26 -0700
committerDana Powers <dana.powers@gmail.com>2016-03-17 11:04:26 -0700
commitf39f461918371f3d8bc22cb7adfa23da7f195bcd (patch)
tree220362c3b6231671301aa433c4bae52def6c146a
parent16a013e207a86e444405177e6b862f9bc73320dc (diff)
downloadkafka-python-f39f461918371f3d8bc22cb7adfa23da7f195bcd.tar.gz
Handle windows socket error codes in BrokerConnection
-rw-r--r--kafka/conn.py10
1 files 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()