Browse Source

[1238] Sockets are now closed properly.

Tomek Mrugalski 13 years ago
parent
commit
b09fdcc6b4
4 changed files with 14 additions and 3 deletions
  1. 2 0
      src/bin/dhcp6/dhcp6_srv.cc
  2. 1 1
      src/bin/dhcp6/dhcp6_srv.h
  3. 6 2
      src/bin/dhcp6/iface_mgr.cc
  4. 5 0
      src/bin/dhcp6/iface_mgr.h

+ 2 - 0
src/bin/dhcp6/dhcp6_srv.cc

@@ -47,6 +47,8 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t port) {
 
 Dhcpv6Srv::~Dhcpv6Srv() {
     cout << "DHCPv6 Srv shutdown." << endl;
+
+    IfaceMgr::instance().closeSockets();
 }
 
 bool

+ 1 - 1
src/bin/dhcp6/dhcp6_srv.h

@@ -47,7 +47,7 @@ public:
     Dhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT);
 
     /// @brief Destructor. Used during DHCPv6 service shutdown.
-    ~Dhcpv6Srv();
+    virtual ~Dhcpv6Srv();
 
     /// @brief Returns server-intentifier option
     ///

+ 6 - 2
src/bin/dhcp6/iface_mgr.cc

@@ -134,8 +134,7 @@ IfaceMgr::IfaceMgr()
     }
 }
 
-IfaceMgr::~IfaceMgr() {
-
+void IfaceMgr::closeSockets() {
     for (IfaceCollection::iterator iface = ifaces_.begin();
          iface != ifaces_.end(); ++iface) {
 
@@ -147,6 +146,11 @@ IfaceMgr::~IfaceMgr() {
         iface->sockets_.clear();
     }
 
+}
+
+IfaceMgr::~IfaceMgr() {
+    closeSockets();
+
     // control_buf_ is deleted automatically (scoped_ptr)
     control_buf_len_ = 0;
 }

+ 5 - 0
src/bin/dhcp6/iface_mgr.h

@@ -301,6 +301,11 @@ public:
     /// @param port specifies port number (usually DHCP6_SERVER_PORT)
     void openSockets(uint16_t port);
 
+
+    /// @brief Closes all open sockets.
+    /// Is used in destructor, but also from Dhcpv4_srv and Dhcpv6_srv classes.
+    void closeSockets();
+
     // don't use private, we need derived classes in tests
 protected: