BIND 10 trac1600, updated. 95af6c2e54fb45fa5af1a2d3650376ccadd32c7b [1600] Changed the interface of DNSService to allow add UDPServer or SyncUDPServer by command.

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Mar 5 03:58:23 UTC 2012


The branch, trac1600 has been updated
       via  95af6c2e54fb45fa5af1a2d3650376ccadd32c7b (commit)
      from  2730ac6f20e6512c9c72cf22e0fe223f9bf66b09 (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 95af6c2e54fb45fa5af1a2d3650376ccadd32c7b
Author: Xie Jiagui <xiejiagui at cnnic.cn>
Date:   Mon Mar 5 11:56:54 2012 +0800

    [1600] Changed the interface of DNSService to allow add UDPServer or
    SyncUDPServer by command.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/asiodns/dns_service.cc               |   72 +++++++++++++++++---------
 src/lib/asiodns/dns_service.h                |   26 +++++++--
 src/lib/asiodns/tests/io_service_unittest.cc |    5 ++
 3 files changed, 72 insertions(+), 31 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/asiodns/dns_service.cc b/src/lib/asiodns/dns_service.cc
index 967ce15..3fcfce3 100644
--- a/src/lib/asiodns/dns_service.cc
+++ b/src/lib/asiodns/dns_service.cc
@@ -25,9 +25,9 @@
 #include <asio.hpp>
 #include <dns_service.h>
 #include <asiolink/io_service.h>
-#include <asiolink/io_service.h>
 #include <tcp_server.h>
 #include <udp_server.h>
+#include <sync_udp_server.h>
 
 #include <log/dummylog.h>
 
@@ -66,11 +66,13 @@ public:
                   const asio::ip::address* v4addr,
                   const asio::ip::address* v6addr,
                   SimpleCallback* checkin, DNSLookup* lookup,
-                  DNSAnswer* answer);
+                  DNSAnswer* answer,
+                  const UDPVersion param_flags);
 
     IOService& io_service_;
 
     typedef boost::shared_ptr<UDPServer> UDPServerPtr;
+    typedef boost::shared_ptr<SyncUDPServer> SyncUDPServerPtr;
     typedef boost::shared_ptr<TCPServer> TCPServerPtr;
     typedef boost::shared_ptr<DNSServer> DNSServerPtr;
     std::vector<DNSServerPtr> servers_;
@@ -85,7 +87,8 @@ public:
         servers_.push_back(server);
     }
 
-    void addServer(uint16_t port, const asio::ip::address& address) {
+    void addServer(uint16_t port, const asio::ip::address& address,
+                   const UDPVersion param_flags) {
         try {
             dlog(std::string("Initialize TCP server at ") + address.to_string() + ":" + boost::lexical_cast<std::string>(port));
             TCPServerPtr tcpServer(new TCPServer(io_service_.get_io_service(),
@@ -93,10 +96,21 @@ public:
             (*tcpServer)();
             servers_.push_back(tcpServer);
             dlog(std::string("Initialize UDP server at ") + address.to_string() + ":" + boost::lexical_cast<std::string>(port));
-            UDPServerPtr udpServer(new UDPServer(io_service_.get_io_service(),
-                address, port, checkin_, lookup_, answer_));
-            (*udpServer)();
-            servers_.push_back(udpServer);
+            
+            if(1 == param_flags) {
+                SyncUDPServerPtr syncUdpServer(new SyncUDPServer(io_service_.get_io_service(),
+                                                address, port, checkin_, lookup_, answer_));
+                (*syncUdpServer)();
+                servers_.push_back(syncUdpServer);
+            } else if(2 == param_flags) {
+                UDPServerPtr udpServer(new UDPServer(io_service_.get_io_service(),
+                                       address, port, checkin_, lookup_, answer_));
+                (*udpServer)();
+                servers_.push_back(udpServer);
+            } else {
+                // If nerther asyn UDPServer nor sync UDNServer, it throws.
+                isc_throw(IOError, "Bad UDPServer Version!");
+            }
         }
         catch (const asio::system_error& err) {
             // We need to catch and convert any ASIO level exceptions.
@@ -106,7 +120,8 @@ public:
                       err.what());
         }
     }
-    void addServer(const char& port, const asio::ip::address& address) {
+    void addServer(const char& port, const asio::ip::address& address,
+                   const UDPVersion param_flags) {
         uint16_t portnum;
         try {
             // XXX: SunStudio with stlport4 doesn't reject some invalid
@@ -122,7 +137,7 @@ public:
             isc_throw(IOError, "Invalid port number '" << &port << "': " <<
                       ex.what());
         }
-        addServer(portnum, address);
+        addServer(portnum, address,param_flags);
     }
 };
 
@@ -132,7 +147,8 @@ DNSServiceImpl::DNSServiceImpl(IOService& io_service,
                                const asio::ip::address* const v6addr,
                                SimpleCallback* checkin,
                                DNSLookup* lookup,
-                               DNSAnswer* answer) :
+                               DNSAnswer* answer,
+                               const UDPVersion para_flags):
     io_service_(io_service),
     checkin_(checkin),
     lookup_(lookup),
@@ -140,10 +156,10 @@ DNSServiceImpl::DNSServiceImpl(IOService& io_service,
 {
 
     if (v4addr) {
-        addServer(port, *v4addr);
+        addServer(port, *v4addr,para_flags);
     }
     if (v6addr) {
-        addServer(port, *v6addr);
+        addServer(port, *v6addr,para_flags);
     }
 }
 
@@ -151,11 +167,12 @@ DNSService::DNSService(IOService& io_service,
                        const char& port, const char& address,
                        SimpleCallback* checkin,
                        DNSLookup* lookup,
-                       DNSAnswer* answer) :
+                       DNSAnswer* answer,
+                       const UDPVersion para_flags) :
     impl_(new DNSServiceImpl(io_service, port, NULL, NULL, checkin, lookup,
-        answer)), io_service_(io_service)
+        answer,para_flags)), io_service_(io_service)
 {
-    addServer(port, &address);
+    addServer(port, &address,para_flags);
 }
 
 DNSService::DNSService(IOService& io_service,
@@ -163,7 +180,8 @@ DNSService::DNSService(IOService& io_service,
                        const bool use_ipv4, const bool use_ipv6,
                        SimpleCallback* checkin,
                        DNSLookup* lookup,
-                       DNSAnswer* answer) :
+                       DNSAnswer* answer,
+                       const UDPVersion para_flags) :
     impl_(NULL), io_service_(io_service)
 {
     const asio::ip::address v4addr_any =
@@ -172,13 +190,13 @@ DNSService::DNSService(IOService& io_service,
     const asio::ip::address v6addr_any =
         asio::ip::address(asio::ip::address_v6::any());
     const asio::ip::address* const v6addrp = use_ipv6 ? &v6addr_any : NULL;
-    impl_ = new DNSServiceImpl(io_service, port, v4addrp, v6addrp, checkin, lookup, answer);
+    impl_ = new DNSServiceImpl(io_service, port, v4addrp, v6addrp, checkin, lookup, answer,para_flags);
 }
 
 DNSService::DNSService(IOService& io_service, SimpleCallback* checkin,
-    DNSLookup* lookup, DNSAnswer *answer) :
+    DNSLookup* lookup, DNSAnswer *answer,const UDPVersion para_flags) :
     impl_(new DNSServiceImpl(io_service, *"0", NULL, NULL, checkin, lookup,
-        answer)), io_service_(io_service)
+        answer,para_flags)), io_service_(io_service)
 {
 }
 
@@ -187,21 +205,25 @@ DNSService::~DNSService() {
 }
 
 void
-DNSService::addServer(const char& port, const std::string& address) {
-    impl_->addServer(port, convertAddr(address));
+DNSService::addServer(const char& port, const std::string& address,UDPVersion para_flags) {
+    impl_->addServer(port, convertAddr(address),para_flags);
 }
 
 void
-DNSService::addServer(uint16_t port, const std::string& address) {
-    impl_->addServer(port, convertAddr(address));
+DNSService::addServer(uint16_t port, const std::string& address,UDPVersion para_flags) {
+    impl_->addServer(port, convertAddr(address),para_flags);
 }
 
 void DNSService::addServerTCPFromFD(int fd, int af) {
     impl_->addServerFromFD<DNSServiceImpl::TCPServerPtr, TCPServer>(fd, af);
 }
 
-void DNSService::addServerUDPFromFD(int fd, int af) {
-    impl_->addServerFromFD<DNSServiceImpl::UDPServerPtr, UDPServer>(fd, af);
+void DNSService::addServerUDPFromFD(int fd, int af,const UDPVersion param_flags) {
+    if(1 == param_flags) { 
+        impl_->addServerFromFD<DNSServiceImpl::SyncUDPServerPtr, SyncUDPServer>(fd, af);
+    } else if(2 == param_flags) {
+        impl_->addServerFromFD<DNSServiceImpl::UDPServerPtr, UDPServer>(fd, af);
+    }
 }
 
 void
diff --git a/src/lib/asiodns/dns_service.h b/src/lib/asiodns/dns_service.h
index 66f8d33..efb68ef 100644
--- a/src/lib/asiodns/dns_service.h
+++ b/src/lib/asiodns/dns_service.h
@@ -27,6 +27,15 @@ class DNSLookup;
 class DNSAnswer;
 class DNSServiceImpl;
 
+
+/// Codes for UDPServers used in addServer()method.
+///
+/// Note: the codes only used in how to create the UDPServers.
+enum UDPVersion {
+      SYNC_=1,     ///< used synchronous UDPServer
+      ASYNC_=2     ///< used asynchronous UDPServer
+};
+
 /// \brief Handle DNS Queries
 ///
 /// DNSService is the service that handles DNS queries and answers with
@@ -57,7 +66,8 @@ public:
     /// \param answer The answer provider (see \c DNSAnswer)
     DNSService(asiolink::IOService& io_service, const char& port,
                const char& address, isc::asiolink::SimpleCallback* checkin,
-               DNSLookup* lookup, DNSAnswer* answer);
+               DNSLookup* lookup, DNSAnswer* answer,
+               const UDPVersion param_flags = SYNC_);
     /// \brief The constructor with a specific port on which the services
     /// listen on.
     ///
@@ -75,19 +85,23 @@ public:
     DNSService(asiolink::IOService& io_service, const char& port,
                const bool use_ipv4, const bool use_ipv6,
                isc::asiolink::SimpleCallback* checkin, DNSLookup* lookup,
-               DNSAnswer* answer);
+               DNSAnswer* answer,
+               const UDPVersion param_flags = SYNC_);
     /// \brief The constructor without any servers.
     ///
     /// Use addServer() to add some servers.
     DNSService(asiolink::IOService& io_service, isc::asiolink::SimpleCallback* checkin,
-               DNSLookup* lookup, DNSAnswer* answer);
+               DNSLookup* lookup, DNSAnswer* answer,
+               const UDPVersion param_flags = SYNC_);
     /// \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);
+    void addServer(uint16_t port, const std::string &address,
+                   const UDPVersion param_flags = SYNC_);
+    void addServer(const char &port, const std::string &address,
+                   const UDPVersion param_flags = SYNC_);
 
     /// \brief Add another TCP server/listener to the service from already
     /// opened file descriptor
@@ -122,7 +136,7 @@ public:
     /// \throw isc::InvalidParameter if af is neither AF_INET nor AF_INET6.
     /// \throw isc::asiolink::IOError when a low-level error happens, like the
     ///     fd is not a valid descriptor or it can't be listened on.
-    void addServerUDPFromFD(int fd, int af);
+    void addServerUDPFromFD(int fd, int af,const UDPVersion param_flags = SYNC_);
 
     /// \brief Remove all servers from the service
     void clearServers();
diff --git a/src/lib/asiodns/tests/io_service_unittest.cc b/src/lib/asiodns/tests/io_service_unittest.cc
index cc64022..4b1889a 100644
--- a/src/lib/asiodns/tests/io_service_unittest.cc
+++ b/src/lib/asiodns/tests/io_service_unittest.cc
@@ -116,3 +116,8 @@ TEST(IOServiceTest, DISABLED_IPv4MappedDuplicateBind) {
     delete dns_service;
 }
 
+TEST(IOServiceTest, BadUdpServerVersion) {
+    IOService io_service;
+     DNSService* dns_service = new DNSService(io_service,NULL,NULL,NULL);
+     EXPECT_THROW(dns_service->addServer(*TEST_SERVER_PORT,"127.0.0.1",UDPVersion(3)),IOError);
+}



More information about the bind10-changes mailing list