From: Remi Gacogne Date: Mon, 6 May 2024 12:41:06 +0000 (+0200) Subject: dnsdist: Simplify IncomingTCPConnectionState::updateIO() X-Git-Tag: rec-5.1.0-alpha1~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efe91151f98223ce70e155324d0e05fcd191a145;p=thirdparty%2Fpdns.git dnsdist: Simplify IncomingTCPConnectionState::updateIO() As suggested by Otto. --- diff --git a/pdns/dnsdistdist/dnsdist-nghttp2-in.cc b/pdns/dnsdistdist/dnsdist-nghttp2-in.cc index e54d7f2f27..302f31961e 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2-in.cc +++ b/pdns/dnsdistdist/dnsdist-nghttp2-in.cc @@ -1166,9 +1166,8 @@ boost::optional IncomingHTTP2Connection::getIdleClientReadTTD(st return now; } -void IncomingHTTP2Connection::updateIO(std::shared_ptr& 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); } diff --git a/pdns/dnsdistdist/dnsdist-nghttp2-in.hh b/pdns/dnsdistdist/dnsdist-nghttp2-in.hh index d6d16a6918..47b9575c0c 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2-in.hh +++ b/pdns/dnsdistdist/dnsdist-nghttp2-in.hh @@ -87,7 +87,7 @@ private: void stopIO(); uint32_t getConcurrentStreamsCount() const; - void updateIO(std::shared_ptr& 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); diff --git a/pdns/dnsdistdist/dnsdist-tcp-upstream.hh b/pdns/dnsdistdist/dnsdist-tcp-upstream.hh index ca2c11ad7c..51892f55ee 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-upstream.hh +++ b/pdns/dnsdistdist/dnsdist-tcp-upstream.hh @@ -131,7 +131,7 @@ public: static void updateIOForAsync(std::shared_ptr& conn); virtual void handleIO(); - virtual void updateIO(std::shared_ptr& conn, IOState newState, const timeval& now); + virtual void updateIO(IOState newState, const timeval& now); QueryProcessingResult handleQuery(PacketBuffer&& query, const struct timeval& now, std::optional streamID); virtual void handleResponse(const struct timeval& now, TCPResponse&& response) override; diff --git a/pdns/dnsdistdist/dnsdist-tcp.cc b/pdns/dnsdistdist/dnsdist-tcp.cc index 8cc1c6c206..da9bcf8587 100644 --- a/pdns/dnsdistdist/dnsdist-tcp.cc +++ b/pdns/dnsdistdist/dnsdist-tcp.cc @@ -398,7 +398,7 @@ void IncomingTCPConnectionState::queueResponse(std::shared_ptractive()) { - 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_ptrd_ioState->update(IOState::Done, handleIOCallback, conn); } -void IncomingTCPConnectionState::updateIO(std::shared_ptr& 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 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(); } }