Commit 0ee8be13 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3715] Use foreach for iterating over the IfaceMgr sockets.

parent 53ee5f29
......@@ -67,15 +67,10 @@ TestControl::TestControlSocket::~TestControlSocket() {
void
TestControl::TestControlSocket::initSocketData() {
BOOST_FOREACH(IfacePtr iface, IfaceMgr::instance().getIfaces()) {
const Iface::SocketCollection& socket_collection =
iface->getSockets();
for (Iface::SocketCollection::const_iterator s =
socket_collection.begin();
s != socket_collection.end();
++s) {
if (s->sockfd_ == sockfd_) {
BOOST_FOREACH(SocketInfo s, iface->getSockets()) {
if (s.sockfd_ == sockfd_) {
ifindex_ = iface->getIndex();
addr_ = s->addr_;
addr_ = s.addr_;
return;
}
}
......
......@@ -367,11 +367,9 @@ bool
IfaceMgr::hasOpenSocket(const uint16_t family) const {
// Iterate over all interfaces and search for open sockets.
BOOST_FOREACH(IfacePtr iface, ifaces_) {
const Iface::SocketCollection& sockets = iface->getSockets();
for (Iface::SocketCollection::const_iterator sock = sockets.begin();
sock != sockets.end(); ++sock) {
BOOST_FOREACH(SocketInfo sock, iface->getSockets()) {
// Check if the socket matches specified family.
if (sock->family_ == family) {
if (sock.family_ == family) {
// There is at least one socket open, so return.
return (true);
}
......@@ -385,14 +383,13 @@ bool
IfaceMgr::hasOpenSocket(const IOAddress& addr) const {
// Iterate over all interfaces and search for open sockets.
BOOST_FOREACH(IfacePtr iface, ifaces_) {
const Iface::SocketCollection& sockets = iface->getSockets();
for (Iface::SocketCollection::const_iterator sock = sockets.begin();
sock != sockets.end(); ++sock) {
BOOST_FOREACH(SocketInfo sock, iface->getSockets()) {
// Check if the socket address matches the specified address or
// if address is unspecified (in6addr_any).
if (sock->addr_ == addr) {
if (sock.addr_ == addr) {
return (true);
} else if (sock->addr_ == IOAddress("::")) {
} else if (sock.addr_ == IOAddress("::")) {
// Handle the case that the address is unspecified (any).
// In this case, we should check if the specified address
// belongs to any of the interfaces.
......@@ -896,17 +893,15 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
/// and then use its copy for select(). Please note that select() modifies
/// provided set to indicated which sockets have something to read.
BOOST_FOREACH(iface, ifaces_) {
const Iface::SocketCollection& socket_collection = iface->getSockets();
for (Iface::SocketCollection::const_iterator s = socket_collection.begin();
s != socket_collection.end(); ++s) {
BOOST_FOREACH(SocketInfo s, iface->getSockets()) {
// Only deal with IPv4 addresses.
if (s->addr_.isV4()) {
if (s.addr_.isV4()) {
// Add this socket to listening set
FD_SET(s->sockfd_, &sockets);
if (maxfd < s->sockfd_) {
maxfd = s->sockfd_;
FD_SET(s.sockfd_, &sockets);
if (maxfd < s.sockfd_) {
maxfd = s.sockfd_;
}
}
}
......@@ -969,11 +964,9 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
// Let's find out which interface/socket has the data
BOOST_FOREACH(iface, ifaces_) {
const Iface::SocketCollection& socket_collection = iface->getSockets();
for (Iface::SocketCollection::const_iterator s = socket_collection.begin();
s != socket_collection.end(); ++s) {
if (FD_ISSET(s->sockfd_, &sockets)) {
candidate = &(*s);
BOOST_FOREACH(SocketInfo s, iface->getSockets()) {
if (FD_ISSET(s.sockfd_, &sockets)) {
candidate = &(s);
break;
}
}
......@@ -1008,17 +1001,15 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
/// and then use its copy for select(). Please note that select() modifies
/// provided set to indicated which sockets have something to read.
BOOST_FOREACH(IfacePtr iface, ifaces_) {
const Iface::SocketCollection& socket_collection = iface->getSockets();
for (Iface::SocketCollection::const_iterator s = socket_collection.begin();
s != socket_collection.end(); ++s) {
BOOST_FOREACH(SocketInfo s, iface->getSockets()) {
// Only deal with IPv6 addresses.
if (s->addr_.isV6()) {
if (s.addr_.isV6()) {
// Add this socket to listening set
FD_SET(s->sockfd_, &sockets);
if (maxfd < s->sockfd_) {
maxfd = s->sockfd_;
FD_SET(s.sockfd_, &sockets);
if (maxfd < s.sockfd_) {
maxfd = s.sockfd_;
}
}
}
......@@ -1083,11 +1074,9 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
// Let's find out which interface/socket has the data
BOOST_FOREACH(IfacePtr iface, ifaces_) {
const Iface::SocketCollection& socket_collection = iface->getSockets();
for (Iface::SocketCollection::const_iterator s = socket_collection.begin();
s != socket_collection.end(); ++s) {
if (FD_ISSET(s->sockfd_, &sockets)) {
candidate = &(*s);
BOOST_FOREACH(SocketInfo s, iface->getSockets()) {
if (FD_ISSET(s.sockfd_, &sockets)) {
candidate = &(s);
break;
}
}
......
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -19,6 +19,8 @@
#include <dhcp/tests/pkt_filter_test_stub.h>
#include <dhcp/tests/pkt_filter6_test_stub.h>
#include <boost/foreach.hpp>
using namespace isc::asiolink;
namespace isc {
......@@ -151,10 +153,8 @@ IfaceMgrTestConfig::socketOpen(const std::string& iface_name,
isc_throw(Unexpected, "No such interface '" << iface_name << "'");
}
const Iface::SocketCollection& sockets = iface->getSockets();
for (Iface::SocketCollection::const_iterator sock = sockets.begin();
sock != sockets.end(); ++sock) {
if (sock->family_ == family) {
BOOST_FOREACH(SocketInfo sock, iface->getSockets()) {
if (sock.family_ == family) {
return (true);
}
}
......@@ -169,11 +169,9 @@ IfaceMgrTestConfig::socketOpen(const std::string& iface_name,
isc_throw(Unexpected, "No such interface '" << iface_name << "'");
}
const Iface::SocketCollection& sockets = iface->getSockets();
for (Iface::SocketCollection::const_iterator sock = sockets.begin();
sock != sockets.end(); ++sock) {
if ((sock->family_ == AF_INET) &&
(sock->addr_ == IOAddress(address))) {
BOOST_FOREACH(SocketInfo sock, iface->getSockets()) {
if ((sock.family_ == AF_INET) &&
(sock.addr_ == IOAddress(address))) {
return (true);
}
}
......@@ -187,11 +185,9 @@ IfaceMgrTestConfig::unicastOpen(const std::string& iface_name) const {
isc_throw(Unexpected, "No such interface '" << iface_name << "'");
}
const Iface::SocketCollection& sockets = iface->getSockets();
for (Iface::SocketCollection::const_iterator sock = sockets.begin();
sock != sockets.end(); ++sock) {
if ((!sock->addr_.isV6LinkLocal()) &&
(!sock->addr_.isV6Multicast())) {
BOOST_FOREACH(SocketInfo sock, iface->getSockets()) {
if ((!sock.addr_.isV6LinkLocal()) &&
(!sock.addr_.isV6Multicast())) {
return (true);
}
}
......
// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -16,6 +16,8 @@
#include <dhcp/pkt6.h>
#include <dhcp/tests/pkt_filter6_test_utils.h>
#include <boost/foreach.hpp>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
......@@ -185,10 +187,8 @@ PktFilter6Stub::openSocket(const Iface& iface, const isc::asiolink::IOAddress& a
const uint16_t port, const bool) {
// Check if there is any other socket bound to the specified address
// and port on this interface.
const Iface::SocketCollection& sockets = iface.getSockets();
for (Iface::SocketCollection::const_iterator socket = sockets.begin();
socket != sockets.end(); ++socket) {
if ((socket->addr_ == addr) && (socket->port_ == port)) {
BOOST_FOREACH(SocketInfo socket, iface.getSockets()) {
if ((socket.addr_ == addr) && (socket.port_ == port)) {
isc_throw(SocketConfigError, "test socket bind error");
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment