summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2009-06-24 09:17:04 (GMT)
committerKristján Valur Jónsson <kristjan@ccpgames.com>2009-06-24 09:17:04 (GMT)
commitf1d11efb72a9f0612a39712658aecff7c2a5abcf (patch)
tree3394ad33b70e88a2de4d03aa659e944c5bff8d42
parent5a85d5c4f2eb09e5ab5d4c84090aee38340eb284 (diff)
downloadcpython-f1d11efb72a9f0612a39712658aecff7c2a5abcf.zip
cpython-f1d11efb72a9f0612a39712658aecff7c2a5abcf.tar.gz
cpython-f1d11efb72a9f0612a39712658aecff7c2a5abcf.tar.bz2
http://bugs.python.org/issue6192
Move the newly introduced disable_nagle_algorithm flag into the StreamRequestHandler, where it is more appropriate.
-rw-r--r--Doc/library/socketserver.rst10
-rw-r--r--Lib/SocketServer.py15
2 files changed, 8 insertions, 17 deletions
diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst
index bf93cce..d2bbba4 100644
--- a/Doc/library/socketserver.rst
+++ b/Doc/library/socketserver.rst
@@ -223,16 +223,6 @@ The server classes support the following class variables:
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
users of the server object.
diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py
index 5f8facc..7a25d0f 100644
--- a/Lib/SocketServer.py
+++ b/Lib/SocketServer.py
@@ -374,7 +374,6 @@ class TCPServer(BaseServer):
- socket_type
- request_queue_size (only for stream sockets)
- allow_reuse_address
- - disable_nagle_algorithm
Instance variables:
@@ -392,8 +391,6 @@ class TCPServer(BaseServer):
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)
@@ -444,10 +441,7 @@ class TCPServer(BaseServer):
May be overridden.
"""
- request = self.socket.accept()
- if self.disable_nagle_algorithm:
- request[0].setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
- return request
+ return self.socket.accept()
def close_request(self, request):
"""Called to clean up an individual request."""
@@ -655,8 +649,15 @@ class StreamRequestHandler(BaseRequestHandler):
rbufsize = -1
wbufsize = 0
+ # Disable nagle algoritm for this socket, if True.
+ # Use only when wbufsize != 0, to avoid small packets.
+ disable_nagle_algorithm = False
+
def setup(self):
self.connection = self.request
+ if self.disable_nagle_algorithm:
+ self.connection.setsockopt(socket.IPPROTO_TCP,
+ socket.TCP_NODELAY, True)
self.rfile = self.connection.makefile('rb', self.rbufsize)
self.wfile = self.connection.makefile('wb', self.wbufsize)