Browse Source

Change the server code of cmdctl and xfrout, use mixin class and mutiple inheritance to avoid the naive old serve_forever() provided by python library.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac352@3076 e5f2f494-b856-4b98-b285-d166d9295462
Likun Zhang 14 years ago
parent
commit
94c0eadb2c
2 changed files with 8 additions and 23 deletions
  1. 3 1
      src/bin/cmdctl/cmdctl.py.in
  2. 5 22
      src/bin/xfrout/xfrout.py.in

+ 3 - 1
src/bin/cmdctl/cmdctl.py.in

@@ -45,6 +45,8 @@ from isc.config import ccsession
 import isc.utils.process
 import isc.utils.process
 from optparse import OptionParser, OptionValueError
 from optparse import OptionParser, OptionValueError
 from hashlib import sha1
 from hashlib import sha1
+from isc.utils import serve_mixin
+
 try:
 try:
     import threading
     import threading
 except ImportError:
 except ImportError:
@@ -439,7 +441,7 @@ class CommandControl():
 
 
         return (keyfile, certfile, accountsfile)
         return (keyfile, certfile, accountsfile)
 
 
-class SecureHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
+class SecureHTTPServer(serve_mixin.ServeMixIn, socketserver.ThreadingMixIn, http.server.HTTPServer):
     '''Make the server address can be reused.'''
     '''Make the server address can be reused.'''
     allow_reuse_address = True
     allow_reuse_address = True
 
 

+ 5 - 22
src/bin/xfrout/xfrout.py.in

@@ -34,6 +34,8 @@ import socket
 import select
 import select
 import errno
 import errno
 from optparse import OptionParser, OptionValueError
 from optparse import OptionParser, OptionValueError
+from isc.utils import serve_mixin
+
 try:
 try:
     from libxfr_python import *
     from libxfr_python import *
     from pydnspp import *
     from pydnspp import *
@@ -289,7 +291,7 @@ class XfroutSession(BaseRequestHandler):
 
 
         self._send_message_with_last_soa(msg, sock, rrset_soa, message_upper_len)
         self._send_message_with_last_soa(msg, sock, rrset_soa, message_upper_len)
 
 
-class UnixSockServer(ThreadingUnixStreamServer):
+class UnixSockServer(serve_mixin.ServeMixIn, ThreadingUnixStreamServer):
     '''The unix domain socket server which accept xfr query sent from auth server.'''
     '''The unix domain socket server which accept xfr query sent from auth server.'''
 
 
     def __init__(self, sock_file, handle_class, shutdown_event, config_data, cc, log):
     def __init__(self, sock_file, handle_class, shutdown_event, config_data, cc, log):
@@ -339,7 +341,7 @@ class UnixSockServer(ThreadingUnixStreamServer):
             return True 
             return True 
 
 
     def shutdown(self):
     def shutdown(self):
-        ThreadingUnixStreamServer.shutdown(self)
+        super().shutdown() # call the shutdown() of class serve_mixin.ServeMinIn
         try:
         try:
             os.unlink(self._sock_file)
             os.unlink(self._sock_file)
         except Exception as e:
         except Exception as e:
@@ -381,25 +383,6 @@ class UnixSockServer(ThreadingUnixStreamServer):
         self._transfers_counter -= 1
         self._transfers_counter -= 1
         self._lock.release()
         self._lock.release()
 
 
-def listen_on_xfr_query(unix_socket_server):
-    '''Listen xfr query in one single thread. Polls for shutdown 
-    every 0.1 seconds, is there a better time?
-    '''
-
-    while True:
-        try:
-            unix_socket_server.serve_forever(poll_interval = 0.1)
-        except select.error as err:
-            # serve_forever() calls select.select(), which can be 
-            # interrupted.
-            # If it is interrupted, it raises select.error with the 
-            # errno set to EINTR. We ignore this case, and let the
-            # normal program flow continue by trying serve_forever()
-            # again.
-            if err.args[0] != errno.EINTR: raise
-
-   
-
 class XfroutServer:
 class XfroutServer:
     def __init__(self):
     def __init__(self):
         self._unix_socket_server = None
         self._unix_socket_server = None
@@ -421,7 +404,7 @@ class XfroutServer:
         self._unix_socket_server = UnixSockServer(self._listen_sock_file, XfroutSession, 
         self._unix_socket_server = UnixSockServer(self._listen_sock_file, XfroutSession, 
                                                   self._shutdown_event, self._config_data,
                                                   self._shutdown_event, self._config_data,
                                                   self._cc, self._log);
                                                   self._cc, self._log);
-        listener = threading.Thread(target = listen_on_xfr_query, args = (self._unix_socket_server,))
+        listener = threading.Thread(target=self._unix_socket_server.serve_forever)
         listener.start()
         listener.start()
         
         
     def _start_notifier(self):
     def _start_notifier(self):