Skip to content

Commit

Permalink
was/Stock: fixups for the IdleConnection Open() change
Browse files Browse the repository at this point in the history
Commit 916a04a broke the build.  Oops!
  • Loading branch information
MaxKellermann committed Jan 16, 2025
1 parent 5e69e9d commit b23efee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/was/SConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include <cassert>

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
Expand Down
12 changes: 1 addition & 11 deletions src/was/SConnection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
56 changes: 18 additions & 38 deletions src/was/Stock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -58,31 +60,6 @@ class WasChild final : public WasStockConnection, ExitListener {
return StringListContains(tag, '\0', other_tag);
}

/**
* Throws on error.
*/
void Launch(const CgiChildParams &params, 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);
}
Expand Down Expand Up @@ -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 */
Expand Down
8 changes: 2 additions & 6 deletions src/was/Stock.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b23efee

Please sign in to comment.