[Zope-Checkins] CVS: Zope/ZServer - FTPServer.py:1.24 HTTPServer.py:1.43 ICPServer.py:1.3

Toby Dickenson tdickenson@geminidataloggers.com
Mon, 4 Nov 2002 08:34:17 -0500


Update of /cvs-repository/Zope/ZServer
In directory cvs.zope.org:/tmp/cvs-serv11475/ZServer

Modified Files:
	FTPServer.py HTTPServer.py ICPServer.py 
Log Message:
clean shutdown

=== Zope/ZServer/FTPServer.py 1.23 => 1.24 ===
--- Zope/ZServer/FTPServer.py:1.23	Wed Aug 14 17:16:50 2002
+++ Zope/ZServer/FTPServer.py	Mon Nov  4 08:33:46 2002
@@ -609,6 +609,11 @@
                         self.port
                         ))
 
+    def clean_shutdown_control(self,phase,time_in_this_phase):
+        if phase==2:
+            self.log_info('closing FTP to new connections')
+            self.close()
+
     def log_info(self, message, type='info'):
         if self.shutup: return
         asyncore.dispatcher.log_info(self, message, type)


=== Zope/ZServer/HTTPServer.py 1.42 => 1.43 ===
--- Zope/ZServer/HTTPServer.py:1.42	Thu Oct  3 22:31:23 2002
+++ Zope/ZServer/HTTPServer.py	Mon Nov  4 08:33:46 2002
@@ -281,7 +281,8 @@
 class zhttp_channel(http_channel):
     "http channel"
 
-    closed=0
+    closed = 0
+    no_more_requests = 0
     zombie_timeout=100*60 # 100 minutes
     max_header_len = 8196
 
@@ -302,10 +303,23 @@
 
     push_with_producer=push
 
+    def clean_shutdown_control(self,phase,time_in_this_phase):
+        if phase==3:
+            # This is the shutdown phase where we are trying to finish processing
+            # outstanding requests, and not accept any more
+            self.no_more_requests = 1
+            if self.working or self.writable():
+                # We are busy working on an old request. Try to stall shutdown
+                return 1
+            else:
+                # We are no longer busy. Close ourself and allow shutdown to proceed
+                self.close()
+                return 0
+
     def work(self):
         "try to handle a request"
         if not self.working:
-            if self.queue:
+            if self.queue and not self.no_more_requests:
                 self.working=1
                 try: module_name, request, response=self.queue.pop(0)
                 except: return
@@ -367,6 +381,11 @@
                         self.server_name,
                         self.server_port
                         ))
+
+    def clean_shutdown_control(self,phase,time_in_this_phase):
+        if phase==2:
+            self.log_info('closing HTTP to new connections')
+            self.close()
 
     def log_info(self, message, type='info'):
         if self.shutup: return


=== Zope/ZServer/ICPServer.py 1.2 => 1.3 ===
--- Zope/ZServer/ICPServer.py:1.2	Wed Aug 14 17:16:50 2002
+++ Zope/ZServer/ICPServer.py	Mon Nov  4 08:33:46 2002
@@ -33,6 +33,7 @@
 class BaseICPServer(asyncore.dispatcher):
 
     REQUESTS_PER_LOOP = 4
+    _shutdown = 0
 
     def __init__ (self,ip,port):
         asyncore.dispatcher.__init__(self)
@@ -45,6 +46,21 @@
             addr = ip
         self.log_info('ICP server started\n\tAddress: %s\n\tPort: %s' % (addr,port) )
 
+    def clean_shutdown_control(self,phase,time_in_this_phase):
+        if phase==1:
+            # Stop responding to requests.
+            if not self._shutdown:
+                self._shutdown = 1
+                self.log_info('shutting down ICP')
+            if time_in_this_phase<2.0:
+                # We have not yet been deaf long enough for our front end proxies to notice.
+                # Do not allow shutdown to proceed yet
+                return 1
+            else:
+                # Shutdown can proceed. We dont need a socket any more
+                self.close()
+                return 0
+
     def handle_read(self):
         for i in range(self.REQUESTS_PER_LOOP):
             try:
@@ -61,7 +77,7 @@
                         self.socket.sendto(reply,whence)
 
     def readable(self):
-        return 1
+        return not self._shutdown
 
     def writable(self):
         return 0