Browse Source

add timeout support in DNS; close #138

auth
clowwindy 11 years ago
parent
commit
b7bfdb9918
  1. 10
      shadowsocks/tcprelay.py

10
shadowsocks/tcprelay.py

@ -166,7 +166,8 @@ class TCPRelayHandler(object):
uncomplete = True uncomplete = True
except (OSError, IOError) as e: except (OSError, IOError) as e:
error_no = eventloop.errno_from_exception(e) error_no = eventloop.errno_from_exception(e)
if error_no in (errno.EAGAIN, errno.EINPROGRESS): if error_no in (errno.EAGAIN, errno.EINPROGRESS,
errno.EWOULDBLOCK):
uncomplete = True uncomplete = True
else: else:
logging.error(e) logging.error(e)
@ -349,7 +350,7 @@ class TCPRelayHandler(object):
data = self._local_sock.recv(BUF_SIZE) data = self._local_sock.recv(BUF_SIZE)
except (OSError, IOError) as e: except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) in \ if eventloop.errno_from_exception(e) in \
(errno.ETIMEDOUT, errno.EAGAIN): (errno.ETIMEDOUT, errno.EAGAIN, errno.EWOULDBLOCK):
return return
if not data: if not data:
self.destroy() self.destroy()
@ -381,7 +382,7 @@ class TCPRelayHandler(object):
data = self._remote_sock.recv(BUF_SIZE) data = self._remote_sock.recv(BUF_SIZE)
except (OSError, IOError) as e: except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) in \ if eventloop.errno_from_exception(e) in \
(errno.ETIMEDOUT, errno.EAGAIN): (errno.ETIMEDOUT, errno.EAGAIN, errno.EWOULDBLOCK):
return return
if not data: if not data:
self.destroy() self.destroy()
@ -610,7 +611,8 @@ class TCPRelay(object):
self._is_local) self._is_local)
except (OSError, IOError) as e: except (OSError, IOError) as e:
error_no = eventloop.errno_from_exception(e) error_no = eventloop.errno_from_exception(e)
if error_no in (errno.EAGAIN, errno.EINPROGRESS): if error_no in (errno.EAGAIN, errno.EINPROGRESS,
errno.EWOULDBLOCK):
continue continue
else: else:
logging.error(e) logging.error(e)

Loading…
Cancel
Save