summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/selector_events.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2016-09-12 08:48:55 (GMT)
committerChristian Heimes <christian@python.org>2016-09-12 08:48:55 (GMT)
commit4d9a72902dec55fe87f105324adc4239a13d966f (patch)
tree12336d19f4aa31e4ef9d2687883006395c474b5d /Lib/asyncio/selector_events.py
parent9017ec1ea0347c4bd901c329254590a9f86a69b8 (diff)
parent0d5048cb21e431c1a8221e15563837090946be81 (diff)
downloadcpython-4d9a72902dec55fe87f105324adc4239a13d966f.zip
cpython-4d9a72902dec55fe87f105324adc4239a13d966f.tar.gz
cpython-4d9a72902dec55fe87f105324adc4239a13d966f.tar.bz2
merge
Diffstat (limited to 'Lib/asyncio/selector_events.py')
-rw-r--r--Lib/asyncio/selector_events.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 34cce6b..c2ebd67 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -39,6 +39,17 @@ def _test_selector_event(selector, fd, event):
return bool(key.events & event)
+if hasattr(socket, 'TCP_NODELAY'):
+ def _set_nodelay(sock):
+ if (sock.family in {socket.AF_INET, socket.AF_INET6} and
+ sock.type == socket.SOCK_STREAM and
+ sock.proto == socket.IPPROTO_TCP):
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+else:
+ def _set_nodelay(sock):
+ pass
+
+
class BaseSelectorEventLoop(base_events.BaseEventLoop):
"""Selector event loop.
@@ -560,6 +571,12 @@ class _SelectorTransport(transports._FlowControlMixin,
def abort(self):
self._force_close(None)
+ def set_protocol(self, protocol):
+ self._protocol = protocol
+
+ def get_protocol(self):
+ return self._protocol
+
def is_closing(self):
return self._closing
@@ -635,6 +652,11 @@ class _SelectorSocketTransport(_SelectorTransport):
self._eof = False
self._paused = False
+ # Disable the Nagle algorithm -- small writes will be
+ # sent without waiting for the TCP ACK. This generally
+ # decreases the latency (in some cases significantly.)
+ _set_nodelay(self._sock)
+
self._loop.call_soon(self._protocol.connection_made, self)
# only start reading when connection_made() has been called
self._loop.call_soon(self._loop.add_reader,