Browse Source

[1238] Changes after review: openSocket*() now returns int

Tomek Mrugalski 13 years ago
parent
commit
86a4ce4511
3 changed files with 12 additions and 19 deletions
  1. 5 10
      src/bin/dhcp6/iface_mgr.cc
  2. 4 4
      src/bin/dhcp6/iface_mgr.h
  3. 3 5
      src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

+ 5 - 10
src/bin/dhcp6/iface_mgr.cc

@@ -87,11 +87,7 @@ bool IfaceMgr::Iface::delAddress(const isc::asiolink::IOAddress& addr) {
     // of the same address added, we are in deep problems anyway.
     size_t size = addrs_.size();
     addrs_.erase(remove(addrs_.begin(), addrs_.end(), addr), addrs_.end());
-    if (addrs_.size() < size) {
-        return (true);
-    } else {
-        return (false);
-    }
+    return (addrs_.size() < size);
 }
 
 bool IfaceMgr::Iface::delSocket(uint16_t sockfd) {
@@ -274,9 +270,8 @@ IfaceMgr::getIface(const std::string& ifname) {
     return (NULL); // not found
 }
 
-uint16_t
-IfaceMgr::openSocket(const std::string& ifname,
-                     const IOAddress& addr,
+int
+IfaceMgr::openSocket(const std::string& ifname, const IOAddress& addr,
                      int port) {
     Iface* iface = getIface(ifname);
     if (!iface) {
@@ -293,7 +288,7 @@ IfaceMgr::openSocket(const std::string& ifname,
     }
 }
 
-uint16_t
+int
 IfaceMgr::openSocket4(Iface& iface, const IOAddress& addr, int port) {
 
     cout << "Creating UDP4 socket on " << iface.getFullName()
@@ -335,7 +330,7 @@ IfaceMgr::openSocket4(Iface& iface, const IOAddress& addr, int port) {
     return (sock);
 }
 
-uint16_t
+int
 IfaceMgr::openSocket6(Iface& iface, const IOAddress& addr, int port) {
 
     cout << "Creating UDP6 socket on " << iface.getFullName()

+ 4 - 4
src/bin/dhcp6/iface_mgr.h

@@ -291,8 +291,8 @@ public:
     ///
     /// @return socket descriptor, if socket creation, binding and multicast
     /// group join were all successful.
-    uint16_t openSocket(const std::string& ifname,
-                        const isc::asiolink::IOAddress& addr, int port);
+    int openSocket(const std::string& ifname,
+                   const isc::asiolink::IOAddress& addr, int port);
 
     /// Opens IPv6 sockets on detected interfaces.
     ///
@@ -328,7 +328,7 @@ protected:
     /// @param port a port that created socket should be bound to
     ///
     /// @return socket descriptor
-    uint16_t openSocket4(Iface& iface, const isc::asiolink::IOAddress& addr, int port);
+    int openSocket4(Iface& iface, const isc::asiolink::IOAddress& addr, int port);
 
     /// @brief Opens IPv6 socket.
     ///
@@ -341,7 +341,7 @@ protected:
     /// @param port a port that created socket should be bound to
     ///
     /// @return socket descriptor
-    uint16_t openSocket6(Iface& iface, const isc::asiolink::IOAddress& addr, int port);
+    int openSocket6(Iface& iface, const isc::asiolink::IOAddress& addr, int port);
 
     /// @brief Adds an interface to list of known interfaces.
     ///

+ 3 - 5
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

@@ -57,15 +57,13 @@ TEST_F(Dhcpv6SrvTest, basic) {
     // interfaces.txt instead. It will pretend to have detected
     // fe80::1234 link-local address on eth0 interface. Obviously
     // an attempt to bind this socket will fail.
-    Dhcpv6Srv * srv = 0;
+    Dhcpv6Srv* srv = 0;
     ASSERT_NO_THROW( {
         // open an unpriviledged port
         srv = new Dhcpv6Srv(DHCP6_SERVER_PORT + 10000);
     });
-    if (srv) {
-        delete srv;
-    }
 
+    delete srv;
 }
 
 TEST_F(Dhcpv6SrvTest, Solicit_basic) {
@@ -75,7 +73,7 @@ TEST_F(Dhcpv6SrvTest, Solicit_basic) {
     // a dummy content for client-id
     boost::shared_array<uint8_t> clntDuid(new uint8_t[32]);
     for (int i = 0; i < 32; i++)
-        clntDuid[i] = 100+i;
+        clntDuid[i] = 100 + i;
 
     boost::shared_ptr<Pkt6> sol =
         boost::shared_ptr<Pkt6>(new Pkt6(DHCPV6_SOLICIT,