}
void
-IfaceMgr::handleClosedExternalSocket(SocketCallbackInfo const& s) {
+IfaceMgr::handleClosedExternalSocket(SocketCallbackInfoIterator it) {
errno = 0;
- if (fcntl(s.socket_, F_GETFD) < 0 && (errno == EBADF)) {
- SocketCallbackInfo x(s);
+ if (fcntl(it->socket_, F_GETFD) < 0 && (errno == EBADF)) {
+ SocketCallbackInfo x(*it);
x.unusable_ = true;
- auto& idx = callbacks_.get<1>();
- auto it = idx.find(s.socket_);
- // Expect that the external socket is still there!
- if (it != idx.end()) {
- idx.replace(it, x);
- }
- isc_throw(SocketFDError, "unexpected state (closed) for fd: " << s.socket_);
+ callbacks_.replace(it, x);
+ isc_throw(SocketFDError, "unexpected state (closed) for fd: " << x.socket_);
}
}
void
IfaceMgr::handleClosedExternalSockets() {
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo s : callbacks_) {
- if (s.unusable_) {
+ for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
+ if (it->unusable_) {
continue;
}
- handleClosedExternalSocket(s);
+ handleClosedExternalSocket(it);
}
}
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (!callbacks_.empty()) {
- for (SocketCallbackInfo const& s : callbacks_) {
- if (s.unusable_) {
+ for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
+ if (it->unusable_) {
continue;
}
- handleClosedExternalSocket(s);
+ handleClosedExternalSocket(it);
// Add this socket to listening set
- fd_event_handler_->add(s.socket_);
+ fd_event_handler_->add(it->socket_);
}
}
}
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo const& s : callbacks_) {
- if (s.unusable_) {
+ for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
+ if (it->unusable_) {
continue;
}
- handleClosedExternalSocket(s);
- if (fd_event_handler_->readReady(s.socket_) ||
- fd_event_handler_->hasError(s.socket_)) {
+ handleClosedExternalSocket(it);
+ if (fd_event_handler_->readReady(it->socket_) ||
+ fd_event_handler_->hasError(it->socket_)) {
found = true;
// something received over external socket
- if (s.callback_) {
+ if (it->callback_) {
// Note the external socket to call its callback without
// the lock taken so it can be deleted.
- ex_sock = s;
+ ex_sock = *it;
break;
}
}
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (!callbacks_.empty()) {
- for (SocketCallbackInfo const& s : callbacks_) {
- if (s.unusable_) {
+ for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
+ if (it->unusable_) {
continue;
}
- handleClosedExternalSocket(s);
+ handleClosedExternalSocket(it);
// Add this socket to listening set
- fd_event_handler_->add(s.socket_);
+ fd_event_handler_->add(it->socket_);
}
}
}
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo const& s : callbacks_) {
- if (s.unusable_) {
+ for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
+ if (it->unusable_) {
continue;
}
- handleClosedExternalSocket(s);
- if (fd_event_handler_->readReady(s.socket_) ||
- fd_event_handler_->hasError(s.socket_)) {
+ handleClosedExternalSocket(it);
+ if (fd_event_handler_->readReady(it->socket_) ||
+ fd_event_handler_->hasError(it->socket_)) {
found = true;
// something received over external socket
- if (s.callback_) {
+ if (it->callback_) {
// Note the external socket to call its callback without
// the lock taken so it can be deleted.
- ex_sock = s;
+ ex_sock = *it;
break;
}
}
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (!callbacks_.empty()) {
- for (SocketCallbackInfo const& s : callbacks_) {
- if (s.unusable_) {
+ for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
+ if (it->unusable_) {
continue;
}
- handleClosedExternalSocket(s);
+ handleClosedExternalSocket(it);
// Add this socket to listening set
- fd_event_handler_->add(s.socket_);
+ fd_event_handler_->add(it->socket_);
}
}
}
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo const& s : callbacks_) {
- if (s.unusable_) {
+ for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
+ if (it->unusable_) {
continue;
}
- handleClosedExternalSocket(s);
- if (fd_event_handler_->readReady(s.socket_) ||
- fd_event_handler_->hasError(s.socket_)) {
+ handleClosedExternalSocket(it);
+ if (fd_event_handler_->readReady(it->socket_) ||
+ fd_event_handler_->hasError(it->socket_)) {
found = true;
// something received over external socket
- if (s.callback_) {
+ if (it->callback_) {
// Note the external socket to call its callback without
// the lock taken so it can be deleted.
- ex_sock = s;
+ ex_sock = *it;
break;
}
}
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (!callbacks_.empty()) {
- for (SocketCallbackInfo const& s : callbacks_) {
- if (s.unusable_) {
+ for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
+ if (it->unusable_) {
continue;
}
- handleClosedExternalSocket(s);
+ handleClosedExternalSocket(it);
// Add this socket to listening set
- fd_event_handler_->add(s.socket_);
+ fd_event_handler_->add(it->socket_);
}
}
}
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo const& s : callbacks_) {
- if (s.unusable_) {
+ for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) {
+ if (it->unusable_) {
continue;
}
- handleClosedExternalSocket(s);
- if (fd_event_handler_->readReady(s.socket_) ||
- fd_event_handler_->hasError(s.socket_)) {
+ handleClosedExternalSocket(it);
+ if (fd_event_handler_->readReady(it->socket_) ||
+ fd_event_handler_->hasError(it->socket_)) {
found = true;
// something received over external socket
- if (s.callback_) {
+ if (it->callback_) {
// Note the external socket to call its callback without
// the lock taken so it can be deleted.
- ex_sock = s;
+ ex_sock = *it;
break;
}
}
callback_ok = (pipefd[0] == fd);
}));
ASSERT_TRUE(ifacemgr->isExternalSocket(pipefd[0]));
+ ASSERT_FALSE(ifacemgr->isExternalSocketUnusable(pipefd[0]));
// Let's create a second pipe and register it as well
int secondpipe[2];
callback2_ok = (secondpipe[0] == fd);
}));
ASSERT_TRUE(ifacemgr->isExternalSocket(secondpipe[0]));
+ ASSERT_FALSE(ifacemgr->isExternalSocketUnusable(secondpipe[0]));
// Verify a call with no data and normal external sockets works ok.
Pkt4Ptr pkt4;
try {
pkt4 = ifacemgr->receive4(RECEIVE_WAIT_MS(10));
} catch (const SocketFDError& ex) {
- std::string err_msg("unexpected state (closed) for fd: ");
- EXPECT_EQ(err_msg, std::string(ex.what()).substr(0, err_msg.length()));
+ std::ostringstream err_msg;
+ err_msg << "unexpected state (closed) for fd: " << pipefd[0];
+ EXPECT_EQ(err_msg.str(), ex.what());
} catch (const std::exception& ex) {
ADD_FAILURE() << "wrong exception thrown: " << ex.what();
}
+ EXPECT_TRUE(ifacemgr->isExternalSocketUnusable(pipefd[0]));
+ EXPECT_FALSE(ifacemgr->isExternalSocketUnusable(secondpipe[0]));
// No callback invocations and no DHCPv4 pkt.
EXPECT_FALSE(callback_ok);
callback_ok = (pipefd[0] == fd);
}));
ASSERT_TRUE(ifacemgr->isExternalSocket(pipefd[0]));
+ ASSERT_FALSE(ifacemgr->isExternalSocketUnusable(pipefd[0]));
// Let's create a second pipe and register it as well
int secondpipe[2];
callback2_ok = (secondpipe[0] == fd);
}));
ASSERT_TRUE(ifacemgr->isExternalSocket(secondpipe[0]));
+ ASSERT_FALSE(ifacemgr->isExternalSocketUnusable(secondpipe[0]));
// Verify a call with no data and normal external sockets works ok.
Pkt6Ptr pkt6;
try {
pkt6 = ifacemgr->receive6(RECEIVE_WAIT_MS(10));
} catch (const SocketFDError& ex) {
- std::string err_msg("unexpected state (closed) for fd: ");
- EXPECT_EQ(err_msg, std::string(ex.what()).substr(0, err_msg.length()));
+ std::ostringstream err_msg;
+ err_msg << "unexpected state (closed) for fd: " << pipefd[0];
+ EXPECT_EQ(err_msg.str(), ex.what());
} catch (const std::exception& ex) {
ADD_FAILURE() << "wrong exception thrown: " << ex.what();
}
+ EXPECT_TRUE(ifacemgr->isExternalSocketUnusable(pipefd[0]));
+ EXPECT_FALSE(ifacemgr->isExternalSocketUnusable(secondpipe[0]));
// No callback invocations and no DHCPv6 pkt.
EXPECT_FALSE(callback_ok);