Parcourir la source

changed interface of the IOService constructor so that it's impossible
to pass NULL port string, which simplifies validation.


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac221b@2466 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya il y a 15 ans
Parent
commit
22d942fa39

+ 4 - 4
src/bin/auth/asio_link.cc

@@ -483,7 +483,7 @@ private:
 
 class IOServiceImpl {
 public:
-    IOServiceImpl(AuthSrv* auth_server, const char* address, const char* port,
+    IOServiceImpl(AuthSrv* auth_server, const char* address, const char& port,
                   const bool use_ipv4, const bool use_ipv6);
     asio::io_service io_service_;
     AuthSrv* auth_server_;
@@ -500,7 +500,7 @@ public:
 };
 
 IOServiceImpl::IOServiceImpl(AuthSrv* auth_server, const char* const address,
-                             const char* const port, const bool use_ipv4,
+                             const char& port, const bool use_ipv4,
                              const bool use_ipv6) :
     auth_server_(auth_server),
     udp4_server_(UDPServerPtr()), udp6_server_(UDPServerPtr()),
@@ -509,7 +509,7 @@ IOServiceImpl::IOServiceImpl(AuthSrv* auth_server, const char* const address,
     uint16_t portnum;
 
     try {
-        portnum = boost::lexical_cast<uint16_t>(port);
+        portnum = boost::lexical_cast<uint16_t>(&port);
     } catch (const boost::bad_lexical_cast& ex) {
         isc_throw(IOError, "[b10-auth] Invalid port number '" << port << "'");
     }
@@ -555,7 +555,7 @@ IOServiceImpl::IOServiceImpl(AuthSrv* auth_server, const char* const address,
 }
 
 IOService::IOService(AuthSrv* auth_server, const char* const address,
-                     const char* const port, const bool use_ipv4,
+                     const char& port, const bool use_ipv4,
                      const bool use_ipv6) {
     impl_ = new IOServiceImpl(auth_server, address, port, use_ipv4, use_ipv6);
 }

+ 1 - 1
src/bin/auth/asio_link.h

@@ -390,7 +390,7 @@ public:
     /// \brief The constructor.  Currently very specific to the authoritative
     /// server implementation.
     IOService(AuthSrv* auth_server, const char* const address,
-              const char* const port, bool use_ipv4, bool use_ipv6);
+              const char& port, bool use_ipv4, bool use_ipv6);
     /// \brief The destructor.
     ~IOService();
     //@}

+ 1 - 1
src/bin/auth/main.cc

@@ -162,7 +162,7 @@ main(int argc, char* argv[]) {
         auth_server->setVerbose(verbose_mode);
         cout << "[b10-auth] Server created." << endl;
 
-        io_service = new asio_link::IOService(auth_server, address, port,
+        io_service = new asio_link::IOService(auth_server, address, *port,
                                               use_ipv4, use_ipv6);
         cout << "[b10-auth] IOService created." << endl;
 

+ 5 - 5
src/bin/auth/tests/asio_link_unittest.cc

@@ -90,10 +90,10 @@ TEST(IOSocketTest, dummySockets) {
 }
 
 TEST(IOServiceTest, badPort) {
-    EXPECT_THROW(IOService(NULL, NULL, "65536", true, false), IOError);
-    EXPECT_THROW(IOService(NULL, NULL, "5300.0", true, false), IOError);
-    EXPECT_THROW(IOService(NULL, NULL, "-1", true, false), IOError);
-    EXPECT_THROW(IOService(NULL, NULL, "domain", true, false), IOError);
+    EXPECT_THROW(IOService(NULL, NULL, *"65536", true, false), IOError);
+    EXPECT_THROW(IOService(NULL, NULL, *"5300.0", true, false), IOError);
+    EXPECT_THROW(IOService(NULL, NULL, *"-1", true, false), IOError);
+    EXPECT_THROW(IOService(NULL, NULL, *"domain", true, false), IOError);
 }
 
 struct addrinfo*
@@ -191,7 +191,7 @@ private:
 };
 
 ASIOLinkTest::ASIOLinkTest() :
-    io_service_(NULL, NULL, TEST_PORT, true, true),
+    io_service_(NULL, NULL, *TEST_PORT, true, true),
     sock_(-1), res_(NULL)
 {
     io_service_.setCallBack(ASIOCallBack(this));