IfacePtr recv_if;
for (const IfacePtr& iface : ifaces_) {
for (const SocketInfo& s : iface->getSockets()) {
- if (fd_event_handler_->readReady(s.sockfd_) ||
- fd_event_handler_->hasError(s.sockfd_)) {
- candidate.reset(new SocketInfo(s));
- break;
+ if (!fd_event_handler_->readReady(s.sockfd_) &&
+ !fd_event_handler_->hasError(s.sockfd_)) {
+ continue;
+ }
+ if (fd_event_handler_->hasError(s.sockfd_)) {
+ handleIfaceSocketError(s);
}
+ candidate.reset(new SocketInfo(s));
+ break;
}
if (candidate) {
recv_if = iface;
isc_throw(SocketFDError, "received data over unknown socket");
}
- // Now we have a socket, let's get some data from it!
+ // Check that we have something to read.
+ int len;
+ if (ioctl(candidate->sockfd_, FIONREAD, &len) < 0) {
+ isc_throw(SocketReadError, strerror(errno));
+ }
+ if (len == 0) {
+ // Nothing to read.
+ return (Pkt4Ptr());
+ }
+
// Assuming that packet filter is not null, because its modifier checks it.
return (packet_filter_->receive(*recv_if, *candidate));
}
// @todo: fix iface starvation
for (const IfacePtr& iface : ifaces_) {
for (const SocketInfo& s : iface->getSockets()) {
- if (fd_event_handler_->readReady(s.sockfd_) ||
- fd_event_handler_->hasError(s.sockfd_)) {
- candidate.reset(new SocketInfo(s));
- break;
+ if (!fd_event_handler_->readReady(s.sockfd_) &&
+ !fd_event_handler_->hasError(s.sockfd_)) {
+ continue;
+ }
+ if (fd_event_handler_->hasError(s.sockfd_)) {
+ handleIfaceSocketError(s);
}
+ candidate.reset(new SocketInfo(s));
+ break;
}
if (candidate) {
break;
isc_throw(SocketFDError, "received data over unknown socket");
}
+ // Check that we have something to read.
+ int len;
+ if (ioctl(candidate->sockfd_, FIONREAD, &len) < 0) {
+ isc_throw(SocketReadError, strerror(errno));
+ }
+ if (len == 0) {
+ // Nothing to read.
+ return (Pkt6Ptr());
+ }
+
// Assuming that packet filter is not null, because its modifier checks it.
return (packet_filter6_->receive(*candidate));
}