|
@@ -52,8 +52,14 @@ class BIND10Server:
|
|
initialization. This is called after the module CC
|
|
initialization. This is called after the module CC
|
|
session has started, and can be used for registering
|
|
session has started, and can be used for registering
|
|
interest on remote modules, etc. If it raises an
|
|
interest on remote modules, etc. If it raises an
|
|
- exception, the server will be immediatelly stopped.
|
|
|
|
|
|
+ exception, the server will be immediately stopped.
|
|
Parameter: None, Return: None
|
|
Parameter: None, Return: None
|
|
|
|
+ _shutdown_module: can be optionally defined for module-specific
|
|
|
|
+ finalization. This is called right before the
|
|
|
|
+ module CC session is stopped. If it raises an
|
|
|
|
+ exception, the server will be immediately
|
|
|
|
+ stopped.
|
|
|
|
+ Parameter: None, Return: None
|
|
|
|
|
|
"""
|
|
"""
|
|
# Will be set to True when the server should stop and shut down.
|
|
# Will be set to True when the server should stop and shut down.
|
|
@@ -72,6 +78,11 @@ class BIND10Server:
|
|
# Basically constant, but allow tests to override it.
|
|
# Basically constant, but allow tests to override it.
|
|
_select_fn = select.select
|
|
_select_fn = select.select
|
|
|
|
|
|
|
|
+ def __init__(self):
|
|
|
|
+ self._read_callbacks = {}
|
|
|
|
+ self._write_callbacks = {}
|
|
|
|
+ self._error_callbacks = {}
|
|
|
|
+
|
|
@property
|
|
@property
|
|
def shutdown(self):
|
|
def shutdown(self):
|
|
return self.__shutdown
|
|
return self.__shutdown
|
|
@@ -141,7 +152,13 @@ class BIND10Server:
|
|
cc_fileno = self._mod_cc.get_socket().fileno()
|
|
cc_fileno = self._mod_cc.get_socket().fileno()
|
|
while not self.__shutdown:
|
|
while not self.__shutdown:
|
|
try:
|
|
try:
|
|
- (reads, _, _) = self._select_fn([cc_fileno], [], [])
|
|
|
|
|
|
+ read_fds = list(self._read_callbacks.keys())
|
|
|
|
+ read_fds.append(cc_fileno)
|
|
|
|
+ write_fds = list(self._write_callbacks.keys())
|
|
|
|
+ error_fds = list(self._error_callbacks.keys())
|
|
|
|
+
|
|
|
|
+ (reads, writes, errors) = \
|
|
|
|
+ self._select_fn(read_fds, write_fds, error_fds)
|
|
except select.error as ex:
|
|
except select.error as ex:
|
|
# ignore intterruption by signal; regard other select errors
|
|
# ignore intterruption by signal; regard other select errors
|
|
# fatal.
|
|
# fatal.
|
|
@@ -149,12 +166,28 @@ class BIND10Server:
|
|
continue
|
|
continue
|
|
else:
|
|
else:
|
|
raise
|
|
raise
|
|
- for fileno in reads:
|
|
|
|
- if fileno == cc_fileno:
|
|
|
|
- # this shouldn't raise an exception (if it does, we'll
|
|
|
|
- # propagate it)
|
|
|
|
- self._mod_cc.check_command(True)
|
|
|
|
|
|
|
|
|
|
+ for fileno in reads:
|
|
|
|
+ if fileno in self._read_callbacks:
|
|
|
|
+ for callback in self._read_callbacks[fileno]:
|
|
|
|
+ callback()
|
|
|
|
+
|
|
|
|
+ for fileno in writes:
|
|
|
|
+ if fileno in self._write_callbacks:
|
|
|
|
+ for callback in self._write_callbacks[fileno]:
|
|
|
|
+ callback()
|
|
|
|
+
|
|
|
|
+ for fileno in errors:
|
|
|
|
+ if fileno in self._error_callbacks:
|
|
|
|
+ for callback in self._error_callbacks[fileno]:
|
|
|
|
+ callback()
|
|
|
|
+
|
|
|
|
+ if cc_fileno in reads:
|
|
|
|
+ # this shouldn't raise an exception (if it does, we'll
|
|
|
|
+ # propagate it)
|
|
|
|
+ self._mod_cc.check_command(True)
|
|
|
|
+
|
|
|
|
+ self._shutdown_module()
|
|
self._mod_cc.send_stopping()
|
|
self._mod_cc.send_stopping()
|
|
|
|
|
|
def _command_handler(self, cmd, args):
|
|
def _command_handler(self, cmd, args):
|
|
@@ -173,9 +206,38 @@ class BIND10Server:
|
|
return isc.config.create_answer(1, "Unknown command: " + str(cmd))
|
|
return isc.config.create_answer(1, "Unknown command: " + str(cmd))
|
|
|
|
|
|
def _setup_module(self):
|
|
def _setup_module(self):
|
|
- """The default implementation of the module specific initilization"""
|
|
|
|
|
|
+ """The default implementation of the module specific initialization"""
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
+ def _shutdown_module(self):
|
|
|
|
+ """The default implementation of the module specific finalization"""
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+ def watch_fileno(self, fileno, rcallback=None, wcallback=None, \
|
|
|
|
+ xcallback=None):
|
|
|
|
+ """Register the fileno for the internal select() call.
|
|
|
|
+
|
|
|
|
+ *callback's are callable objects which would be called when
|
|
|
|
+ read, write, error events occur on the specified fileno.
|
|
|
|
+ """
|
|
|
|
+ if rcallback is not None:
|
|
|
|
+ if fileno in self._read_callbacks:
|
|
|
|
+ self._read_callbacks[fileno].append(rcallback)
|
|
|
|
+ else:
|
|
|
|
+ self._read_callbacks[fileno] = [rcallback]
|
|
|
|
+
|
|
|
|
+ if wcallback is not None:
|
|
|
|
+ if fileno in self._write_callbacks:
|
|
|
|
+ self._write_callbacks[fileno].append(wcallback)
|
|
|
|
+ else:
|
|
|
|
+ self._write_callbacks[fileno] = [wcallback]
|
|
|
|
+
|
|
|
|
+ if xcallback is not None:
|
|
|
|
+ if fileno in self._error_callbacks:
|
|
|
|
+ self._error_callbacks[fileno].append(xcallback)
|
|
|
|
+ else:
|
|
|
|
+ self._error_callbacks[fileno] = [xcallback]
|
|
|
|
+
|
|
def run(self, module_name):
|
|
def run(self, module_name):
|
|
"""Start the server and let it run until it's told to stop.
|
|
"""Start the server and let it run until it's told to stop.
|
|
|
|
|