diff options
author | Yury Selivanov <yury@magic.io> | 2016-09-12 01:44:17 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2016-09-12 01:44:17 (GMT) |
commit | 503ba3ed973d8e82ea5e38cb287d4127fccf51b8 (patch) | |
tree | 763d37115600123def5749e3237e92cde2c7ec97 /Lib/asyncio/selector_events.py | |
parent | 2609fa7311c7536b8e8412f213576568f0f61957 (diff) | |
parent | 44c19eccf9fd8258f8d939fe30b79b644b2c235a (diff) | |
download | cpython-503ba3ed973d8e82ea5e38cb287d4127fccf51b8.zip cpython-503ba3ed973d8e82ea5e38cb287d4127fccf51b8.tar.gz cpython-503ba3ed973d8e82ea5e38cb287d4127fccf51b8.tar.bz2 |
Merge 3.5 (issue #27456)
Diffstat (limited to 'Lib/asyncio/selector_events.py')
-rw-r--r-- | Lib/asyncio/selector_events.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 1850bdb..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. @@ -641,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, |