From: Remi Gacogne Date: Mon, 8 Feb 2021 14:35:00 +0000 (+0100) Subject: dnsdist: Move TCPClientCollection ctor to dnsdist-tcp.cc X-Git-Tag: dnsdist-1.6.0-alpha2~11^2~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cea9f70da5f8d7945e9392d8af0621743100a896;p=thirdparty%2Fpdns.git dnsdist: Move TCPClientCollection ctor to dnsdist-tcp.cc --- diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index a17c5acf62..e4840fc9e1 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -190,6 +190,32 @@ std::shared_ptr IncomingTCPConnectionState::getDownstrea static void tcpClientThread(int pipefd); +TCPClientCollection::TCPClientCollection(size_t maxThreads, bool useSinglePipe): d_tcpclientthreads(maxThreads), d_maxthreads(maxThreads), d_singlePipe{-1,-1}, d_useSinglePipe(useSinglePipe) +{ + if (d_useSinglePipe) { + if (pipe(d_singlePipe) < 0) { + int err = errno; + throw std::runtime_error("Error creating the TCP single communication pipe: " + stringerror(err)); + } + + if (!setNonBlocking(d_singlePipe[0])) { + int err = errno; + close(d_singlePipe[0]); + close(d_singlePipe[1]); + throw std::runtime_error("Error setting the TCP single communication pipe non-blocking: " + stringerror(err)); + } + + if (!setNonBlocking(d_singlePipe[1])) { + int err = errno; + close(d_singlePipe[0]); + close(d_singlePipe[1]); + throw std::runtime_error("Error setting the TCP single communication pipe non-blocking: " + stringerror(err)); + } + + setPipeBufferSize(d_singlePipe[0], 1048576); + } +} + void TCPClientCollection::addTCPClientThread() { int pipefds[2] = { -1, -1}; diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index a98c7324d3..81b1b3af52 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -831,30 +831,7 @@ class TCPClientCollection { const bool d_useSinglePipe; public: - TCPClientCollection(size_t maxThreads, bool useSinglePipe=false): d_tcpclientthreads(maxThreads), d_maxthreads(maxThreads), d_singlePipe{-1,-1}, d_useSinglePipe(useSinglePipe) - - { - if (d_useSinglePipe) { - if (pipe(d_singlePipe) < 0) { - int err = errno; - throw std::runtime_error("Error creating the TCP single communication pipe: " + stringerror(err)); - } - - if (!setNonBlocking(d_singlePipe[0])) { - int err = errno; - close(d_singlePipe[0]); - close(d_singlePipe[1]); - throw std::runtime_error("Error setting the TCP single communication pipe non-blocking: " + stringerror(err)); - } - - if (!setNonBlocking(d_singlePipe[1])) { - int err = errno; - close(d_singlePipe[0]); - close(d_singlePipe[1]); - throw std::runtime_error("Error setting the TCP single communication pipe non-blocking: " + stringerror(err)); - } - } - } + TCPClientCollection(size_t maxThreads, bool useSinglePipe=false); int getThread() { if (d_numthreads == 0) {