BIND 10 trac1454, updated. a842f40cddc919f5bb0aa68943fd7ef7b8938a04 [1454] The handle_incoming request

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Jan 3 18:17:16 UTC 2012


The branch, trac1454 has been updated
       via  a842f40cddc919f5bb0aa68943fd7ef7b8938a04 (commit)
       via  b6aa3ff5422ec34da9c413aabff15145d86596e6 (commit)
      from  9af13dfc788b7ddf5667545aa483ced00c349a20 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a842f40cddc919f5bb0aa68943fd7ef7b8938a04
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Jan 3 19:15:43 2012 +0100

    [1454] The handle_incoming request
    
    Reads the request and passes it to be handled. If it fails, the
    connection is closed.

commit b6aa3ff5422ec34da9c413aabff15145d86596e6
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Jan 3 17:28:29 2012 +0100

    [1454] Call handle_incoming when there's data

-----------------------------------------------------------------------

Summary of changes:
 src/bin/ddns/ddns.py.in         |   32 ++++++++++++++++++++-
 src/bin/ddns/tests/ddns_test.py |   59 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 2 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/ddns/ddns.py.in b/src/bin/ddns/ddns.py.in
index b5a0383..47f4435 100755
--- a/src/bin/ddns/ddns.py.in
+++ b/src/bin/ddns/ddns.py.in
@@ -138,6 +138,33 @@ class DDNSServer:
         session = isc.util.io.socketsession.SocketSessionReceiver(socket)
         self._socket_sessions[fileno] = (socket, session)
 
+    def handle_request(self, request):
+        """
+        This is called whenever a new DDNS request comes. Here the magic
+        happens, the rest is either subroutines of the magic or the accounting
+        around it that calls it from time to time.
+
+        It is called with the request being session as received from
+        SocketSessionReceiver, eg. tupple
+        (socket, local_address, remote_address, data).
+        """
+        # TODO: Implement the magic
+        pass
+
+    def handle_incoming(self, fileno):
+        """
+        Handle incoming event on the socket with given fileno.
+        """
+        (socket, session) = self._socket_sessions[fileno]
+        try:
+            request = session.pop()
+            self.handle_request(request)
+        except isc.util.io.socketsession.SocketSessionError:
+            # No matter why this failed, the connection is in unknown, possibly
+            # broken state. So, we close the socket and remove the session.
+            del self._socket_sessions[fileno]
+            socket.close()
+
     def run(self):
         '''
         Get and process all commands sent from cfgmgr or other modules.
@@ -155,14 +182,15 @@ class DDNSServer:
 
             # TODO: Catch select exceptions, like EINTR
             (reads, writes, exceptions) = \
-                select.select([cc_fileno, listen_fileno], [], [])
+                select.select([cc_fileno, listen_fileno] +
+                              list(self._socket_sessions.keys()), [], [])
             for fileno in reads:
                 if fileno == cc_fileno:
                     self._cc.check_command(True)
                 elif fileno == listen_fileno:
                     self.accept()
                 else:
-                    pass # TODO
+                    self.handle_incoming(fileno)
         self.shutdown_cleanup()
         logger.info(DDNS_STOPPED)
 
diff --git a/src/bin/ddns/tests/ddns_test.py b/src/bin/ddns/tests/ddns_test.py
index 53ecfd2..0ae1976 100755
--- a/src/bin/ddns/tests/ddns_test.py
+++ b/src/bin/ddns/tests/ddns_test.py
@@ -202,6 +202,65 @@ class TestDDNSServer(unittest.TestCase):
         self.assertTrue(isinstance(session, FakeSession))
         self.assertEqual(socket, session.socket())
 
+    def test_incoming_called(self):
+        """
+        Test the run calls handle_incoming when there's something on the
+        socket.
+        """
+        socket = FakeSocket(3)
+        self.ddns_server._socket_sessions = {3: (socket, FakeSession(socket))}
+        self.ddns_server.handle_incoming = self.__hook
+        self.__select_expected = ([1, 2, 3], [], [], None)
+        self.__select_answer = ([3], [], [])
+        self.ddns_server.run()
+        self.assertTrue(self.ddns_server._shutdown)
+        self.assertIsNone(self.__select_answer)
+        self.assertEqual(3, self.__hook_called)
+
+    def test_handle_incoming_ok(self):
+        """
+        Test the handle_incoming pops the session and calls handle_request
+        when everything is OK.
+        """
+        socket = FakeSocket(3)
+        session = FakeSession(socket)
+        # It doesn't really matter what data we use here, it is only passed
+        # through the code
+        param = (FakeSocket(4), ('127.0.0.1', 1234), ('127.0.0.1', 1235),
+                 'Some data')
+        def pop():
+            return param
+        # Prepare data into the session
+        session.pop = pop
+        self.ddns_server._socket_sessions = {3: (socket, session)}
+        self.ddns_server.handle_request = self.__hook
+        # Call it
+        self.ddns_server.handle_incoming(3)
+        # The popped data are passed into the handle_request
+        self.assertEqual(param, self.__hook_called)
+        # The sessions are kept the same
+        self.assertEqual({3: (socket, session)},
+                         self.ddns_server._socket_sessions)
+
+    def test_handle_incoming_fail(self):
+        """
+        Test the handle_incoming removes (and closes) the socket and session
+        when the session complains.
+        """
+        socket = FakeSocket(3)
+        session = FakeSession(socket)
+        def pop():
+            raise isc.util.io.socketsession.SocketSessionError('Test error')
+        session.pop = pop
+        socket.close = self.__hook
+        self.__hook_called = False
+        self.ddns_server._socket_sessions = {3: (socket, session)}
+        self.ddns_server.handle_incoming(3)
+        # The "dead" session is removed
+        self.assertEqual({}, self.ddns_server._socket_sessions)
+        # Close is called with no parameter, so the default None
+        self.assertIsNone(self.__hook_called)
+
 class TestMain(unittest.TestCase):
     def setUp(self):
         self._server = MyDDNSServer()




More information about the bind10-changes mailing list