[svn] commit: r1418 - in /trunk/src: bin/bindctl/bindctl.py.in bin/cmdctl/cmdctl.py.in lib/python/isc/cc/session.py

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Mar 15 16:42:10 UTC 2010


Author: jelte
Date: Mon Mar 15 16:42:10 2010
New Revision: 1418

Log:
added a feature (yes i know, but this is a serious problem) to cc/session.py;
if you pass recvmsg() or group_recvmsg() the sequence number you got back from send(), it will only give back the answer to your message (which should be sent back with group_reply()); other messages are queued and returned on subsequent calls of recvmsg()

this should fix at least the Bad config version some people have been having (which were caused by other messages getting in before the answer to certain requests made by cmdctl)

it's only in the python version, and i would like someone to take a good look at this change (perhaps the api of this part can be better, and possibly a limit on how many messages are queued). If people are ok with this solution we'll add it to the cpp version too

Added:
    trunk/src/bin/bindctl/bindctl.py.in
      - copied, changed from r1410, trunk/src/bin/bindctl/bindctl.py.in
Modified:
    trunk/src/bin/cmdctl/cmdctl.py.in
    trunk/src/lib/python/isc/cc/session.py

Modified: trunk/src/bin/cmdctl/cmdctl.py.in
==============================================================================
--- trunk/src/bin/cmdctl/cmdctl.py.in (original)
+++ trunk/src/bin/cmdctl/cmdctl.py.in Mon Mar 15 16:42:10 2010
@@ -296,9 +296,9 @@
         print('b10-cmdctl send command \'%s\' to %s' %(command_name, module_name))
         try:
             msg = isc.config.ccsession.create_command(command_name, params)
-            self.cc.group_sendmsg(msg, module_name)
+            seq = self.cc.group_sendmsg(msg, module_name)
             #TODO, it may be blocked, msqg need to add a new interface waiting in timeout.
-            answer, env = self.cc.group_recvmsg(False)
+            answer, env = self.cc.group_recvmsg(False, seq)
             if answer:
                 try:
                     rcode, arg = isc.config.ccsession.parse_answer(answer)

Modified: trunk/src/lib/python/isc/cc/session.py
==============================================================================
--- trunk/src/lib/python/isc/cc/session.py (original)
+++ trunk/src/lib/python/isc/cc/session.py Mon Mar 15 16:42:10 2010
@@ -32,6 +32,7 @@
         self._recvlength = 0
         self._sequence = 1
         self._closed = False
+        self._queue = []
 
         try:
             self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -75,7 +76,18 @@
         if msg:
             self._socket.send(msg)
 
-    def recvmsg(self, nonblock = True):
+    def recvmsg(self, nonblock = True, seq = None):
+        if len(self._queue) > 0:
+            if seq == None:
+                msg, env = self._queue.pop(0)
+            else:
+                i = 0;
+                for msg, env in self._queue:
+                    if "reply" in env and seq == env["reply"]:
+                        self._queue.remove(i)
+                        return env, msg
+                    else:
+                        i = i + 1
         if self._closed:
             raise SessionError("Session has been closed.")
         data = self._receive_full_buffer(nonblock)
@@ -83,7 +95,13 @@
             header_length = struct.unpack('>H', data[0:2])[0]
             data_length = len(data) - 2 - header_length
             if data_length > 0:
-                return isc.cc.message.from_wire(data[2:header_length+2]), isc.cc.message.from_wire(data[header_length + 2:])
+                env = isc.cc.message.from_wire(data[2:header_length+2])
+                msg = isc.cc.message.from_wire(data[header_length + 2:])
+                if seq == None or "reply" in env and seq == env["reply"]:
+                    return env, msg
+                else:
+                    self._queue.append((env,msg))
+                    self.recvmsg(nonblock, seq)
             else:
                 return isc.cc.message.from_wire(data[2:header_length+2]), None
         return None, None
@@ -155,8 +173,8 @@
         }, isc.cc.message.to_wire(msg))
         return seq
 
-    def group_recvmsg(self, nonblock = True):
-        env, msg  = self.recvmsg(nonblock)
+    def group_recvmsg(self, nonblock = True, seq = None):
+        env, msg  = self.recvmsg(nonblock, seq)
         if env == None:
             # return none twice to match normal return value
             # (so caller won't get a type error on no data)




More information about the bind10-changes mailing list