From: JINMEI Tatuya Date: Tue, 3 Apr 2012 23:38:53 +0000 (-0700) Subject: [1820] removed constructors concrete DNSServer classes with addre+port. X-Git-Tag: trac2351_base~226^2~116^2~56^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=350e65820efee213ef09122b88cdfdb7f4ab38b0;p=thirdparty%2Fkea.git [1820] removed constructors concrete DNSServer classes with addre+port. This is part of the cleanup. as we removed the corresponding interface at DNSService, no one now uses these constructors. --- diff --git a/src/lib/asiodns/sync_udp_server.cc b/src/lib/asiodns/sync_udp_server.cc index fb53fbaa64..a31301d0df 100644 --- a/src/lib/asiodns/sync_udp_server.cc +++ b/src/lib/asiodns/sync_udp_server.cc @@ -38,29 +38,6 @@ using namespace isc::asiolink; namespace isc { namespace asiodns { -SyncUDPServer::SyncUDPServer(asio::io_service& io_service, - const asio::ip::address& addr, - const uint16_t port, - asiolink::SimpleCallback* checkin, - DNSLookup* lookup, DNSAnswer* answer) : - output_buffer_(new isc::util::OutputBuffer(0)), - query_(new isc::dns::Message(isc::dns::Message::PARSE)), - answer_(new isc::dns::Message(isc::dns::Message::RENDER)), - io_(io_service), checkin_callback_(checkin), lookup_callback_(lookup), - answer_callback_(answer), stopped_(false) -{ - // We must use different instantiations for v4 and v6; - // otherwise ASIO will bind to both - asio::ip::udp proto = addr.is_v4() ? asio::ip::udp::v4() : - asio::ip::udp::v6(); - socket_.reset(new asio::ip::udp::socket(io_service, proto)); - socket_->set_option(asio::socket_base::reuse_address(true)); - if (addr.is_v6()) { - socket_->set_option(asio::ip::v6_only(true)); - } - socket_->bind(asio::ip::udp::endpoint(addr, port)); -} - SyncUDPServer::SyncUDPServer(asio::io_service& io_service, const int fd, const int af, asiolink::SimpleCallback* checkin, DNSLookup* lookup, DNSAnswer* answer) : diff --git a/src/lib/asiodns/sync_udp_server.h b/src/lib/asiodns/sync_udp_server.h index f21d3e5569..97184226f4 100644 --- a/src/lib/asiodns/sync_udp_server.h +++ b/src/lib/asiodns/sync_udp_server.h @@ -42,19 +42,6 @@ namespace asiodns { /// the UDPClass. class SyncUDPServer : public DNSServer, public boost::noncopyable { public: - /// \brief Constructor - /// \param io_service the asio::io_service to work with - /// \param addr the IP address to listen for queries on - /// \param port the port to listen for queries on - /// \param checkin the callbackprovider for non-DNS events - /// \param lookup the callbackprovider for DNS lookup events - /// \param answer the callbackprovider for DNS answer events - explicit SyncUDPServer(asio::io_service& io_service, - const asio::ip::address& addr, const uint16_t port, - isc::asiolink::SimpleCallback* checkin = NULL, - DNSLookup* lookup = NULL, - DNSAnswer* answer = NULL); - /// \brief Constructor /// \param io_service the asio::io_service to work with /// \param fd the file descriptor of opened UDP socket diff --git a/src/lib/asiodns/tcp_server.cc b/src/lib/asiodns/tcp_server.cc index 3e97e14504..8e4b4d6f05 100644 --- a/src/lib/asiodns/tcp_server.cc +++ b/src/lib/asiodns/tcp_server.cc @@ -47,28 +47,6 @@ namespace asiodns { /// The following functions implement the \c TCPServer class. /// /// The constructor -TCPServer::TCPServer(io_service& io_service, - const ip::address& addr, const uint16_t port, - const SimpleCallback* checkin, - const DNSLookup* lookup, - const DNSAnswer* answer) : - io_(io_service), done_(false), - checkin_callback_(checkin), lookup_callback_(lookup), - answer_callback_(answer) -{ - tcp::endpoint endpoint(addr, port); - acceptor_.reset(new tcp::acceptor(io_service)); - acceptor_->open(endpoint.protocol()); - // Set v6-only (we use a separate instantiation for v4, - // otherwise asio will bind to both v4 and v6 - if (addr.is_v6()) { - acceptor_->set_option(ip::v6_only(true)); - } - acceptor_->set_option(tcp::acceptor::reuse_address(true)); - acceptor_->bind(endpoint); - acceptor_->listen(); -} - TCPServer::TCPServer(io_service& io_service, int fd, int af, const SimpleCallback* checkin, const DNSLookup* lookup, diff --git a/src/lib/asiodns/tcp_server.h b/src/lib/asiodns/tcp_server.h index a75fddbf80..01695e4093 100644 --- a/src/lib/asiodns/tcp_server.h +++ b/src/lib/asiodns/tcp_server.h @@ -37,12 +37,6 @@ namespace asiodns { /// defined in coroutine.h. class TCPServer : public virtual DNSServer, public virtual coroutine { public: - explicit TCPServer(asio::io_service& io_service, - const asio::ip::address& addr, const uint16_t port, - const isc::asiolink::SimpleCallback* checkin = NULL, - const DNSLookup* lookup = NULL, - const DNSAnswer* answer = NULL); - /// \brief Constructor /// \param io_service the asio::io_service to work with /// \param fd the file descriptor of opened TCP socket diff --git a/src/lib/asiodns/tests/dns_server_unittest.cc b/src/lib/asiodns/tests/dns_server_unittest.cc index 0064bba70b..a5e83c7757 100644 --- a/src/lib/asiodns/tests/dns_server_unittest.cc +++ b/src/lib/asiodns/tests/dns_server_unittest.cc @@ -414,22 +414,7 @@ class DNSServerTestBase : public::testing::Test { static bool io_service_is_time_out; }; -// Initialization with name and port -template -class AddrPortInit : public DNSServerTestBase { -protected: - AddrPortInit() { - this->udp_server_ = new UDPServerClass(this->service, - this->server_address_, - server_port, this->checker_, - this->lookup_, this->answer_); - this->tcp_server_ = new TCPServer(this->service, this->server_address_, - server_port, this->checker_, - this->lookup_, this->answer_); - } -}; - -// Initialization by the file descriptor +// Initialization (by the file descriptor) template class FdInit : public DNSServerTestBase { private: @@ -494,8 +479,7 @@ protected: template class DNSServerTest : public Parent { }; -typedef ::testing::Types, AddrPortInit, - FdInit, FdInit > +typedef ::testing::Types, FdInit > ServerTypes; TYPED_TEST_CASE(DNSServerTest, ServerTypes); @@ -507,12 +491,6 @@ bool DNSServerTestBase::io_service_is_time_out = false; template asio::io_service* DNSServerTestBase::current_service(NULL); -typedef ::testing::Types, FdInit > - SyncTypes; -template -class SyncServerTest : public Parent { }; -TYPED_TEST_CASE(SyncServerTest, SyncTypes); - // Test whether server stopped successfully after client get response // client will send query and start to wait for response, once client // get response, udp server will be stopped, the io service won't quit @@ -558,7 +536,8 @@ TYPED_TEST(DNSServerTest, stopUDPServerDuringPrepareAnswer) { EXPECT_TRUE(this->serverStopSucceed()); } -static void stopServerManyTimes(DNSServer *server, unsigned int times) { +void +stopServerManyTimes(DNSServer *server, unsigned int times) { for (unsigned int i = 0; i < times; ++i) { server->stop(); } @@ -680,18 +659,19 @@ TYPED_TEST(DNSServerTestBase, DISABLED_invalidUDPFD) { isc::asiolink::IOError); } -// Check it rejects some of the unsupported operatirons -TYPED_TEST(SyncServerTest, unsupportedOps) { - EXPECT_THROW(this->udp_server_->clone(), isc::Unexpected); - EXPECT_THROW(this->udp_server_->asyncLookup(), isc::Unexpected); +// A specialized test type for SyncUDPServer. +typedef FdInit SyncServerTest; + +// Check it rejects some of the unsupported operations +TEST_F(SyncServerTest, unsupportedOps) { + EXPECT_THROW(udp_server_->clone(), isc::Unexpected); + EXPECT_THROW(udp_server_->asyncLookup(), isc::Unexpected); } // Check it rejects forgotten resume (eg. insists that it is synchronous) -TYPED_TEST(SyncServerTest, mustResume) { - this->lookup_->allow_resume_ = false; - ASSERT_THROW(this->testStopServerByStopper(this->udp_server_, - this->udp_client_, - this->lookup_), +TEST_F(SyncServerTest, mustResume) { + lookup_->allow_resume_ = false; + ASSERT_THROW(testStopServerByStopper(udp_server_, udp_client_, lookup_), isc::Unexpected); } diff --git a/src/lib/asiodns/udp_server.cc b/src/lib/asiodns/udp_server.cc index 0fb8bec9b7..0f5456b3d1 100644 --- a/src/lib/asiodns/udp_server.cc +++ b/src/lib/asiodns/udp_server.cc @@ -182,12 +182,6 @@ struct UDPServer::Data { /// /// The constructor. It just creates new internal state object /// and lets it handle the initialization. -UDPServer::UDPServer(io_service& io_service, const ip::address& addr, - const uint16_t port, SimpleCallback* checkin, - DNSLookup* lookup, DNSAnswer* answer) : - data_(new Data(io_service, addr, port, checkin, lookup, answer)) -{ } - UDPServer::UDPServer(io_service& io_service, int fd, int af, SimpleCallback* checkin, DNSLookup* lookup, DNSAnswer* answer) : diff --git a/src/lib/asiodns/udp_server.h b/src/lib/asiodns/udp_server.h index 2b6a574141..b32c06c9d0 100644 --- a/src/lib/asiodns/udp_server.h +++ b/src/lib/asiodns/udp_server.h @@ -39,19 +39,6 @@ namespace asiodns { /// class UDPServer : public virtual DNSServer, public virtual coroutine { public: - /// \brief Constructor - /// \param io_service the asio::io_service to work with - /// \param addr the IP address to listen for queries on - /// \param port the port to listen for queries on - /// \param checkin the callbackprovider for non-DNS events - /// \param lookup the callbackprovider for DNS lookup events - /// \param answer the callbackprovider for DNS answer events - explicit UDPServer(asio::io_service& io_service, - const asio::ip::address& addr, const uint16_t port, - isc::asiolink::SimpleCallback* checkin = NULL, - DNSLookup* lookup = NULL, - DNSAnswer* answer = NULL); - /// \brief Constructor /// \param io_service the asio::io_service to work with /// \param fd the file descriptor of opened UDP socket