]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Simplify IncomingTCPConnectionState::updateIO() 14130/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 6 May 2024 12:41:06 +0000 (14:41 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 6 May 2024 12:41:06 +0000 (14:41 +0200)
As suggested by Otto.

pdns/dnsdistdist/dnsdist-nghttp2-in.cc
pdns/dnsdistdist/dnsdist-nghttp2-in.hh
pdns/dnsdistdist/dnsdist-tcp-upstream.hh
pdns/dnsdistdist/dnsdist-tcp.cc

index e54d7f2f27f8324841604b06d5727beec8e19a76..302f31961e04c99496337692407baada23ed7784 100644 (file)
@@ -1166,9 +1166,8 @@ boost::optional<struct timeval> IncomingHTTP2Connection::getIdleClientReadTTD(st
   return now;
 }
 
-void IncomingHTTP2Connection::updateIO(std::shared_ptr<IncomingTCPConnectionState>& conn, IOState newState, const timeval& now)
+void IncomingHTTP2Connection::updateIO(IOState newState, const timeval& now)
 {
-  (void)conn;
   (void)now;
   updateIO(newState, newState == IOState::NeedWrite ? handleWritableIOCallback : handleReadableIOCallback);
 }
index d6d16a69186614f77a65242c64179b2a6b9c1c98..47b9575c0cddfb12890903b8d4606a14570bca77 100644 (file)
@@ -87,7 +87,7 @@ private:
 
   void stopIO();
   uint32_t getConcurrentStreamsCount() const;
-  void updateIO(std::shared_ptr<IncomingTCPConnectionState>& conn, IOState newState, const timeval& now) override;
+  void updateIO(IOState newState, const timeval& now) override;
   void updateIO(IOState newState, const FDMultiplexer::callbackfunc_t& callback);
   void handleIOError();
   bool sendResponse(StreamID streamID, PendingQuery& context, uint16_t responseCode, const HeadersMap& customResponseHeaders, const std::string& contentType = "", bool addContentType = true);
index ca2c11ad7c0c513611c42d89c0f7f962d3089010..51892f55ee18c434f399c855fa52d63076c1dceb 100644 (file)
@@ -131,7 +131,7 @@ public:
   static void updateIOForAsync(std::shared_ptr<IncomingTCPConnectionState>& conn);
 
   virtual void handleIO();
-  virtual void updateIO(std::shared_ptr<IncomingTCPConnectionState>& conn, IOState newState, const timeval& now);
+  virtual void updateIO(IOState newState, const timeval& now);
 
   QueryProcessingResult handleQuery(PacketBuffer&& query, const struct timeval& now, std::optional<int32_t> streamID);
   virtual void handleResponse(const struct timeval& now, TCPResponse&& response) override;
index 8cc1c6c2062275349a118bcad0237fb97a65fc6b..da9bcf85875a663b12fd3cc6ab86d0a22fc9c73c 100644 (file)
@@ -398,7 +398,7 @@ void IncomingTCPConnectionState::queueResponse(std::shared_ptr<IncomingTCPConnec
 
     // for the same reason we need to update the state right away, nobody will do that for us
     if (state->active()) {
-      state->updateIO(state, iostate, now);
+      state->updateIO(iostate, now);
       // if we have not finished reading every available byte, we _need_ to do an actual read
       // attempt before waiting for the socket to become readable again, because if there is
       // buffered data available the socket might never become readable again.
@@ -449,14 +449,15 @@ void IncomingTCPConnectionState::updateIOForAsync(std::shared_ptr<IncomingTCPCon
   conn->d_ioState->update(IOState::Done, handleIOCallback, conn);
 }
 
-void IncomingTCPConnectionState::updateIO(std::shared_ptr<IncomingTCPConnectionState>& state, IOState newState, const struct timeval& now)
+void IncomingTCPConnectionState::updateIO(IOState newState, const struct timeval& now)
 {
+  auto sharedPtrToConn = shared_from_this();
   if (newState == IOState::Async) {
-    updateIOForAsync(state);
+    updateIOForAsync(sharedPtrToConn);
     return;
   }
 
-  state->d_ioState->update(newState, handleIOCallback, state, newState == IOState::NeedWrite ? state->getClientWriteTTD(now) : state->getClientReadTTD(now));
+  d_ioState->update(newState, handleIOCallback, sharedPtrToConn, newState == IOState::NeedWrite ? getClientWriteTTD(now) : getClientReadTTD(now));
 }
 
 /* called from the backend code when a new response has been received */
@@ -1171,12 +1172,12 @@ void IncomingTCPConnectionState::handleIO()
       return;
     }
 
-    auto state = shared_from_this();
+    auto sharedPtrToConn = shared_from_this();
     if (iostate == IOState::Done) {
-      d_ioState->update(iostate, handleIOCallback, state);
+      d_ioState->update(iostate, handleIOCallback, sharedPtrToConn);
     }
     else {
-      updateIO(state, iostate, now);
+      updateIO(iostate, now);
     }
     ioGuard.release();
   } while ((iostate == IOState::NeedRead || iostate == IOState::NeedWrite) && !d_lastIOBlocked);
@@ -1191,21 +1192,21 @@ void IncomingTCPConnectionState::notifyIOError(const struct timeval& now, TCPRes
     return;
   }
 
-  std::shared_ptr<IncomingTCPConnectionState> state = shared_from_this();
-  --state->d_currentQueriesCount;
-  state->d_hadErrors = true;
+  auto sharedPtrToConn = shared_from_this();
+  --sharedPtrToConn->d_currentQueriesCount;
+  sharedPtrToConn->d_hadErrors = true;
 
-  if (state->d_state == State::sendingResponse) {
+  if (sharedPtrToConn->d_state == State::sendingResponse) {
     /* if we have responses to send, let's do that first */
   }
-  else if (!state->d_queuedResponses.empty()) {
+  else if (!sharedPtrToConn->d_queuedResponses.empty()) {
     /* stop reading and send what we have */
     try {
-      auto iostate = sendQueuedResponses(state, now);
+      auto iostate = sendQueuedResponses(sharedPtrToConn, now);
 
-      if (state->active() && iostate != IOState::Done) {
+      if (sharedPtrToConn->active() && iostate != IOState::Done) {
         // we need to update the state right away, nobody will do that for us
-        updateIO(state, iostate, now);
+        updateIO(iostate, now);
       }
     }
     catch (const std::exception& e) {
@@ -1214,7 +1215,7 @@ void IncomingTCPConnectionState::notifyIOError(const struct timeval& now, TCPRes
   }
   else {
     // the backend code already tried to reconnect if it was possible
-    state->terminateClientConnection();
+    sharedPtrToConn->terminateClientConnection();
   }
 }