Skip to content

Commit

Permalink
Try to make sure TCP_NODELAY is set on INET sockets.
Browse files Browse the repository at this point in the history
This is a nasty work around for: https://bugs.python.org/issue27456

It can't always be applied.  For example, it can't be applied to Linux
SSL sockets using the asyncio-provided loop.
  • Loading branch information
Jim Fulton committed Jul 6, 2016
1 parent 48defe9 commit 3d886d4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ZEO/asyncio/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from struct import unpack
import asyncio
import logging
import socket
import sys

from .marshal import encoder

logger = logging.getLogger(__name__)

INET_FAMILIES = socket.AF_INET, socket.AF_INET6

class Protocol(asyncio.Protocol):
"""asyncio low-level ZEO base interface
"""
Expand Down Expand Up @@ -41,7 +45,16 @@ def close(self):

def connection_made(self, transport):
logger.info("Connected %s", self)

if (sys.version_info < (3, 6) and
hasattr(transport, '_sock') and
transport._sock.family in INET_FAMILIES
):
# See https://bugs.python.org/issue27456 :(
transport._sock.setsockopt(
socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
self.transport = transport

paused = self.paused
output = self.output
append = output.append
Expand Down

0 comments on commit 3d886d4

Please sign in to comment.