Skip to content

Commit

Permalink
DelegateOpen, R{Bind,Connect}: use CoEnqueueSpawner and CoWaitSpawnCo…
Browse files Browse the repository at this point in the history
…mpletion
  • Loading branch information
MaxKellermann committed Jul 8, 2024
1 parent 9243d7a commit c2cd1eb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/DelegateOpen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "DelegateOpen.hxx"
#include "Connection.hxx"
#include "spawn/CoEnqueue.hxx"
#include "spawn/CoWaitSpawnCompletion.hxx"
#include "spawn/Interface.hxx"
#include "spawn/Prepared.hxx"
#include "spawn/ProcessHandle.hxx"
Expand Down Expand Up @@ -80,8 +82,14 @@ SendOpen(SocketDescriptor s, std::string_view path)
Co::Task<UniqueFileDescriptor>
DelegateOpen(const Connection &ssh_connection, std::string_view path)
{
/* throttle if the spawner is under pressure */
co_await CoEnqueueSpawner{ssh_connection.GetSpawnService()};

auto [control_socket, child_handle] = SpawnOpen(ssh_connection);

/* wait for spawner completion and rethrow errors */
co_await CoWaitSpawnCompletion{*child_handle};

SendOpen(control_socket, path);

co_await AwaitableSocketEvent(ssh_connection.GetEventLoop(),
Expand Down
8 changes: 8 additions & 0 deletions src/RBind.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ using std::string_view_literals::operator""sv;
#ifdef ENABLE_TRANSLATION

#include "translation/Response.hxx"
#include "spawn/CoEnqueue.hxx"
#include "spawn/CoWaitSpawnCompletion.hxx"
#include "spawn/ChildOptions.hxx"
#include "spawn/ProcessHandle.hxx"
#include "spawn/Prepared.hxx"
Expand Down Expand Up @@ -151,9 +153,15 @@ NsResolveBindTCP(EventLoop &event_loop,
SpawnService &spawn_service, const ChildOptions &options,
std::string_view host, const unsigned port)
{
/* throttle if the spawner is under pressure */
co_await CoEnqueueSpawner{spawn_service};

auto [control_socket, child_handle] =
SpawnNsResolveBindTCPFunction(spawn_service, options);

/* wait for spawner completion and rethrow errors */
co_await CoWaitSpawnCompletion{*child_handle};

co_return co_await SpawnResolveBind(event_loop, control_socket, host, port);
}

Expand Down
8 changes: 8 additions & 0 deletions src/RConnect.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifdef ENABLE_TRANSLATION

#include "translation/Response.hxx"
#include "spawn/CoEnqueue.hxx"
#include "spawn/CoWaitSpawnCompletion.hxx"
#include "spawn/ChildOptions.hxx"
#include "spawn/ProcessHandle.hxx"
#include "spawn/Prepared.hxx"
Expand Down Expand Up @@ -132,9 +134,15 @@ NsResolveConnectTCP(EventLoop &event_loop,
SpawnService &spawn_service, const ChildOptions &options,
std::string_view host, const unsigned port)
{
/* throttle if the spawner is under pressure */
co_await CoEnqueueSpawner{spawn_service};

auto [control_socket, child_handle] =
SpawnNsResolveConnectTCPFunction(spawn_service, options);

/* wait for spawner completion and rethrow errors */
co_await CoWaitSpawnCompletion{*child_handle};

co_return co_await SpawnResolveConnect(event_loop, control_socket, host, port);
}

Expand Down

0 comments on commit c2cd1eb

Please sign in to comment.