mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Store all errors signaling a disconnection into a global frozenset to save some computation time on recv() and send().
This commit is contained in:
parent
7d49bc9911
commit
985b68e611
1 changed files with 4 additions and 2 deletions
|
|
@ -56,6 +56,8 @@ import os
|
||||||
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
|
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
|
||||||
ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, errorcode
|
ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, errorcode
|
||||||
|
|
||||||
|
DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
socket_map
|
socket_map
|
||||||
except NameError:
|
except NameError:
|
||||||
|
|
@ -364,7 +366,7 @@ class dispatcher:
|
||||||
except socket.error as why:
|
except socket.error as why:
|
||||||
if why.args[0] == EWOULDBLOCK:
|
if why.args[0] == EWOULDBLOCK:
|
||||||
return 0
|
return 0
|
||||||
elif why.args[0] in (ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED):
|
elif why.args[0] in DISCONNECTED:
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
|
|
@ -382,7 +384,7 @@ class dispatcher:
|
||||||
return data
|
return data
|
||||||
except socket.error as why:
|
except socket.error as why:
|
||||||
# winsock sometimes throws ENOTCONN
|
# winsock sometimes throws ENOTCONN
|
||||||
if why.args[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED]:
|
if why.args[0] in DISCONNECTED:
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
return b''
|
return b''
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue