]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix SSLIOStream in Python 3.5a1.
authorBen Darnell <ben@bendarnell.com>
Wed, 18 Feb 2015 22:12:13 +0000 (17:12 -0500)
committerBen Darnell <ben@bendarnell.com>
Wed, 18 Feb 2015 22:18:59 +0000 (17:18 -0500)
The behavior of SSLSocket.send() with an unwriteable socket
has changed: http://bugs.python.org/issue20951

tornado/iostream.py

index b971318299ccb4b409c25bc0a61dfee1ead9e86f..8c7675c0dd5b38bb12019ade691e578f7d010122 100644 (file)
@@ -1341,6 +1341,20 @@ class SSLIOStream(IOStream):
                                       do_handshake_on_connect=False)
         self._add_io_state(old_state)
 
+    def write_to_fd(self, data):
+        try:
+            return self.socket.send(data)
+        except ssl.SSLError as e:
+            if e.args[0] == ssl.SSL_ERROR_WANT_WRITE:
+                # In Python 3.5+, SSLSocket.send raises a WANT_WRITE error if
+                # the socket is not writeable; we need to transform this into
+                # an EWOULDBLOCK socket.error or a zero return value,
+                # either of which will be recognized by the caller of this
+                # method. Prior to Python 3.5, an unwriteable socket would
+                # simply return 0 bytes written.
+                return 0
+            raise
+
     def read_from_fd(self):
         if self._ssl_accepting:
             # If the handshake hasn't finished yet, there can't be anything