[Python-checkins] CVS: python/dist/src/Lib SocketServer.py,1.24,1.24.2.1

Thomas Wouters twouters@users.sourceforge.net
Wed, 11 Jul 2001 05:05:52 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv4498/Lib

Modified Files:
      Tag: release21-maint
	SocketServer.py 
Log Message:

Backport of Guido's checkin 1.25:

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).



Index: SocketServer.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/SocketServer.py,v
retrieving revision 1.24
retrieving revision 1.24.2.1
diff -C2 -r1.24 -r1.24.2.1
*** SocketServer.py	2001/04/11 04:02:05	1.24
--- SocketServer.py	2001/07/11 12:05:49	1.24.2.1
***************
*** 121,127 ****
  # Author of the BaseServer patch: Luke Kenneth Casson Leighton
  
! __version__ = "0.3"
  
  
  import socket
  import sys
--- 121,132 ----
  # Author of the BaseServer patch: Luke Kenneth Casson Leighton
  
! # 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
  import sys
***************
*** 130,134 ****
  __all__ = ["TCPServer","UDPServer","ForkingUDPServer","ForkingTCPServer",
             "ThreadingUDPServer","ThreadingTCPServer","BaseRequestHandler",
!            "StreamRequestHandler","DatagramRequestHandler"]
  if hasattr(socket, "AF_UNIX"):
      __all__.extend(["UnixStreamServer","UnixDatagramServer",
--- 135,140 ----
  __all__ = ["TCPServer","UDPServer","ForkingUDPServer","ForkingTCPServer",
             "ThreadingUDPServer","ThreadingTCPServer","BaseRequestHandler",
!            "StreamRequestHandler","DatagramRequestHandler",
!            "ThreadingMixIn", "ForkingMixIn"]
  if hasattr(socket, "AF_UNIX"):
      __all__.extend(["UnixStreamServer","UnixDatagramServer",
***************
*** 216,220 ****
              except:
                  self.handle_error(request, client_address)
!         self.close_request(request)
  
      def verify_request(self, request, client_address):
--- 222,226 ----
              except:
                  self.handle_error(request, client_address)
!                 self.close_request(request)
  
      def verify_request(self, request, client_address):
***************
*** 233,236 ****
--- 239,243 ----
          """
          self.finish_request(request, client_address)
+         self.close_request(request)
  
      def server_close(self):
***************
*** 424,427 ****
--- 431,435 ----
                  self.active_children = []
              self.active_children.append(pid)
+             self.close_request(request)
              return
          else:
***************
*** 429,439 ****
              # 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)
                  finally:
                      os._exit(1)
--- 437,445 ----
              # This must never return, hence os._exit()!
              try:
                  self.finish_request(request, client_address)
                  os._exit(0)
              except:
                  try:
!                     self.handle_error(request, client_address)
                  finally:
                      os._exit(1)
***************
*** 545,548 ****
--- 551,557 ----
  
  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."""