From 7de4d645a5e268d202409b35d797b3db09eec476 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 10 Jul 2001 11:50:09 +0000 Subject: [PATCH] IMPORTANT FIX: This should definitely go into the 2.1.1 release!!! Fix various serious problems: - The ThreadingTCPServer class and its derived classes were completely broken because the main thread would close the request before the handler thread had time to look at it. This was introduced by Ping's close_request() patch. The fix moves the close_request() calls to after the handler has run to completion in the BaseServer class and the ForkingMixIn class; when using the ThreadingMixIn, closing the request is the handler's responsibility. - The ForkingUDPServer class has always been been broken because the socket was closed in the child before calling the handler. I fixed this by simply not calling server_close() in the child at all. - I cannot get the UnixDatagramServer class to work at all. The recvfrom() call doesn't return a meaningful client address. I added a comment to this effect. Maybe it works on other Unix versions. - The __all__ variable was missing ThreadingMixIn and ForkingMixIn. - Bumped __version__ to "0.4". - Added a note about the test suite (to be checked in shortly). --- Lib/SocketServer.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py index e5863b5adb3..e52dddc3b2d 100644 --- a/Lib/SocketServer.py +++ b/Lib/SocketServer.py @@ -120,7 +120,12 @@ BaseServer: # Author of the BaseServer patch: Luke Kenneth Casson Leighton -__version__ = "0.3" +# XXX Warning! +# There is a test suite for this module, but it cannot be run by the +# standard regression test. +# To run it manually, run Lib/test/test_socketserver.py. + +__version__ = "0.4" import socket @@ -129,7 +134,8 @@ import os __all__ = ["TCPServer","UDPServer","ForkingUDPServer","ForkingTCPServer", "ThreadingUDPServer","ThreadingTCPServer","BaseRequestHandler", - "StreamRequestHandler","DatagramRequestHandler"] + "StreamRequestHandler","DatagramRequestHandler", + "ThreadingMixIn", "ForkingMixIn"] if hasattr(socket, "AF_UNIX"): __all__.extend(["UnixStreamServer","UnixDatagramServer", "ThreadingUnixStreamServer", @@ -215,7 +221,7 @@ class BaseServer: self.process_request(request, client_address) except: self.handle_error(request, client_address) - self.close_request(request) + self.close_request(request) def verify_request(self, request, client_address): """Verify the request. May be overridden. @@ -232,6 +238,7 @@ class BaseServer: """ self.finish_request(request, client_address) + self.close_request(request) def server_close(self): """Called to clean-up the server. @@ -423,18 +430,17 @@ class ForkingMixIn: if self.active_children is None: self.active_children = [] self.active_children.append(pid) + self.close_request(request) return else: # Child process. # This must never return, hence os._exit()! try: - self.server_close() self.finish_request(request, client_address) os._exit(0) except: try: - self.handle_error(request, - client_address) + self.handle_error(request, client_address) finally: os._exit(1) @@ -545,6 +551,9 @@ class StreamRequestHandler(BaseRequestHandler): class DatagramRequestHandler(BaseRequestHandler): + # XXX Regrettably, I cannot get this working on Linux; + # s.recvfrom() doesn't return a meaningful client address. + """Define self.rfile and self.wfile for datagram sockets.""" def setup(self):