Skip to content

Commit a30220d

Browse files
committed
Fix socket bugs caused by switching to a newer MSVC compiler
Windows uses different error codes than Unix does, and our socket code was only checking for Unix errors by number. This was causing some things to fail that should have worked. I believe that in the newer Python's that these errors are folded from the Windows errors to Unix errors, but I can't find where to do that here in Python2.
1 parent 98e03ad commit a30220d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Lib/asyncore.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@
5353
import warnings
5454

5555
import os
56-
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
56+
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
5757
ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
58-
errorcode
58+
errorcode, \
59+
WSAEWOULDBLOCK, WSAENOTCONN, WSAEINPROGRESS, WSAEALREADY, WSAEISCONN, \
60+
WSAECONNABORTED, WSAENOTCONN, WSAEBADF
5961

6062
_DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
61-
EBADF))
63+
EBADF, WSAENOTCONN, WSAECONNABORTED, WSAEBADF))
6264

6365
try:
6466
socket_map
@@ -249,7 +251,7 @@ def __init__(self, sock=None, map=None):
249251
try:
250252
self.addr = sock.getpeername()
251253
except socket.error, err:
252-
if err.args[0] in (ENOTCONN, EINVAL):
254+
if err.args[0] in (ENOTCONN, EINVAL, WSAENOTCONN):
253255
# To handle the case where we got an unconnected
254256
# socket.
255257
self.connected = False
@@ -345,7 +347,7 @@ def connect(self, address):
345347
self.connected = False
346348
self.connecting = True
347349
err = self.socket.connect_ex(address)
348-
if err in (EINPROGRESS, EALREADY, EWOULDBLOCK) \
350+
if err in (EINPROGRESS, EALREADY, EWOULDBLOCK, WSAEINPROGRESS, WSAEALREADY, WSAEWOULDBLOCK) \
349351
or err == EINVAL and os.name in ('nt', 'ce'):
350352
self.addr = address
351353
return
@@ -362,7 +364,7 @@ def accept(self):
362364
except TypeError:
363365
return None
364366
except socket.error as why:
365-
if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN):
367+
if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN, WSAEWOULDBLOCK, WSAECONNABORTED):
366368
return None
367369
else:
368370
raise
@@ -374,7 +376,7 @@ def send(self, data):
374376
result = self.socket.send(data)
375377
return result
376378
except socket.error, why:
377-
if why.args[0] == EWOULDBLOCK:
379+
if why.args[0] in(EWOULDBLOCK, WSAEWOULDBLOCK):
378380
return 0
379381
elif why.args[0] in _DISCONNECTED:
380382
self.handle_close()
@@ -408,7 +410,7 @@ def close(self):
408410
try:
409411
self.socket.close()
410412
except socket.error, why:
411-
if why.args[0] not in (ENOTCONN, EBADF):
413+
if why.args[0] not in (ENOTCONN, EBADF, WSAENOTCONN, WSAEBADF):
412414
raise
413415

414416
# cheap inheritance, used to pass all other attribute

0 commit comments

Comments
 (0)