From: Oguzhan Ozmen Date: Wed, 24 Jun 2026 01:48:05 +0000 (+0000) Subject: rgw/beast: (non-functional) refactor Connection and ConnectionList to header X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=222a39366d27aaadf2c96a33b8a29275f233afab;p=ceph.git rgw/beast: (non-functional) refactor Connection and ConnectionList to header Just like rgw_asio_frontend_timer.h, factor out the Connection struct and ConnectionList class from the anonymous namespace in rgw_asio_frontend.cc to a new header rgw_asio_frontend_connection.h (under namespace rgw::asio). This is especially needed to get better coverage thru unittesting. This is non-functional: no logic changes, the types, methods, and behavior are identical as before. The frontend .cc uses type aliases to maintain the same unqualified names. Signed-off-by: Oguzhan Ozmen --- diff --git a/src/rgw/rgw_asio_frontend.cc b/src/rgw/rgw_asio_frontend.cc index 694eb88c544b..8148001ef3c1 100644 --- a/src/rgw/rgw_asio_frontend.cc +++ b/src/rgw/rgw_asio_frontend.cc @@ -44,6 +44,7 @@ #include "rgw_zone.h" +#include "rgw_asio_frontend_connection.h" #include "rgw_asio_frontend_timer.h" #include "rgw_dmclock_async_scheduler.h" @@ -57,13 +58,11 @@ namespace http = boost::beast::http; namespace ssl = boost::asio::ssl; #endif -struct Connection; - using timeout_timer = rgw::basic_timeout_timer; + boost::asio::any_io_executor, rgw::asio::Connection>; -static constexpr size_t parse_buffer_size = 65536; -using parse_buffer = boost::beast::flat_static_buffer; +static constexpr size_t parse_buffer_size = rgw::asio::parse_buffer_size; +using parse_buffer = rgw::asio::parse_buffer; // use mmap/mprotect to allocate 512k coroutine stacks auto make_stack_allocator() { @@ -407,56 +406,8 @@ void handle_connection(boost::asio::io_context& context, } } -// timeout support requires that connections are reference-counted, because the -// timeout_handler can outlive the coroutine -struct Connection : boost::intrusive::list_base_hook<>, - boost::intrusive_ref_counter -{ - tcp::socket socket; - parse_buffer buffer; - - explicit Connection(tcp::socket&& socket) noexcept - : socket(std::move(socket)) {} - - void close(boost::system::error_code& ec) { - socket.close(ec); - } - - tcp::socket& get_socket() { return socket; } -}; - -class ConnectionList { - using List = boost::intrusive::list; - List connections; - std::mutex mutex; - - void remove(Connection& c) { - std::lock_guard lock{mutex}; - if (c.is_linked()) { - connections.erase(List::s_iterator_to(c)); - } - } - public: - class Guard { - ConnectionList *list; - Connection *conn; - public: - Guard(ConnectionList *list, Connection *conn) : list(list), conn(conn) {} - ~Guard() { list->remove(*conn); } - }; - [[nodiscard]] Guard add(Connection& conn) { - std::lock_guard lock{mutex}; - connections.push_back(conn); - return Guard{this, &conn}; - } - void close(boost::system::error_code& ec) { - std::lock_guard lock{mutex}; - for (auto& conn : connections) { - conn.socket.close(ec); - } - connections.clear(); - } -}; +using rgw::asio::Connection; +using rgw::asio::ConnectionList; namespace dmc = rgw::dmclock; class AsioFrontend { diff --git a/src/rgw/rgw_asio_frontend_connection.h b/src/rgw/rgw_asio_frontend_connection.h new file mode 100644 index 000000000000..56d5e233d0be --- /dev/null +++ b/src/rgw/rgw_asio_frontend_connection.h @@ -0,0 +1,68 @@ +#pragma once + +#include + +#include +#include +#include +#include + +namespace rgw::asio { + +using tcp = boost::asio::ip::tcp; + +static constexpr size_t parse_buffer_size = 65536; +using parse_buffer = boost::beast::flat_static_buffer; + +// timeout support requires that connections are reference-counted, because the +// timeout_handler can outlive the coroutine +struct Connection : boost::intrusive::list_base_hook<>, + boost::intrusive_ref_counter +{ + tcp::socket socket; + parse_buffer buffer; + + explicit Connection(tcp::socket&& socket) noexcept + : socket(std::move(socket)) {} + + void close(boost::system::error_code& ec) { + socket.close(ec); + } + + tcp::socket& get_socket() { return socket; } +}; + +class ConnectionList { + using List = boost::intrusive::list; + List connections; + std::mutex mutex; + + void remove(Connection& c) { + std::lock_guard lock{mutex}; + if (c.is_linked()) { + connections.erase(List::s_iterator_to(c)); + } + } + public: + class Guard { + ConnectionList *list; + Connection *conn; + public: + Guard(ConnectionList *list, Connection *conn) : list(list), conn(conn) {} + ~Guard() { list->remove(*conn); } + }; + [[nodiscard]] Guard add(Connection& conn) { + std::lock_guard lock{mutex}; + connections.push_back(conn); + return Guard{this, &conn}; + } + void close(boost::system::error_code& ec) { + std::lock_guard lock{mutex}; + for (auto& conn : connections) { + conn.socket.close(ec); + } + connections.clear(); + } +}; + +} // namespace rgw::asio