[svn] commit: r2829 - in /branches/trac312/src/lib/python/isc: cc/session.py config/ccsession.py config/cfgmgr.py config/tests/cfgmgr_test.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Aug 27 14:49:52 UTC 2010
Author: jelte
Date: Fri Aug 27 14:49:51 2010
New Revision: 2829
Log:
bit of set_timeout cleanup in cfgmgr
CCSession's check_command now does a non-blocking read to see if there are commands (instead of a blocking+timeout catch)
make default timeout a class constant in python cc.Session
Modified:
branches/trac312/src/lib/python/isc/cc/session.py
branches/trac312/src/lib/python/isc/config/ccsession.py
branches/trac312/src/lib/python/isc/config/cfgmgr.py
branches/trac312/src/lib/python/isc/config/tests/cfgmgr_test.py
Modified: branches/trac312/src/lib/python/isc/cc/session.py
==============================================================================
--- branches/trac312/src/lib/python/isc/cc/session.py (original)
+++ branches/trac312/src/lib/python/isc/cc/session.py Fri Aug 27 14:49:51 2010
@@ -28,12 +28,10 @@
class SessionTimeout(Exception): pass
class Session:
+ MSGQ_DEFAULT_TIMEOUT = 4000
+
def __init__(self, socket_file=None):
self._socket = None
- # store the current timeout value in seconds (the way
- # settimeout() wants them, our API takes milliseconds
- # so that it is consistent with the C++ version)
- self._socket_timeout = 4;
self._lname = None
self._recvbuffer = bytearray()
self._recvlength = 0
@@ -41,6 +39,7 @@
self._closed = False
self._queue = []
self._lock = threading.RLock()
+ self.set_timeout(self.MSGQ_DEFAULT_TIMEOUT);
if socket_file is None:
if "BIND10_MSGQ_SOCKET_FILE" in os.environ:
Modified: branches/trac312/src/lib/python/isc/config/ccsession.py
==============================================================================
--- branches/trac312/src/lib/python/isc/config/ccsession.py (original)
+++ branches/trac312/src/lib/python/isc/config/ccsession.py Fri Aug 27 14:49:51 2010
@@ -177,18 +177,11 @@
def check_command(self):
"""Check whether there is a command or configuration update
on the channel. Call the corresponding callback function if
- there is."""
- msg, env = None, None
-
- # the module may have set timeout to zero (if it knows it will
- # simply be doing nothing until it gets a command), but we
- # cannot be sure of that (and we should change it at this
- # level), so if we get a timeout, there is simply nothing to
- # do and we return.
- try:
- msg, env = self._session.group_recvmsg(False)
- except isc.cc.SessionTimeout:
- return
+ 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)
# should we default to an answer? success-by-default? unhandled error?
if msg is not None and not 'result' in msg:
Modified: branches/trac312/src/lib/python/isc/config/cfgmgr.py
==============================================================================
--- branches/trac312/src/lib/python/isc/config/cfgmgr.py (original)
+++ branches/trac312/src/lib/python/isc/config/cfgmgr.py Fri Aug 27 14:49:51 2010
@@ -285,13 +285,9 @@
seq = self.cc.group_sendmsg(update_cmd, module_name)
try:
# We have set the timeout to forever, set it now so we won't hang
- self.cc.set_timeout(4000)
answer, env = self.cc.group_recvmsg(False, seq)
except isc.cc.SessionTimeout:
answer = ccsession.create_answer(1, "Timeout waiting for answer from " + module_name)
- finally:
- # and set it back
- self.cc.set_timeout(0)
else:
conf_part = data.set(self.config.data, module_name, {})
data.merge(conf_part[module_name], cmd[1])
@@ -302,11 +298,9 @@
# replace 'our' answer with that of the module
# We have set the timeout to forever, set it now so we won't hang
try:
- self.cc.set_timeout(4000)
answer, env = self.cc.group_recvmsg(False, seq)
except isc.cc.SessionTimeout:
answer = ccsession.create_answer(1, "Timeout waiting for answer from " + module_name)
- self.cc.set_timeout(0)
if answer:
rcode, val = ccsession.parse_answer(answer)
if rcode == 0:
@@ -328,7 +322,6 @@
self.config.data[module])
seq = self.cc.group_sendmsg(update_cmd, module)
try:
- self.cc.set_timeout(4000)
answer, env = self.cc.group_recvmsg(False, seq)
if answer == None:
got_error = True
@@ -341,8 +334,6 @@
except isc.cc.SessionTimeout:
got_error = True
err_list.append("CC Timeout waiting on answer message from " + module)
- finally:
- self.cc.set_timeout(0)
if not got_error:
self.write_config()
return ccsession.create_answer(0)
@@ -416,10 +407,12 @@
self.running = True
while (self.running):
# we just wait eternally for any command here, so disable
- # timeouts
+ # timeouts for this specific recv
self.cc.set_timeout(0)
msg, env = self.cc.group_recvmsg(False)
- # ignore 'None' value (current result of timeout)
+ # and set it back to whatever we default to
+ self.cc.set_timeout(isc.cc.Session.MSGQ_DEFAULT_TIMEOUT)
+ # ignore 'None' value (even though they should not occur)
# and messages that are answers to questions we did
# not ask
if msg is not None and not 'result' in msg:
Modified: branches/trac312/src/lib/python/isc/config/tests/cfgmgr_test.py
==============================================================================
--- branches/trac312/src/lib/python/isc/config/tests/cfgmgr_test.py (original)
+++ branches/trac312/src/lib/python/isc/config/tests/cfgmgr_test.py Fri Aug 27 14:49:51 2010
@@ -258,7 +258,7 @@
self._handle_msg_helper({ "command": [ "set_config", [ ] ] },
{'result': [1, 'Wrong number of arguments']} )
self._handle_msg_helper({ "command": [ "set_config", [ self.name, { "test": 125 }] ] },
- { 'result': [1, 'Timeout waiting for answer from TestModule']} )
+ { 'result': [1, 'No answer message from TestModule']} )
#self.assertEqual(len(self.fake_session.message_queue), 1)
#self.assertEqual({'config_update': {'test': 124}},
More information about the bind10-changes
mailing list