]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a fast path for IOStream writes in addition to reads.
authorBen Darnell <ben@bendarnell.com>
Wed, 6 Jul 2011 05:34:26 +0000 (22:34 -0700)
committerBen Darnell <ben@bendarnell.com>
Wed, 6 Jul 2011 05:34:26 +0000 (22:34 -0700)
This is a significant speedup for small requests, since it is now
possible to do a request and (synchronous) response without calling
IOLoop.add_handler.

tornado/iostream.py

index 8a328eca2d86f23e521fb52432c1a45240cb9081..b41800f1087012ebcf80b9e800051f7c9fb7a397 100644 (file)
@@ -174,8 +174,15 @@ class IOStream(object):
         assert isinstance(data, bytes_type)
         self._check_closed()
         self._write_buffer.append(data)
-        self._add_io_state(self.io_loop.WRITE)
         self._write_callback = stack_context.wrap(callback)
+        self._handle_write()
+        if self._write_buffer:
+            self._add_io_state(self.io_loop.WRITE)
+        elif callback is None and self._state is None:
+            # if callback is not None and we just completed the write
+            # in the fast path, _add_io_state will be called from
+            # _run_callback (see comments there for why)
+            self._add_io_state(0)
 
     def set_close_callback(self, callback):
         """Call the given callback when the stream is closed."""