From 315dd2e6d945b624a0c611ea314b573ca3d9817e Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 23 May 2013 10:17:23 +0200 Subject: [PATCH] Merge updated patch found in #664, which fixes #664 by removing the optimization 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. --- pdns/nameserver.cc | 54 +++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index 067a33e60..a343dfd02 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -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 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<