[svn] commit: r3431 - in /branches/vorner-recursor-config/src/lib/asiolink: asiolink.cc asiolink.h tests/asiolink_unittest.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Nov 3 14:57:49 UTC 2010


Author: vorner
Date: Wed Nov  3 14:57:49 2010
New Revision: 3431

Log:
Merge preparation, step 2

asiolink compiles and passes tests

Modified:
    branches/vorner-recursor-config/src/lib/asiolink/asiolink.cc
    branches/vorner-recursor-config/src/lib/asiolink/asiolink.h
    branches/vorner-recursor-config/src/lib/asiolink/tests/asiolink_unittest.cc

Modified: branches/vorner-recursor-config/src/lib/asiolink/asiolink.cc
==============================================================================
--- branches/vorner-recursor-config/src/lib/asiolink/asiolink.cc (original)
+++ branches/vorner-recursor-config/src/lib/asiolink/asiolink.cc Wed Nov  3 14:57:49 2010
@@ -51,7 +51,10 @@
     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 @@
     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 @@
                   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 @@
 
     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 @@
     }
 };
 
-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 @@
                        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, 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)
 {
 }
 
@@ -261,26 +262,6 @@
     // FIXME: This does not work, it does not close the socket.
     // How is it done?
     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,

Modified: branches/vorner-recursor-config/src/lib/asiolink/asiolink.h
==============================================================================
--- branches/vorner-recursor-config/src/lib/asiolink/asiolink.h (original)
+++ branches/vorner-recursor-config/src/lib/asiolink/asiolink.h Wed Nov  3 14:57:49 2010
@@ -129,19 +129,9 @@
 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.
     ///
@@ -219,9 +209,20 @@
                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.
     ///
@@ -528,7 +529,7 @@
     ///        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);
     //@}

Modified: branches/vorner-recursor-config/src/lib/asiolink/tests/asiolink_unittest.cc
==============================================================================
--- branches/vorner-recursor-config/src/lib/asiolink/tests/asiolink_unittest.cc (original)
+++ branches/vorner-recursor-config/src/lib/asiolink/tests/asiolink_unittest.cc Wed Nov  3 14:57:49 2010
@@ -366,11 +366,14 @@
     }
 
     // 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, 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, 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);




More information about the bind10-changes mailing list