[svn] commit: r2735 - in /branches/trac296/src/lib/cc: session.cc session_unittests.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Aug 16 08:54:28 UTC 2010
Author: jelte
Date: Mon Aug 16 08:54:28 2010
New Revision: 2735
Log:
comments from review
Modified:
branches/trac296/src/lib/cc/session.cc
branches/trac296/src/lib/cc/session_unittests.cc
Modified: branches/trac296/src/lib/cc/session.cc
==============================================================================
--- branches/trac296/src/lib/cc/session.cc (original)
+++ branches/trac296/src/lib/cc/session.cc Mon Aug 16 08:54:28 2010
@@ -56,19 +56,7 @@
// (e.g. write(2)) so we don't import the entire asio namespace.
using asio::io_service;
-// By default, unless changed or disabled, blocking reads on
-// the msgq channel will time out after 4 seconds in this
-// implementation.
-// This number is chosen to be low enough so that whatever
-// component is blocking does not seem to be hanging, but
-// still gives enough time for other modules to respond if they
-// are busy. If this choice turns out to be a bad one, we can
-// change it later.
-#define BIND10_MSGQ_DEFAULT_TIMEOUT 4000
-
-namespace isc {
-namespace cc {
-
+namespace {
/// \brief Sets the given Optional 'result' to the given error code
/// Used as a callback for emulating sync reads with async calls
/// \param result Pointer to the optional to set
@@ -79,13 +67,17 @@
{
result->reset(err);
}
+}
+
+namespace isc {
+namespace cc {
class SessionImpl {
public:
SessionImpl(io_service& io_service) :
sequence_(-1), queue_(Element::createList()),
io_service_(io_service), socket_(io_service_), data_length_(0),
- timeout_(BIND10_MSGQ_DEFAULT_TIMEOUT)
+ timeout_(MSGQ_DEFAULT_TIMEOUT)
{}
void establish(const char& socket_file);
void disconnect();
@@ -112,8 +104,17 @@
uint32_t data_length_;
boost::function<void()> user_handler_;
asio::error_code error_;
- // timeout for blocking reads (in seconds, defaults to 4000)
size_t timeout_;
+
+ // By default, unless changed or disabled, blocking reads on
+ // the msgq channel will time out after 4 seconds in this
+ // implementation.
+ // This number is chosen to be low enough so that whatever
+ // component is blocking does not seem to be hanging, but
+ // still gives enough time for other modules to respond if they
+ // are busy. If this choice turns out to be a bad one, we can
+ // change it later.
+ static const size_t MSGQ_DEFAULT_TIMEOUT = 4000;
};
void
@@ -184,6 +185,8 @@
// until the cancel is processed before we continue
while (!read_result && !timer_result) {
socket_.io_service().run_one();
+
+ // Don't cancel the timer if we haven't set it
if (read_result && getTimeout() != 0) {
timer.cancel();
while (!timer_result) {
Modified: branches/trac296/src/lib/cc/session_unittests.cc
==============================================================================
--- branches/trac296/src/lib/cc/session_unittests.cc (original)
+++ branches/trac296/src/lib/cc/session_unittests.cc Mon Aug 16 08:54:28 2010
@@ -122,7 +122,7 @@
class SessionTest : public ::testing::Test {
protected:
- SessionTest() {
+ SessionTest() : sess(my_io_service) {
// The TestDomainSocket is held as a 'new'-ed pointer,
// so we can call unlink() first.
unlink(BIND10_TEST_SOCKET_FILE);
@@ -135,11 +135,10 @@
asio::io_service my_io_service;
TestDomainSocket* tds;
+ Session sess;
};
TEST_F(SessionTest, timeout_on_connect) {
- Session sess(my_io_service);
-
// set to a short timeout so the test doesn't take too long
EXPECT_EQ(4000, sess.getTimeout());
sess.setTimeout(100);
@@ -151,14 +150,12 @@
TEST_F(SessionTest, connect_ok) {
tds->setSendLname();
- Session sess(my_io_service);
sess.establish(BIND10_TEST_SOCKET_FILE);
}
TEST_F(SessionTest, connect_ok_no_timeout) {
tds->setSendLname();
- Session sess(my_io_service);
sess.setTimeout(0);
sess.establish(BIND10_TEST_SOCKET_FILE);
}
@@ -166,7 +163,6 @@
TEST_F(SessionTest, connect_ok_connection_reset) {
tds->setSendLname();
- Session sess(my_io_service);
sess.establish(BIND10_TEST_SOCKET_FILE);
// Close the session again, so the next recv() should throw
sess.disconnect();
More information about the bind10-changes
mailing list