Browse Source

[1454] Accept implemented

Michal 'vorner' Vaner 13 years ago
parent
commit
9af13dfc78
2 changed files with 12 additions and 2 deletions
  1. 6 2
      src/bin/ddns/ddns.py.in
  2. 6 0
      src/bin/ddns/tests/ddns_test.py

+ 6 - 2
src/bin/ddns/ddns.py.in

@@ -23,6 +23,7 @@ from isc.dns import *
 from isc.config.ccsession import *
 from isc.cc import SessionError, SessionTimeout
 import isc.util.process
+import isc.util.io.socketsession
 import select
 
 from isc.log_messages.ddns_messages import *
@@ -86,7 +87,7 @@ class DDNSServer:
         self._config_data = self._cc.get_full_config()
         self._cc.start()
         self._shutdown = False
-        # List of the sessions where we get the packets to handle
+        # List of the sessions where we get the packets
         self._socket_sessions = {}
 
     def config_handler(self, new_config):
@@ -132,7 +133,10 @@ class DDNSServer:
         """
         Accept another connection and create the session receiver.
         """
-        pass
+        socket = self._listen_socket.accept()
+        fileno = socket.fileno()
+        session = isc.util.io.socketsession.SocketSessionReceiver(socket)
+        self._socket_sessions[fileno] = (socket, session)
 
     def run(self):
         '''

+ 6 - 0
src/bin/ddns/tests/ddns_test.py

@@ -20,6 +20,7 @@ import isc
 import ddns
 import isc.config
 import select
+import isc.util.io.socketsession
 
 class FakeSocket:
     """
@@ -29,6 +30,8 @@ class FakeSocket:
         self.__fileno = fileno
     def fileno(self):
         return self.__fileno
+    def accept(self):
+        return FakeSocket(self.__fileno + 1)
 
 class FakeSession:
     """
@@ -102,6 +105,8 @@ class TestDDNSServer(unittest.TestCase):
 
     def tearDown(self):
         ddns.select.select = select.select
+        ddns.isc.util.io.socketsession.SocketSessionReceiver = \
+            isc.util.io.socketsession.SocketSessionReceiver
 
     def test_config_handler(self):
         # Config handler does not do anything yet, but should at least
@@ -186,6 +191,7 @@ class TestDDNSServer(unittest.TestCase):
         Test that we can accept a new connection.
         """
         # There's nothing before the accept
+        ddns.isc.util.io.socketsession.SocketSessionReceiver = FakeSession
         self.assertEqual({}, self.ddns_server._socket_sessions)
         self.ddns_server.accept()
         # Now the new session socket receiver is stored in the dict