Browse Source

Allow ccsession to have a block command check

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac349@3004 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
70b4e32173

+ 14 - 8
src/lib/python/isc/config/ccsession.py

@@ -1,4 +1,5 @@
 # Copyright (C) 2009  Internet Systems Consortium.
 # Copyright (C) 2009  Internet Systems Consortium.
+# Copyright (C) 2010  CZ NIC
 #
 #
 # Permission to use, copy, modify, and distribute this software for any
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
 # purpose with or without fee is hereby granted, provided that the above
@@ -169,20 +170,25 @@ class ModuleCCSession(ConfigData):
            time-critical, it is strongly recommended to only use
            time-critical, it is strongly recommended to only use
            check_command(), and not look at the socket at all."""
            check_command(), and not look at the socket at all."""
         return self._session._socket
         return self._session._socket
-    
+
     def close(self):
     def close(self):
         """Close the session to the command channel"""
         """Close the session to the command channel"""
         self._session.close()
         self._session.close()
 
 
-    def check_command(self):
+    def check_command(self, nonblock = True):
         """Check whether there is a command or configuration update
         """Check whether there is a command or configuration update
            on the channel. Call the corresponding callback function if
            on the channel. Call the corresponding callback function if
-           there is. This function does a non-blocking read on the
-           cc session, and returns nothing. It will respond to any
-           command by either an error or the answer message returned
-           by the callback, unless the latter is None."""
-        msg, env = self._session.group_recvmsg(True)
-        
+           there is. This function does a read on the cc session, and
+           returns nothing. It will respond to any command by either
+           an error or the answer message returned by the callback,
+           unless the latter is None."""
+        timeout_orig = self._session.get_timeout()
+        self._session.set_timeout(0)
+        try:
+            msg, env = self._session.group_recvmsg(nonblock)
+        finally:
+            self._session.set_timeout(timeout_orig)
+
         # should we default to an answer? success-by-default? unhandled error?
         # should we default to an answer? success-by-default? unhandled error?
         if msg is not None and not 'result' in msg:
         if msg is not None and not 'result' in msg:
             answer = None
             answer = None

+ 3 - 0
src/lib/python/isc/config/tests/unittest_fakesession.py

@@ -88,3 +88,6 @@ class FakeModuleCCSession:
 
 
     def set_timeout(self, timeout):
     def set_timeout(self, timeout):
         self._timeout = timeout
         self._timeout = timeout
+
+    def get_timeout(self):
+        return self._timeout