[svn] commit: r3079 - /branches/trac299/src/bin/xfrout/xfrout.py.in
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Sep 30 05:18:45 UTC 2010
Author: chenzhengzhang
Date: Thu Sep 30 05:18:45 2010
New Revision: 3079
Log:
add xfrout session shutdown socket pair
Modified:
branches/trac299/src/bin/xfrout/xfrout.py.in
Modified: branches/trac299/src/bin/xfrout/xfrout.py.in
==============================================================================
--- branches/trac299/src/bin/xfrout/xfrout.py.in (original)
+++ branches/trac299/src/bin/xfrout/xfrout.py.in Thu Sep 30 05:18:45 2010
@@ -57,7 +57,7 @@
MAX_TRANSFERS_OUT = 10
VERBOSE_MODE = False
-SESSION_RUNNABLE = True
+SESSION_RUNNABLE = False
XFROUT_MAX_MESSAGE_SIZE = 65535
def get_rrset_len(rrset):
@@ -68,16 +68,29 @@
class XfroutSession(BaseRequestHandler):
- def __init__(self, request, client_address, server, log):
+ def __init__(self, request, client_address, server, log, sock):
# The initializer for the superclass may call functions
# that need _log to be set, so we set it first
self._log = log
+ self._shutdown_sock = sock
BaseRequestHandler.__init__(self, request, client_address, server)
def handle(self):
# Handle a request until shutdown or xfrout client is closed.
- global SESSION_RUNNABLE
+ global SESSION_RUNNABLE
+ SESSION_RUNNABLE = True
while SESSION_RUNNABLE:
+ try:
+ rlist, wlist, xlist = select.select([self._shutdown_sock, self.request], [], [])
+ except select.error as e:
+ if e.args[0] == errno.EINTR:
+ (rlist, wlist, xlist) = ([], [], [])
+ else:
+ sys.stderr.write("[b10-xfrout] Error with select(): %s\n" %e)
+ break
+ if self._shutdown_sock in rlist:
+ break
+
fd = recv_fd(self.request.fileno())
if fd < 0:
@@ -86,7 +99,7 @@
# xfrout running.
if fd == -2:
self._log.log_message("error", "Failed to receive the file descriptor for XFR connection")
- break
+ break
data_len = self.request.recv(2)
if not data_len:
@@ -271,6 +284,7 @@
for rr_data in sqlite3_ds.get_zone_datas(zone_name, self.server.get_db_file()):
if self.server._shutdown_event.is_set(): # Check if xfrout is shutdown
self._log.log_message("error", "shutdown!")
+ return
# TODO: RRType.SOA() ?
if RRType(rr_data[5]) == RRType("SOA"): #ignore soa record
@@ -304,13 +318,14 @@
self._lock = threading.Lock()
self._transfers_counter = 0
self._shutdown_event = shutdown_event
+ self._master_sock, self._slave_sock = socket.socketpair()
self._log = log
self.update_config_data(config_data)
self._cc = cc
def finish_request(self, request, client_address):
'''Finish one request by instantiating RequestHandlerClass.'''
- self.RequestHandlerClass(request, client_address, self, self._log)
+ self.RequestHandlerClass(request, client_address, self, self._log, self._slave_sock)
def _remove_unused_sock_file(self, sock_file):
'''Try to remove the socket file. If the file is being used
@@ -346,6 +361,7 @@
def shutdown(self):
global SESSION_RUNNABLE
SESSION_RUNNABLE = False
+ self._master_sock.send(b"shutdown") # terminate the xfrout session thread
ThreadingUnixStreamServer.shutdown(self)
try:
os.unlink(self._sock_file)
@@ -405,7 +421,7 @@
# again.
if err.args[0] != errno.EINTR: raise
-
+
class XfroutServer:
def __init__(self):
More information about the bind10-changes
mailing list