[svn] commit: r3366 - in /trunk: ./ src/bin/cmdctl/ src/bin/xfrout/ src/lib/python/isc/utils/ src/lib/python/isc/utils/tests/

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Oct 27 06:30:43 UTC 2010


Author: zhanglikun
Date: Wed Oct 27 06:30:43 2010
New Revision: 3366

Log:
merge trac352 to trunk.

Added:
    trunk/src/lib/python/isc/utils/socketserver_mixin.py
      - copied unchanged from r3365, branches/trac352/src/lib/python/isc/utils/socketserver_mixin.py
    trunk/src/lib/python/isc/utils/tests/socketserver_mixin_test.py
      - copied unchanged from r3365, branches/trac352/src/lib/python/isc/utils/tests/socketserver_mixin_test.py
Modified:
    trunk/   (props changed)
    trunk/ChangeLog
    trunk/src/bin/cmdctl/cmdctl.py.in   (contents, props changed)
    trunk/src/bin/xfrout/xfrout.py.in
    trunk/src/lib/python/isc/utils/Makefile.am
    trunk/src/lib/python/isc/utils/__init__.py
    trunk/src/lib/python/isc/utils/tests/Makefile.am

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog (original)
+++ trunk/ChangeLog Wed Oct 27 06:30:43 2010
@@ -1,3 +1,9 @@
+  112.	[func]		zhang likun
+	Add one mixin class to override the naive serve_forever() provided
+	in python library socketserver. Instead of polling for shutdwon
+	every poll_interval seconds, one socketpair is used to wake up
+	the waiting server.(Trac #352, svn TBD)
+
   111.	[bug]*   zhanglikun, Michal Vaner
 	Make sure process xfrin/xfrout/zonemgr/cmdctl can be stoped
 	properly when user enter "ctrl+c" or 'Boss shutdown' command

Modified: trunk/src/bin/cmdctl/cmdctl.py.in
==============================================================================
--- trunk/src/bin/cmdctl/cmdctl.py.in (original)
+++ trunk/src/bin/cmdctl/cmdctl.py.in Wed Oct 27 06:30:43 2010
@@ -47,6 +47,8 @@
 import isc.utils.process
 from optparse import OptionParser, OptionValueError
 from hashlib import sha1
+from isc.utils import socketserver_mixin
+
 try:
     import threading
 except ImportError:
@@ -441,7 +443,9 @@
 
         return (keyfile, certfile, accountsfile)
 
-class SecureHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
+class SecureHTTPServer(socketserver_mixin.NoPollMixIn,
+                       socketserver.ThreadingMixIn,
+                       http.server.HTTPServer):
     '''Make the server address can be reused.'''
     allow_reuse_address = True
 
@@ -449,6 +453,7 @@
                  CommandControlClass,
                  idle_timeout = 1200, verbose = False):
         '''idle_timeout: the max idle time for login'''
+        socketserver_mixin.NoPollMixIn.__init__(self)
         try:
             http.server.HTTPServer.__init__(self, server_address, RequestHandlerClass)
         except socket.error as err:

Modified: trunk/src/bin/xfrout/xfrout.py.in
==============================================================================
--- trunk/src/bin/xfrout/xfrout.py.in (original)
+++ trunk/src/bin/xfrout/xfrout.py.in Wed Oct 27 06:30:43 2010
@@ -35,6 +35,8 @@
 import select
 import errno
 from optparse import OptionParser, OptionValueError
+from isc.utils import socketserver_mixin
+
 try:
     from libxfr_python import *
     from pydnspp import *
@@ -291,12 +293,13 @@
 
         self._send_message_with_last_soa(msg, sock, rrset_soa, message_upper_len)
 
-class UnixSockServer(ThreadingUnixStreamServer):
+class UnixSockServer(socketserver_mixin.NoPollMixIn, 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):
         self._remove_unused_sock_file(sock_file)
         self._sock_file = sock_file
+        socketserver_mixin.NoPollMixIn.__init__(self)
         ThreadingUnixStreamServer.__init__(self, sock_file, handle_class)
         self._lock = threading.Lock()
         self._transfers_counter = 0
@@ -341,7 +344,7 @@
             return True 
 
     def shutdown(self):
-        ThreadingUnixStreamServer.shutdown(self)
+        super().shutdown() # call the shutdown() of class socketserver_mixin.NoPollMixIn
         try:
             os.unlink(self._sock_file)
         except Exception as e:
@@ -382,26 +385,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
-        else:
-            # serve_forever() loop has been stoped normally.
-            break
 
 class XfroutServer:
     def __init__(self):
@@ -424,7 +407,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):

Modified: trunk/src/lib/python/isc/utils/Makefile.am
==============================================================================
--- trunk/src/lib/python/isc/utils/Makefile.am (original)
+++ trunk/src/lib/python/isc/utils/Makefile.am Wed Oct 27 06:30:43 2010
@@ -1,5 +1,5 @@
 SUBDIRS = tests
 
-python_PYTHON = __init__.py process.py
+python_PYTHON = __init__.py process.py socketserver_mixin.py
 
 pythondir = $(pyexecdir)/isc/utils

Modified: trunk/src/lib/python/isc/utils/__init__.py
==============================================================================
--- trunk/src/lib/python/isc/utils/__init__.py (original)
+++ trunk/src/lib/python/isc/utils/__init__.py Wed Oct 27 06:30:43 2010
@@ -1,0 +1,1 @@
+from isc.utils.socketserver_mixin import *

Modified: trunk/src/lib/python/isc/utils/tests/Makefile.am
==============================================================================
--- trunk/src/lib/python/isc/utils/tests/Makefile.am (original)
+++ trunk/src/lib/python/isc/utils/tests/Makefile.am Wed Oct 27 06:30:43 2010
@@ -1,4 +1,4 @@
-PYTESTS = process_test.py
+PYTESTS = process_test.py socketserver_mixin_test.py
 EXTRA_DIST = $(PYTESTS)
 
 # later will have configure option to choose this, like: coverage run --branch




More information about the bind10-changes mailing list