Skip to content

Commit c5834a9

Browse files
committed
Handle EHOSTDOWN, ENETDOWN.
Someone on the mailing list reported getting these. Also centralize the list of these errors, so we don't have different parts of the code supporting a different subset of them. Now just use ssnet.NET_ERRS.
1 parent e247454 commit c5834a9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def try_send(self):
130130
try:
131131
self.sock.send(self.request)
132132
except socket.error, e:
133-
if e.args[0] in [errno.ECONNREFUSED, errno.EHOSTUNREACH]:
133+
if e.args[0] in ssnet.NET_ERRS:
134134
# might have been spurious; try again.
135135
# Note: these errors sometimes are reported by recv(),
136136
# and sometimes by send(). We have to catch both.
@@ -145,7 +145,7 @@ def callback(self):
145145
try:
146146
data = self.sock.recv(4096)
147147
except socket.error, e:
148-
if e.args[0] in [errno.ECONNREFUSED, errno.EHOSTUNREACH]:
148+
if e.args[0] in ssnet.NET_ERRS:
149149
# might have been spurious; try again.
150150
# Note: these errors sometimes are reported by recv(),
151151
# and sometimes by send(). We have to catch both.

ssnet.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
CMD_DNS_REQ: 'DNS_REQ',
4141
CMD_DNS_RESPONSE: 'DNS_RESPONSE',
4242
}
43-
43+
44+
45+
NET_ERRS = [errno.ECONNREFUSED, errno.ETIMEDOUT,
46+
errno.EHOSTUNREACH, errno.ENETUNREACH,
47+
errno.EHOSTDOWN, errno.ENETDOWN]
4448

4549

4650
def _add(l, elem):
@@ -151,9 +155,7 @@ def try_connect(self):
151155
elif e.args[0] == errno.EISCONN:
152156
# connected successfully (BSD)
153157
self.connect_to = None
154-
elif e.args[0] in [errno.ECONNREFUSED, errno.ETIMEDOUT,
155-
errno.EHOSTUNREACH, errno.ENETUNREACH,
156-
errno.EACCES, errno.EPERM]:
158+
elif e.args[0] in NET_ERRS + [errno.EACCES, errno.EPERM]:
157159
# a "normal" kind of error
158160
self.connect_to = None
159161
self.seterr(e)

0 commit comments

Comments
 (0)