Permalink
Browse files

Merge updated patch found in #664, which fixes #664 by removing the o…

…ptimization of not using 'poll' when we are listening on only 1 socket. This will slow us down when listening to one socket only,

but hopefully only slightly. It does simplify the code.
  • Loading branch information...
1 parent 2df0838 commit 315dd2e6d945b624a0c611ea314b573ca3d9817e @ahupowerdns ahupowerdns committed May 23, 2013
Showing with 24 additions and 30 deletions.
  1. +24 −30 pdns/nameserver.cc
View
@@ -105,7 +105,7 @@ void UDPNameserver::bindIPv4()
Utility::setCloseOnExec(s);
- if(locals.size() > 1 && !Utility::setNonBlocking(s))
+ if(!Utility::setNonBlocking(s))
throw AhuException("Unable to set UDP socket to non-blocking: "+stringerror());
memset(&locala,0,sizeof(locala));
@@ -204,6 +204,9 @@ void UDPNameserver::bindIPv6()
throw AhuException("Unable to acquire a UDPv6 socket: "+string(strerror(errno)));
Utility::setCloseOnExec(s);
+ if(!Utility::setNonBlocking(s))
+ throw AhuException("Unable to set UDPv6 socket to non-blocking: "+stringerror());
+
ComboAddress locala(localname, ::arg().asNum("local-port"));
@@ -374,42 +377,33 @@ DNSPacket *UDPNameserver::receive(DNSPacket *prefilled)
int err;
vector<struct pollfd> rfds= d_rfds;
- if(d_sockets.size()>1) {
- BOOST_FOREACH(struct pollfd &pfd, rfds) {
- pfd.events = POLLIN;
- pfd.revents = 0;
- }
+
+ BOOST_FOREACH(struct pollfd &pfd, rfds) {
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+ }
- err = poll(&rfds[0], rfds.size(), -1);
- if(err < 0)
- unixDie("Unable to poll for new UDP events");
+ err = poll(&rfds[0], rfds.size(), -1);
+ if(err < 0)
+ unixDie("Unable to poll for new UDP events");
- BOOST_FOREACH(struct pollfd &pfd, rfds) {
- if(pfd.revents & POLLIN) {
- sock=pfd.fd;
- len=0;
+ BOOST_FOREACH(struct pollfd &pfd, rfds) {
+ if(pfd.revents & POLLIN) {
+ sock=pfd.fd;
+ len=0;
- if((len=recvmsg(sock, &msgh, 0)) < 0 ) {
- if(errno != EAGAIN)
- L<<Logger::Error<<"recvfrom gave error, ignoring: "<<strerror(errno)<<endl;
- return 0;
- }
- break;
+ if((len=recvmsg(sock, &msgh, 0)) < 0 ) {
+ if(errno != EAGAIN)
+ L<<Logger::Error<<"recvfrom gave error, ignoring: "<<strerror(errno)<<endl;
+ return 0;
}
- }
- if(sock==-1)
- throw AhuException("poll betrayed us! (should not happen)");
- }
- else {
- sock=d_sockets[0];
-
- if((len=recvmsg(sock, &msgh, 0)) < 0 ) {
- if(errno != EAGAIN)
- L<<Logger::Error<<"recvfrom gave error, ignoring: "<<strerror(errno)<<endl;
- return 0;
+ break;
}
}
+ if(sock==-1)
+ throw AhuException("poll betrayed us! (should not happen)");
+
DLOG(L<<"Received a packet " << len <<" bytes long from "<< remote.toString()<<endl);
DNSPacket *packet;

0 comments on commit 315dd2e

Please sign in to comment.