From: Remi Gacogne Date: Sat, 7 Oct 2017 08:28:35 +0000 (+0200) Subject: If accept() returns EAGAIN, Socket::accept() returns a null pointer X-Git-Tag: rec-4.1.0-rc1~2^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F5792%2Fhead;p=thirdparty%2Fpdns.git If accept() returns EAGAIN, Socket::accept() returns a null pointer --- diff --git a/pdns/sstuff.hh b/pdns/sstuff.hh index e7fb6ee9ab..707b1ad12b 100644 --- a/pdns/sstuff.hh +++ b/pdns/sstuff.hh @@ -96,7 +96,7 @@ public: int s=::accept(d_socket,(sockaddr *)&remote, &remlen); if(s<0) { if(errno==EAGAIN) - return 0; + return nullptr; throw NetworkError("Accepting a connection: "+string(strerror(errno))); } diff --git a/pdns/webserver.cc b/pdns/webserver.cc index 09e838ac0e..7cfba4153b 100644 --- a/pdns/webserver.cc +++ b/pdns/webserver.cc @@ -350,6 +350,9 @@ void WebServer::go() while(true) { try { auto client = d_server->accept(); + if (!client) { + continue; + } if (client->acl(acl)) { std::thread webHandler(WebServerConnectionThreadStart, this, client); webHandler.detach(); diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index f590bd12b7..e54d812586 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -541,7 +541,9 @@ void AsyncServerNewConnectionMT(void *p) { AsyncServer *server = (AsyncServer*)p; try { auto socket = server->accept(); - server->d_asyncNewConnectionCallback(socket); + if (socket) { + server->d_asyncNewConnectionCallback(socket); + } } catch (NetworkError &e) { // we're running in a shared process/thread, so can't just terminate/abort. return;