BIND 10 trac805, updated. 444f92d580471b1ed9474a373a4797d497fdcea4 [805] Make sure complicated objects are not static
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jan 4 10:38:07 UTC 2012
The branch, trac805 has been updated
via 444f92d580471b1ed9474a373a4797d497fdcea4 (commit)
via 50839dcce8152c27e4642f3c073e41a466cca0b8 (commit)
via 63a5191b95065ff4d918df0b9143e9371cd6f5d6 (commit)
via 5e04e03abdb6960f58127868ae91d596f18edd30 (commit)
via 619af407edf1c63ee20fed09ee39a338a41183e3 (commit)
via 8bb7f2c2df4a11a1301ee114ef4d2f6e8b8e71fd (commit)
from d93776a7695e631375165090e001bcbe38923d7e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 444f92d580471b1ed9474a373a4797d497fdcea4
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jan 4 11:35:56 2012 +0100
[805] Make sure complicated objects are not static
The service is now (nonstatic) member and the static variable is only
pointer to the active one, so the signal handler can access it.
commit 50839dcce8152c27e4642f3c073e41a466cca0b8
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jan 4 11:25:26 2012 +0100
[805] Removed extra freeaddrinfo
commit 63a5191b95065ff4d918df0b9143e9371cd6f5d6
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jan 4 11:21:47 2012 +0100
[805] Move stuff to constructor/destructor
It eliminates the need to call commonSetup and makes it possible to
constify something.
commit 5e04e03abdb6960f58127868ae91d596f18edd30
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jan 4 11:10:19 2012 +0100
[805] Some exception handling
Catch on the closing bracket, include little bit more in the try.
commit 619af407edf1c63ee20fed09ee39a338a41183e3
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jan 4 11:05:24 2012 +0100
[805] Use logging macros
Just consistency and performance.
commit 8bb7f2c2df4a11a1301ee114ef4d2f6e8b8e71fd
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jan 4 11:02:05 2012 +0100
[805] Copyright year update
The time goes on and we are a year older already.
-----------------------------------------------------------------------
Summary of changes:
src/lib/asiodns/logger.cc | 2 +-
src/lib/asiodns/logger.h | 2 +-
src/lib/asiodns/tcp_server.cc | 11 ++---
src/lib/asiodns/tests/dns_server_unittest.cc | 63 +++++++++++++------------
src/lib/asiodns/udp_server.cc | 16 +++----
5 files changed, 46 insertions(+), 48 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/asiodns/logger.cc b/src/lib/asiodns/logger.cc
index e4c60e2..5801a0b 100644
--- a/src/lib/asiodns/logger.cc
+++ b/src/lib/asiodns/logger.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
diff --git a/src/lib/asiodns/logger.h b/src/lib/asiodns/logger.h
index d690edf..306d463 100644
--- a/src/lib/asiodns/logger.h
+++ b/src/lib/asiodns/logger.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
diff --git a/src/lib/asiodns/tcp_server.cc b/src/lib/asiodns/tcp_server.cc
index f7e9138..b351f71 100644
--- a/src/lib/asiodns/tcp_server.cc
+++ b/src/lib/asiodns/tcp_server.cc
@@ -81,16 +81,15 @@ TCPServer::TCPServer(io_service& io_service, int fd, int af,
isc_throw(InvalidParameter, "Address family must be either AF_INET "
"or AF_INET6, not " << af);
}
- logger.debug(DBGLVL_TRACE_BASIC, ASIODNS_FD_ADD_TCP).arg(fd);
+ LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, ASIODNS_FD_ADD_TCP).arg(fd);
- acceptor_.reset(new tcp::acceptor(io_service));
try {
+ acceptor_.reset(new tcp::acceptor(io_service));
acceptor_->assign(af == AF_INET6 ? tcp::v6() : tcp::v4(), fd);
acceptor_->listen();
- }
- // Whatever the thing throws, it is something from ASIO and we convert
- // it
- catch (const std::exception& exception) {
+ } catch (const std::exception& exception) {
+ // Whatever the thing throws, it is something from ASIO and we convert
+ // it
isc_throw(IOError, exception.what());
}
}
diff --git a/src/lib/asiodns/tests/dns_server_unittest.cc b/src/lib/asiodns/tests/dns_server_unittest.cc
index 0b9cdad..1272de1 100644
--- a/src/lib/asiodns/tests/dns_server_unittest.cc
+++ b/src/lib/asiodns/tests/dns_server_unittest.cc
@@ -321,10 +321,23 @@ class TCPClient : public SimpleClient {
class DNSServerTestBase : public::testing::Test {
protected:
DNSServerTestBase() :
+ server_address_(ip::address::from_string(server_ip)),
+ checker_(new DummyChecker()),
+ lookup_(new DummyLookup()),
+ answer_(new SimpleAnswer()),
+ udp_client_(new UDPClient(service,
+ ip::udp::endpoint(server_address_,
+ server_port))),
+ tcp_client_(new TCPClient(service,
+ ip::tcp::endpoint(server_address_,
+ server_port))),
udp_server_(NULL),
tcp_server_(NULL)
- { }
- void TearDown() {
+ {
+ current_service = &service;
+ }
+
+ ~ DNSServerTestBase() {
if (udp_server_) {
udp_server_->stop();
}
@@ -338,6 +351,9 @@ class DNSServerTestBase : public::testing::Test {
delete udp_client_;
delete tcp_server_;
delete tcp_client_;
+ // No delete here. The service is not allocated by new, but as our
+ // member. This only references it, so just cleaning the pointer.
+ current_service = NULL;
}
void testStopServerByStopper(DNSServer* server, SimpleClient* client,
@@ -353,6 +369,7 @@ class DNSServerTestBase : public::testing::Test {
// server stop failed
void (*prev_handler)(int) =
std::signal(SIGALRM, DNSServerTestBase::stopIOService);
+ current_service = &service;
alarm(IO_SERVICE_TIME_OUT);
service.run();
service.reset();
@@ -361,48 +378,37 @@ class DNSServerTestBase : public::testing::Test {
std::signal(SIGALRM, prev_handler);
}
- void commonSetup() {
- server_address_ = ip::address::from_string(server_ip);
- checker_ = new DummyChecker();
- lookup_ = new DummyLookup();
- answer_ = new SimpleAnswer();
- udp_client_ = new UDPClient(service,
- ip::udp::endpoint(server_address_,
- server_port));
- tcp_client_ = new TCPClient(service,
- ip::tcp::endpoint(server_address_,
- server_port));
- }
-
static void stopIOService(int _no_use_parameter) {
io_service_is_time_out = true;
- service.stop();
+ if (current_service != NULL) {
+ current_service->stop();
+ }
}
bool serverStopSucceed() const {
return (!io_service_is_time_out);
}
- DummyChecker* checker_;
- DummyLookup* lookup_;
- SimpleAnswer* answer_;
+ asio::io_service service;
+ const ip::address server_address_;
+ DummyChecker* const checker_;
+ DummyLookup* const lookup_;
+ SimpleAnswer* const answer_;
+ UDPClient* const udp_client_;
+ TCPClient* const tcp_client_;
UDPServer* udp_server_;
- UDPClient* udp_client_;
- TCPClient* tcp_client_;
TCPServer* tcp_server_;
- ip::address server_address_;
// To access them in signal handle function, the following
// variables have to be static.
- static asio::io_service service;
+ static asio::io_service* current_service;
static bool io_service_is_time_out;
};
// Initialization with name and port
class AddrPortInit : public DNSServerTestBase {
protected:
- void SetUp() {
- commonSetup();
+ AddrPortInit() {
udp_server_ = new UDPServer(service, server_address_, server_port,
checker_, lookup_, answer_);
tcp_server_ = new TCPServer(service, server_address_, server_port,
@@ -429,7 +435,6 @@ private:
const int error = getaddrinfo(server_ip, server_port_str,
&hints, &res);
if (error != 0) {
- freeaddrinfo(res);
isc_throw(IOError, "getaddrinfo failed: " << gai_strerror(error));
}
@@ -456,8 +461,8 @@ private:
}
}
protected:
+ // Using SetUp here so we can ASSERT_*
void SetUp() {
- commonSetup();
const int fdUDP(getFd(SOCK_DGRAM));
ASSERT_NE(-1, fdUDP) << strerror(errno);
udp_server_ = new UDPServer(service, fdUDP, AF_INET6, checker_,
@@ -477,7 +482,7 @@ typedef ::testing::Types<AddrPortInit, FdInit> ServerTypes;
TYPED_TEST_CASE(DNSServerTest, ServerTypes);
bool DNSServerTestBase::io_service_is_time_out = false;
-asio::io_service DNSServerTestBase::service;
+asio::io_service* DNSServerTestBase::current_service(NULL);
// Test whether server stopped successfully after client get response
// client will send query and start to wait for response, once client
@@ -606,7 +611,6 @@ TYPED_TEST(DNSServerTest, stopTCPServeMoreThanOnce) {
TEST_F(DNSServerTestBase, invalidFamily) {
// We abuse DNSServerTestBase for this test, as we don't need the
// initialization.
- commonSetup();
EXPECT_THROW(UDPServer(service, 0, AF_UNIX, checker_, lookup_,
answer_), isc::InvalidParameter);
EXPECT_THROW(TCPServer(service, 0, AF_UNIX, checker_, lookup_,
@@ -617,7 +621,6 @@ TEST_F(DNSServerTestBase, invalidFamily) {
TEST_F(DNSServerTestBase, invalidTCPFD) {
// We abuse DNSServerTestBase for this test, as we don't need the
// initialization.
- commonSetup();
/*
FIXME: The UDP server doesn't fail reliably with an invalid FD.
We need to find a way to trigger it reliably (it seems epoll
diff --git a/src/lib/asiodns/udp_server.cc b/src/lib/asiodns/udp_server.cc
index 9f6258f..001fdd5 100644
--- a/src/lib/asiodns/udp_server.cc
+++ b/src/lib/asiodns/udp_server.cc
@@ -85,17 +85,13 @@ struct UDPServer::Data {
isc_throw(InvalidParameter, "Address family must be either AF_INET "
"or AF_INET6, not " << af);
}
- logger.debug(DBGLVL_TRACE_BASIC, ASIODNS_FD_ADD_UDP).arg(fd);
- // We must use different instantiations for v4 and v6;
- // otherwise ASIO will bind to both
- udp proto = af == AF_INET6 ? udp::v6() : udp::v4();
- socket_.reset(new udp::socket(io_service));
+ LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, ASIODNS_FD_ADD_UDP).arg(fd);
try {
- socket_->assign(proto, fd);
- }
- // Whatever the thing throws, it is something from ASIO and we convert
- // it
- catch (const std::exception& exception) {
+ socket_.reset(new udp::socket(io_service));
+ socket_->assign(AF_INET6 ? udp::v6() : udp::v4(), fd);
+ } catch (const std::exception& exception) {
+ // Whatever the thing throws, it is something from ASIO and we convert
+ // it
isc_throw(IOError, exception.what());
}
}
More information about the bind10-changes
mailing list