Skip to content

Commit

Permalink
Merge pull request #1044 from schlamar/wouldblock-const
Browse files Browse the repository at this point in the history
Use constant for blocking errnos.
  • Loading branch information
bdarnell committed May 6, 2014
2 parents d19cba3 + 702892a commit 63ff9d6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tornado/netutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
# thread now.
u('foo').encode('idna')

# These errnos indicate that a non-blocking operation must be retried
# at a later time. On most platforms they're the same value, but on
# some they differ.
_ERRNO_WOULDBLOCK = (errno.EWOULDBLOCK, errno.EAGAIN)


def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128, flags=None):
"""Creates listening sockets bound to the given port and address.
Expand Down Expand Up @@ -163,9 +168,9 @@ def accept_handler(fd, events):
try:
connection, address = sock.accept()
except socket.error as e:
# EWOULDBLOCK and EAGAIN indicate we have accepted every
# _ERRNO_WOULDBLOCK indicate we have accepted every
# connection that is available.
if errno_from_exception(e) in (errno.EWOULDBLOCK, errno.EAGAIN):
if errno_from_exception(e) in _ERRNO_WOULDBLOCK:
return
# ECONNABORTED indicates that there was a connection
# but it was closed while still in the accept queue.
Expand Down

0 comments on commit 63ff9d6

Please sign in to comment.