From cea9f70da5f8d7945e9392d8af0621743100a896 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 8 Feb 2021 15:35:00 +0100 Subject: [PATCH] dnsdist: Move TCPClientCollection ctor to dnsdist-tcp.cc --- pdns/dnsdist-tcp.cc | 26 ++++++++++++++++++++++++++ pdns/dnsdist.hh | 25 +------------------------ 2 files changed, 27 insertions(+), 24 deletions(-) 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) { -- 2.47.2