|
@@ -35,6 +35,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 socketserver_mixin
|
|
|
|
+
|
|
try:
|
|
try:
|
|
from libxfr_python import *
|
|
from libxfr_python import *
|
|
from pydnspp import *
|
|
from pydnspp import *
|
|
@@ -291,12 +293,13 @@ 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(socketserver_mixin.NoPollMixIn, 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):
|
|
self._remove_unused_sock_file(sock_file)
|
|
self._remove_unused_sock_file(sock_file)
|
|
self._sock_file = sock_file
|
|
self._sock_file = sock_file
|
|
|
|
+ socketserver_mixin.NoPollMixIn.__init__(self)
|
|
ThreadingUnixStreamServer.__init__(self, sock_file, handle_class)
|
|
ThreadingUnixStreamServer.__init__(self, sock_file, handle_class)
|
|
self._lock = threading.Lock()
|
|
self._lock = threading.Lock()
|
|
self._transfers_counter = 0
|
|
self._transfers_counter = 0
|
|
@@ -341,7 +344,7 @@ class UnixSockServer(ThreadingUnixStreamServer):
|
|
return True
|
|
return True
|
|
|
|
|
|
def shutdown(self):
|
|
def shutdown(self):
|
|
- ThreadingUnixStreamServer.shutdown(self)
|
|
|
|
|
|
+ super().shutdown() # call the shutdown() of class socketserver_mixin.NoPollMixIn
|
|
try:
|
|
try:
|
|
os.unlink(self._sock_file)
|
|
os.unlink(self._sock_file)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -383,26 +386,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
|
|
|
|
- else:
|
|
|
|
- # serve_forever() loop has been stoped normally.
|
|
|
|
- break
|
|
|
|
-
|
|
|
|
class XfroutServer:
|
|
class XfroutServer:
|
|
def __init__(self):
|
|
def __init__(self):
|
|
self._unix_socket_server = None
|
|
self._unix_socket_server = None
|
|
@@ -424,7 +407,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):
|