Commit 68d78362 authored by Michal Vaner's avatar Michal Vaner
Browse files

Merge preparation, step 2

asiolink compiles and passes tests

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-recursor-config@3431 e5f2f494-b856-4b98-b285-d166d9295462
parent d64bf0a8
......@@ -51,7 +51,10 @@ private:
IOServiceImpl& operator=(const IOService& source);
public:
/// \brief The constructor
IOServiceImpl() : io_service_() {};
IOServiceImpl() :
io_service_(),
work_(io_service_)
{};
/// \brief The destructor.
~IOServiceImpl() {};
//@}
......@@ -83,6 +86,7 @@ public:
asio::io_service& get_io_service() { return io_service_; };
private:
asio::io_service io_service_;
asio::io_service::work work_;
};
IOService::IOService() {
......@@ -119,11 +123,9 @@ public:
const ip::address* v4addr, const ip::address* v6addr,
SimpleCallback* checkin, DNSLookup* lookup,
DNSAnswer* answer);
//asio::io_service io_service_;
// So it does not run out of work when there are no listening sockets
asio::io_service::work work_;
void stop();
IOService& io_service_;
typedef boost::shared_ptr<UDPServer> UDPServerPtr;
typedef boost::shared_ptr<TCPServer> TCPServerPtr;
typedef boost::shared_ptr<DNSServer> DNSServerPtr;
......@@ -134,13 +136,13 @@ public:
void addServer(uint16_t port, const ip::address& address) {
try {
TCPServerPtr tcpServer(new TCPServer(io_service_, address, port,
checkin_, lookup_, answer_));
TCPServerPtr tcpServer(new TCPServer(io_service_.get_io_service(),
address, port, checkin_, lookup_, answer_));
(*tcpServer)();
servers_.push_back(tcpServer);
UDPServerPtr udpServer(new UDPServer(io_service_, address, port,
checkin_, lookup_, answer_));
UDPServerPtr udpServer(new UDPServer(io_service_.get_io_service(),
address, port, checkin_, lookup_, answer_));
(*udpServer)();
servers_.push_back(udpServer);
}
......@@ -172,15 +174,14 @@ public:
}
};
DNSServiceImpl::DNSServiceImpl(IOService& io_service_,
DNSServiceImpl::DNSServiceImpl(IOService& io_service,
const char& port,
const ip::address* const v4addr,
const ip::address* const v6addr,
SimpleCallback* checkin,
DNSLookup* lookup,
DNSAnswer* answer) :
// TODO MERGE move work to IOService
work_(io_service_),
io_service_(io_service),
checkin_(checkin),
lookup_(lookup),
answer_(answer)
......@@ -199,7 +200,7 @@ DNSService::DNSService(IOService& io_service,
SimpleCallback* checkin,
DNSLookup* lookup,
DNSAnswer* answer) :
impl_(new IOServiceImpl(io_service, port, NULL, NULL, checkin, lookup,
impl_(new DNSServiceImpl(io_service, port, NULL, NULL, checkin, lookup,
answer)), io_service_(io_service)
{
addServer(port, &address);
......@@ -222,8 +223,8 @@ DNSService::DNSService(IOService& io_service,
DNSService::DNSService(IOService& io_service, SimpleCallback* checkin,
DNSLookup* lookup, DNSAnswer *answer) :
impl_(new IOServiceImpl(io_service, *"0", NULL, NULL, checkin, lookup,
answer))
impl_(new DNSServiceImpl(io_service, *"0", NULL, NULL, checkin, lookup,
answer)), io_service_(io_service)
{
}
......@@ -263,26 +264,6 @@ DNSService::clearServers() {
impl_->servers_.clear();
}
void
IOService::run() {
impl_->io_service_.run();
}
void
IOService::run_one() {
impl_->io_service_.run_one();
}
void
IOService::stop() {
impl_->io_service_.stop();
}
asio::io_service&
IOService::get_io_service() {
return (impl_->io_service_);
}
RecursiveQuery::RecursiveQuery(DNSService& dns_service,
const std::vector<std::pair<std::string, uint16_t> >& upstream) :
dns_service_(dns_service), upstream_(upstream)
......
......@@ -129,20 +129,10 @@ private:
public:
/// \brief The constructor
IOService();
/// \brief The constructor without any servers.
///
/// Use addServer() to add some servers.
IOService(SimpleCallback *checkin, DNSLookup* lookup, DNSAnswer *answer);
/// \brief The destructor.
~IOService();
//@}
/// \brief Add another server to the service
void addServer(uint16_t port, const std::string &address);
void addServer(const char &port, const std::string &address);
/// \brief Remove all servers from the service
void clearServers();
/// \brief Start the underlying event loop.
///
/// This method does not return control to the caller until
......@@ -219,10 +209,21 @@ public:
const bool use_ipv4, const bool use_ipv6,
SimpleCallback* checkin, DNSLookup* lookup,
DNSAnswer* answer);
/// \brief The constructor without any servers.
///
/// Use addServer() to add some servers.
DNSService(IOService& io_service, SimpleCallback* checkin,
DNSLookup* lookup, DNSAnswer* answer);
/// \brief The destructor.
~DNSService();
//@}
/// \brief Add another server to the service
void addServer(uint16_t port, const std::string &address);
void addServer(const char &port, const std::string &address);
/// \brief Remove all servers from the service
void clearServers();
/// \brief Return the native \c io_service object used in this wrapper.
///
/// This is a short term work around to support other BIND 10 modules
......@@ -528,7 +529,7 @@ public:
/// query on.
/// \param upstream Addresses and ports of the upstream servers
/// to forward queries to.
RecursiveQuery(IOService& io_service,
RecursiveQuery(DNSService& dns_service,
const std::vector<std::pair<std::string, uint16_t> >&
upstream);
//@}
......
......@@ -366,11 +366,14 @@ protected:
}
// Set up an IO Service queue without any addresses
void setIOService() {
void setDNSService() {
delete dns_service_;
dns_service_ = NULL;
delete io_service_;
io_service_ = NULL;
io_service_ = new IOService();
callback_ = new ASIOCallBack(this);
io_service_ = new IOService(callback_, NULL, NULL);
dns_service_ = new DNSService(*io_service_, callback_, NULL, NULL);
}
// Run a simple server test, on either IPv4 or IPv6, and over either
......@@ -552,16 +555,16 @@ TEST_F(ASIOLinkTest, v4TCPSendSpecific) {
}
TEST_F(ASIOLinkTest, v6AddServer) {
setIOService();
io_service_->addServer(*TEST_SERVER_PORT, TEST_IPV6_ADDR);
setDNSService();
dns_service_->addServer(*TEST_SERVER_PORT, TEST_IPV6_ADDR);
doTest(AF_INET6, IPPROTO_TCP);
EXPECT_THROW(sendTCP(AF_INET), IOError);
}
TEST_F(ASIOLinkTest, v4AddServer) {
setIOService();
io_service_->addServer(*TEST_SERVER_PORT, TEST_IPV4_ADDR);
setDNSService();
dns_service_->addServer(*TEST_SERVER_PORT, TEST_IPV4_ADDR);
doTest(AF_INET, IPPROTO_TCP);
EXPECT_THROW(sendTCP(AF_INET6), IOError);
......@@ -570,7 +573,8 @@ TEST_F(ASIOLinkTest, v4AddServer) {
TEST_F(ASIOLinkTest, DISABLED_clearServers) {
// FIXME: Enable when clearServers actually close the sockets
// See #388
io_service_->clearServers();
setDNSService();
dns_service_->clearServers();
EXPECT_THROW(sendTCP(AF_INET), IOError);
EXPECT_THROW(sendTCP(AF_INET6), IOError);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment