summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiampaolo RodolĂ  <g.rodola@gmail.com>2010-09-15 21:43:47 (GMT)
committerGiampaolo RodolĂ  <g.rodola@gmail.com>2010-09-15 21:43:47 (GMT)
commit985b68e611e5902bd21ce3159e849b2dcd370afb (patch)
tree79bbd3137f5e0e1dd713cfb1d4c1e2281534a6c4
parent7d49bc99113c817a7d7c127ebdef674680d567df (diff)
downloadcpython-985b68e611e5902bd21ce3159e849b2dcd370afb.zip
cpython-985b68e611e5902bd21ce3159e849b2dcd370afb.tar.gz
cpython-985b68e611e5902bd21ce3159e849b2dcd370afb.tar.bz2
Store all errors signaling a disconnection into a global frozenset to save some computation time on recv() and send().
-rw-r--r--Lib/asyncore.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index edb1c7b..fbbee29 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -56,6 +56,8 @@ import os
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, errorcode
+DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED))
+
try:
socket_map
except NameError:
@@ -364,7 +366,7 @@ class dispatcher:
except socket.error as why:
if why.args[0] == EWOULDBLOCK:
return 0
- elif why.args[0] in (ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED):
+ elif why.args[0] in DISCONNECTED:
self.handle_close()
return 0
else:
@@ -382,7 +384,7 @@ class dispatcher:
return data
except socket.error as why:
# winsock sometimes throws ENOTCONN
- if why.args[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED]:
+ if why.args[0] in DISCONNECTED:
self.handle_close()
return b''
else: