Browse Source

[3715] Use foreach to iterate over IfaceMgr callbacks.

Marcin Siodelski 10 years ago
parent
commit
29cc4209a3
1 changed files with 19 additions and 26 deletions
  1. 19 26
      src/lib/dhcp/iface_mgr.cc

+ 19 - 26
src/lib/dhcp/iface_mgr.cc

@@ -292,13 +292,11 @@ IfaceMgr::isDirectResponseSupported() const {
 
 
 void
 void
 IfaceMgr::addExternalSocket(int socketfd, SocketCallback callback) {
 IfaceMgr::addExternalSocket(int socketfd, SocketCallback callback) {
-    for (SocketCallbackInfoContainer::iterator s = callbacks_.begin();
-         s != callbacks_.end(); ++s) {
-
+    BOOST_FOREACH(SocketCallbackInfo s, callbacks_) {
         // There's such a socket description there already.
         // There's such a socket description there already.
         // Update the callback and we're done
         // Update the callback and we're done
-        if (s->socket_ == socketfd) {
-            s->callback_ = callback;
+        if (s.socket_ == socketfd) {
+            s.callback_ = callback;
             return;
             return;
         }
         }
     }
     }
@@ -909,11 +907,10 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
 
 
     // if there are any callbacks for external sockets registered...
     // if there are any callbacks for external sockets registered...
     if (!callbacks_.empty()) {
     if (!callbacks_.empty()) {
-        for (SocketCallbackInfoContainer::const_iterator s = callbacks_.begin();
-             s != callbacks_.end(); ++s) {
-            FD_SET(s->socket_, &sockets);
-            if (maxfd < s->socket_) {
-                maxfd = s->socket_;
+        BOOST_FOREACH(SocketCallbackInfo s, callbacks_) {
+            FD_SET(s.socket_, &sockets);
+            if (maxfd < s.socket_) {
+                maxfd = s.socket_;
             }
             }
         }
         }
     }
     }
@@ -944,9 +941,8 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
     }
     }
 
 
     // Let's find out which socket has the data
     // Let's find out which socket has the data
-    for (SocketCallbackInfoContainer::iterator s = callbacks_.begin();
-         s != callbacks_.end(); ++s) {
-        if (!FD_ISSET(s->socket_, &sockets)) {
+    BOOST_FOREACH(SocketCallbackInfo s, callbacks_) {
+        if (!FD_ISSET(s.socket_, &sockets)) {
             continue;
             continue;
         }
         }
 
 
@@ -955,8 +951,8 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
         // Calling the external socket's callback provides its service
         // Calling the external socket's callback provides its service
         // layer access without integrating any specific features
         // layer access without integrating any specific features
         // in IfaceMgr
         // in IfaceMgr
-        if (s->callback_) {
-            s->callback_();
+        if (s.callback_) {
+            s.callback_();
         }
         }
 
 
         return (Pkt4Ptr());
         return (Pkt4Ptr());
@@ -1017,13 +1013,11 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
 
 
     // if there are any callbacks for external sockets registered...
     // if there are any callbacks for external sockets registered...
     if (!callbacks_.empty()) {
     if (!callbacks_.empty()) {
-        for (SocketCallbackInfoContainer::const_iterator s = callbacks_.begin();
-             s != callbacks_.end(); ++s) {
-
+        BOOST_FOREACH(SocketCallbackInfo s, callbacks_) {
             // Add it to the set as well
             // Add it to the set as well
-            FD_SET(s->socket_, &sockets);
-            if (maxfd < s->socket_) {
-                maxfd = s->socket_;
+            FD_SET(s.socket_, &sockets);
+            if (maxfd < s.socket_) {
+                maxfd = s.socket_;
             }
             }
         }
         }
     }
     }
@@ -1054,9 +1048,8 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
     }
     }
 
 
     // Let's find out which socket has the data
     // Let's find out which socket has the data
-    for (SocketCallbackInfoContainer::iterator s = callbacks_.begin();
-         s != callbacks_.end(); ++s) {
-        if (!FD_ISSET(s->socket_, &sockets)) {
+    BOOST_FOREACH(SocketCallbackInfo s, callbacks_) {
+        if (!FD_ISSET(s.socket_, &sockets)) {
             continue;
             continue;
         }
         }
 
 
@@ -1065,8 +1058,8 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
         // Calling the external socket's callback provides its service
         // Calling the external socket's callback provides its service
         // layer access without integrating any specific features
         // layer access without integrating any specific features
         // in IfaceMgr
         // in IfaceMgr
-        if (s->callback_) {
-            s->callback_();
+        if (s.callback_) {
+            s.callback_();
         }
         }
 
 
         return (Pkt6Ptr());
         return (Pkt6Ptr());