[svn] commit: r3076 - in /branches/trac352/src/bin: cmdctl/cmdctl.py.in xfrout/xfrout.py.in

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Sep 30 03:19:08 UTC 2010


Author: zhanglikun
Date: Thu Sep 30 03:19:08 2010
New Revision: 3076

Log:
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. 

Modified:
    branches/trac352/src/bin/cmdctl/cmdctl.py.in
    branches/trac352/src/bin/xfrout/xfrout.py.in

Modified: branches/trac352/src/bin/cmdctl/cmdctl.py.in
==============================================================================
--- branches/trac352/src/bin/cmdctl/cmdctl.py.in (original)
+++ branches/trac352/src/bin/cmdctl/cmdctl.py.in Thu Sep 30 03:19:08 2010
@@ -45,6 +45,8 @@
 import isc.utils.process
 from optparse import OptionParser, OptionValueError
 from hashlib import sha1
+from isc.utils import serve_mixin
+
 try:
     import threading
 except ImportError:
@@ -439,7 +441,7 @@
 
         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.'''
     allow_reuse_address = True
 

Modified: branches/trac352/src/bin/xfrout/xfrout.py.in
==============================================================================
--- branches/trac352/src/bin/xfrout/xfrout.py.in (original)
+++ branches/trac352/src/bin/xfrout/xfrout.py.in Thu Sep 30 03:19:08 2010
@@ -34,6 +34,8 @@
 import select
 import errno
 from optparse import OptionParser, OptionValueError
+from isc.utils import serve_mixin
+
 try:
     from libxfr_python import *
     from pydnspp import *
@@ -289,7 +291,7 @@
 
         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.'''
 
     def __init__(self, sock_file, handle_class, shutdown_event, config_data, cc, log):
@@ -339,7 +341,7 @@
             return True 
 
     def shutdown(self):
-        ThreadingUnixStreamServer.shutdown(self)
+        super().shutdown() # call the shutdown() of class serve_mixin.ServeMinIn
         try:
             os.unlink(self._sock_file)
         except Exception as e:
@@ -380,25 +382,6 @@
         self._lock.acquire()
         self._transfers_counter -= 1
         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:
     def __init__(self):
@@ -421,7 +404,7 @@
         self._unix_socket_server = UnixSockServer(self._listen_sock_file, XfroutSession, 
                                                   self._shutdown_event, self._config_data,
                                                   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()
         
     def _start_notifier(self):




More information about the bind10-changes mailing list