]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Cleaner TCPCrossProtocolQuerySender() constructor
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 23 Nov 2021 14:36:12 +0000 (15:36 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 7 Apr 2022 13:52:55 +0000 (15:52 +0200)
pdns/dnsdist-tcp.cc

index ada447c3de3fafe972877ef110bb2840ed424271..7acf6909e367d02acebc92c22a2a3995cc565860 100644 (file)
@@ -565,7 +565,7 @@ struct TCPCrossProtocolResponse
 class TCPCrossProtocolQuerySender : public TCPQuerySender
 {
 public:
-  TCPCrossProtocolQuerySender(std::shared_ptr<IncomingTCPConnectionState>& state, int responseDescriptor): d_state(state), d_responseDesc(responseDescriptor)
+  TCPCrossProtocolQuerySender(std::shared_ptr<IncomingTCPConnectionState>& state): d_state(state)
   {
   }
 
@@ -581,13 +581,13 @@ public:
 
   void handleResponse(const struct timeval& now, TCPResponse&& response) override
   {
-    if (d_responseDesc == -1) {
+    if (d_state->d_threadData.crossProtocolResponsesPipe == -1) {
       throw std::runtime_error("Invalid pipe descriptor in TCP Cross Protocol Query Sender");
     }
 
     auto ptr = new TCPCrossProtocolResponse(std::move(response), d_state, now);
     static_assert(sizeof(ptr) <= PIPE_BUF, "Writes up to PIPE_BUF are guaranteed not to be interleaved and to either fully succeed or fail");
-    ssize_t sent = write(d_responseDesc, &ptr, sizeof(ptr));
+    ssize_t sent = write(d_state->d_threadData.crossProtocolResponsesPipe, &ptr, sizeof(ptr));
     if (sent != sizeof(ptr)) {
       if (errno == EAGAIN || errno == EWOULDBLOCK) {
         ++g_stats.tcpCrossProtocolResponsePipeFull;
@@ -613,7 +613,6 @@ public:
 
 private:
   std::shared_ptr<IncomingTCPConnectionState> d_state;
-  int d_responseDesc{-1};
 };
 
 class TCPCrossProtocolQuery : public CrossProtocolQuery
@@ -774,7 +773,7 @@ static void handleQuery(std::shared_ptr<IncomingTCPConnectionState>& state, cons
       proxyProtocolPayload = getProxyProtocolPayload(dq);
     }
 
-    auto incoming = std::make_shared<TCPCrossProtocolQuerySender>(state, state->d_threadData.crossProtocolResponsesPipe);
+    auto incoming = std::make_shared<TCPCrossProtocolQuerySender>(state);
     auto cpq = std::make_unique<TCPCrossProtocolQuery>(std::move(state->d_buffer), std::move(ids), ds, incoming);
     cpq->query.d_proxyProtocolPayload = std::move(proxyProtocolPayload);