From b23efeea183199ada3310271cefc0d7748115b57 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 16 Jan 2025 09:31:54 +0100 Subject: [PATCH] was/Stock: fixups for the IdleConnection Open() change Commit 916a04a82164a04f84acb936021d4d97752a036c broke the build. Oops! --- src/was/SConnection.cxx | 4 +-- src/was/SConnection.hxx | 12 +-------- src/was/Stock.cxx | 56 +++++++++++++---------------------------- src/was/Stock.hxx | 8 ++---- 4 files changed, 23 insertions(+), 57 deletions(-) diff --git a/src/was/SConnection.cxx b/src/was/SConnection.cxx index dacfa8024..ce82eccfb 100644 --- a/src/was/SConnection.cxx +++ b/src/was/SConnection.cxx @@ -7,10 +7,10 @@ #include -WasStockConnection::WasStockConnection(CreateStockItem c) noexcept +WasStockConnection::WasStockConnection(CreateStockItem c, WasSocket &&_socket) noexcept :StockItem(c), logger(GetStockName()), - connection(c.stock.GetEventLoop(), *this) {} + connection(c.stock.GetEventLoop(), std::move(_socket), *this) {} void WasStockConnection::Stop(uint_least64_t _received) noexcept diff --git a/src/was/SConnection.hxx b/src/was/SConnection.hxx index 5ff4af3cf..cc396f6bd 100644 --- a/src/was/SConnection.hxx +++ b/src/was/SConnection.hxx @@ -16,13 +16,7 @@ class WasStockConnection WasIdleConnection connection; public: - explicit WasStockConnection(CreateStockItem c) noexcept; - - WasStockConnection(CreateStockItem c, WasSocket &&_socket) noexcept - :WasStockConnection(c) - { - Open(std::move(_socket)); - } + WasStockConnection(CreateStockItem c, WasSocket &&_socket) noexcept; auto &GetEventLoop() const noexcept { return connection.GetEventLoop(); @@ -43,10 +37,6 @@ public: virtual void SetUri([[maybe_unused]] const char *uri) noexcept {} protected: - void Open(WasSocket &&_socket) noexcept { - connection.Open(std::move(_socket)); - } - /* virtual methods from class StockItem */ bool Borrow() noexcept override; bool Release() noexcept override; diff --git a/src/was/Stock.cxx b/src/was/Stock.cxx index b0ff65b6b..d5a015757 100644 --- a/src/was/Stock.cxx +++ b/src/was/Stock.cxx @@ -29,8 +29,6 @@ WasStock::WasStockMap::GetLimit(const void *request, } class WasChild final : public WasStockConnection, ExitListener { - WasStock &was_stock; - const std::string tag; ChildErrorLog log; @@ -43,13 +41,17 @@ class WasChild final : public WasStockConnection, ExitListener { public: explicit WasChild(CreateStockItem c, - WasStock &_was_stock, + ChildErrorLog &&_log, + WasProcess &&process, std::string_view _tag, bool _disposable) noexcept - :WasStockConnection(c), - was_stock(_was_stock), + :WasStockConnection(c, std::move(process)), tag(_tag), + log(std::move(_log)), + handle(std::move(process.handle)), + listen_stream_lease(std::move(process.listen_stream_lease)), disposable(_disposable) { + handle->SetExitListener(*this); } ~WasChild() noexcept override; @@ -58,31 +60,6 @@ class WasChild final : public WasStockConnection, ExitListener { return StringListContains(tag, '\0', other_tag); } - /** - * Throws on error. - */ - void Launch(const CgiChildParams ¶ms, Net::Log::Sink *log_sink, - const ChildErrorLogOptions &log_options) { - auto process = - was_launch(was_stock.GetSpawnService(), - was_stock.GetListenStreamStock(), - GetStockName(), - params.executable_path, - params.args, - params.options, - log.EnableClient(GetEventLoop(), - log_sink, log_options, - params.options.stderr_pond)); - - handle = std::move(process.handle); - handle->SetExitListener(*this); - - listen_stream_lease = std::move(process.listen_stream_lease); - - WasSocket &socket = process; - Open(std::move(socket)); - } - void SetSite(const char *_site) noexcept override { log.SetSite(_site); } @@ -127,14 +104,17 @@ WasStock::Create(CreateStockItem c, StockRequest _request, assert(params.executable_path != nullptr); - auto *child = new WasChild(c, *this, params.options.tag, params.disposable); - - try { - child->Launch(params, log_sink, log_options); - } catch (...) { - delete child; - throw; - } + ChildErrorLog log; + auto process = was_launch(spawn_service, listen_stream_stock, + c.GetStockName(), + params.executable_path, + params.args, + params.options, + log.EnableClient(GetEventLoop(), + log_sink, log_options, + params.options.stderr_pond)); + + auto *child = new WasChild(c, std::move(log), std::move(process), params.options.tag, params.disposable); /* invoke the CgiChildParams destructor before invoking the callback, because the latter may destroy the pool */ diff --git a/src/was/Stock.hxx b/src/was/Stock.hxx index 6ed7d3aee..4bb32f064 100644 --- a/src/was/Stock.hxx +++ b/src/was/Stock.hxx @@ -51,12 +51,8 @@ public: stock(event_loop, *this, limit, max_idle, std::chrono::minutes(10)) {} - auto &GetSpawnService() const noexcept { - return spawn_service; - } - - auto *GetListenStreamStock() const noexcept { - return listen_stream_stock; + auto &GetEventLoop() const noexcept { + return stock.GetEventLoop(); } void FadeAll() noexcept {