desired. If :meth:`handle_request` receives no incoming requests within the
timeout period, the :meth:`handle_timeout` method is called.
+.. attribute:: TCPServer.disable_nagle_algorithm
+
+ If set to True, it will set the TCP_NODELAY attribute of new requests
+ connections. This can help alleviate problems with latency in
+ request-response type applications. To avoid sending many small packets,
+ this option should be used only when bufferning output, such as when
+ setting :attr:`StreamRequestHandler.wbufsize` attribute to -1.
+
+ .. versionadded:: 2.7
There are various server methods that can be overridden by subclasses of base
server classes like :class:`TCPServer`; these methods aren't useful to external
- socket_type
- request_queue_size (only for stream sockets)
- allow_reuse_address
+ - disable_nagle_algorithm
Instance variables:
allow_reuse_address = False
+ disable_nagle_algorithm = False
+
def __init__(self, server_address, RequestHandlerClass, bind_and_activate=True):
"""Constructor. May be extended, do not override."""
BaseServer.__init__(self, server_address, RequestHandlerClass)
May be overridden.
"""
- return self.socket.accept()
+ request = self.socket.accept()
+ if self.disable_nagle_algorithm:
+ request[0].setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
+ return request
def close_request(self, request):
"""Called to clean up an individual request."""