]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
check for errno.WSA* on 64-bit Windows (fixes #1052) 1084/head
authorUllrich Koethe <ullrich.koethe@iwr.uni-heidelberg.de>
Mon, 23 Jun 2014 12:40:40 +0000 (14:40 +0200)
committerUllrich Koethe <ullrich.koethe@iwr.uni-heidelberg.de>
Mon, 23 Jun 2014 12:40:40 +0000 (14:40 +0200)
tornado/iostream.py
tornado/netutil.py
tornado/test/iostream_test.py
tornado/test/simple_httpclient_test.py

index 8b6142582a9ff73275ab6f31b2ec50858b1364f4..3ebcd586fcdc8c8cc0b03dd8e72f4965460e6304 100644 (file)
@@ -57,12 +57,24 @@ except ImportError:
 # some they differ.
 _ERRNO_WOULDBLOCK = (errno.EWOULDBLOCK, errno.EAGAIN)
 
+if hasattr(errno, "WSAEWOULDBLOCK"):
+    _ERRNO_WOULDBLOCK += (errno.WSAEWOULDBLOCK,)
+
 # These errnos indicate that a connection has been abruptly terminated.
 # They should be caught and handled less noisily than other errors.
 _ERRNO_CONNRESET = (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE,
                     errno.ETIMEDOUT)
 
+if hasattr(errno, "WSAECONNRESET"):
+    _ERRNO_CONNRESET += (errno.WSAECONNRESET, errno.WSAECONNABORTED, errno.WSAETIMEDOUT)
+
+# More non-portable errnos:
+_ERRNO_INPROGRESS = (errno.EINPROGRESS,)
+
+if hasattr(errno, "WSAEINPROGRESS"):
+    _ERRNO_INPROGRESS += (errno.WSAEINPROGRESS,)
 
+#######################################################
 class StreamClosedError(IOError):
     """Exception raised by `IOStream` methods when the stream is closed.
 
@@ -990,7 +1002,7 @@ class IOStream(BaseIOStream):
             # returned immediately when attempting to connect to
             # localhost, so handle them the same way as an error
             # reported later in _handle_connect.
-            if (errno_from_exception(e) != errno.EINPROGRESS and
+            if (errno_from_exception(e) not in _ERRNO_INPROGRESS and
                     errno_from_exception(e) not in _ERRNO_WOULDBLOCK):
                 gen_log.warning("Connect error on fd %s: %s",
                                 self.socket.fileno(), e)
index a9e05d1e6158db3cecf44360d185f76eadc28eaf..336c806287e9771d81409011f16dc00f03015296 100644 (file)
@@ -57,6 +57,9 @@ u('foo').encode('idna')
 # some they differ.
 _ERRNO_WOULDBLOCK = (errno.EWOULDBLOCK, errno.EAGAIN)
 
+if hasattr(errno, "WSAEWOULDBLOCK"):
+    _ERRNO_WOULDBLOCK += (errno.WSAEWOULDBLOCK,)
+
 
 def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128, flags=None):
     """Creates listening sockets bound to the given port and address.
index e9d241a5dcb4978b9b192a5a6b9d6cff671f22a0..01b0d95ac29391107e89fe7988a06a92da0322a1 100644 (file)
@@ -232,8 +232,11 @@ class TestIOStreamMixin(object):
         self.assertFalse(self.connect_called)
         self.assertTrue(isinstance(stream.error, socket.error), stream.error)
         if sys.platform != 'cygwin':
+            _ERRNO_CONNREFUSED = (errno.ECONNREFUSED,)
+            if hasattr(errno, "WSAECONNREFUSED"):
+                _ERRNO_CONNREFUSED += (errno.WSAECONNREFUSED,)
             # cygwin's errnos don't match those used on native windows python
-            self.assertEqual(stream.error.args[0], errno.ECONNREFUSED)
+            self.assertTrue(stream.error.args[0] in _ERRNO_CONNREFUSED)
 
     def test_gaierror(self):
         # Test that IOStream sets its exc_info on getaddrinfo error
index 2ba9f75d7cafa34bbc911c4fdfc4182df13234d1..f17da7e02d3133e578a9ec945f3f13663a781e9f 100644 (file)
@@ -321,8 +321,10 @@ class SimpleHTTPClientTestMixin(object):
 
         if sys.platform != 'cygwin':
             # cygwin returns EPERM instead of ECONNREFUSED here
-            self.assertTrue(str(errno.ECONNREFUSED) in str(response.error),
-                            response.error)
+            contains_errno = str(errno.ECONNREFUSED) in str(response.error)
+            if not contains_errno and hasattr(errno, "WSAECONNREFUSED"):
+                contains_errno = str(errno.WSAECONNREFUSED) in str(response.error)
+            self.assertTrue(contains_errno, response.error)
             # This is usually "Connection refused".
             # On windows, strerror is broken and returns "Unknown error".
             expected_message = os.strerror(errno.ECONNREFUSED)