Skip to content

Commit

Permalink
unified cancellation on process.async_wait()
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Oct 25, 2024
1 parent 7777db8 commit 1e41629
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/boost/process/v2/detail/process_handle_fd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ struct basic_process_handle_fd
template<typename Self>
void operator()(Self &&self)
{
self.reset_cancellation_state(asio::enable_total_cancellation());
error_code ec;
native_exit_code_type exit_code{};
int wait_res = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,15 @@ struct basic_process_handle_fd_or_signal
pid_type pid_;
bool needs_post = true;

template<typename Self.
void operator()(Self && self)
{
self.reset_cancellation_state(asio::enable_total_cancellation());
(*this)(std::move(self), error_code{});
}

template<typename Self>
void operator()(Self &&self, error_code ec = {}, int = 0)
void operator()(Self &&self, error_code ec, int = 0)
{
native_exit_code_type exit_code{};
int wait_res = -1;
Expand Down
1 change: 1 addition & 0 deletions include/boost/process/v2/detail/process_handle_signal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ struct basic_process_handle_signal
template<typename Self>
void operator()(Self &&self)
{
self.reset_cancellation_state(asio::enable_total_cancellation());
handle.async_wait(std::move(self));
handle.cancel();
// we cancel so we end up on the signal-sets executor
Expand Down
14 changes: 14 additions & 0 deletions include/boost/process/v2/detail/process_handle_windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,27 @@ struct basic_process_handle_win
template<typename Self>
void operator()(Self &&self)
{

self.reset_cancellation_state(asio::enable_total_cancellation());
auto sl = self.get_cancellation_state().slot();
auto & h = handle;
if (sl.is_connected())
sl.assign(
[&h](asio::cancellation_type ct)
{
boost::system::error_code ec;
h.cancel(ec);
});
handle.async_wait(std::move(self));
}

template<typename Self>
void operator()(Self &&self, error_code ec)
{
native_exit_code_type exit_code{};
if (ec == asio::error::operation_aborted && !self.get_cancellation_state().cancelled())
return handle.async_wait(std::move(self));

if (!ec)
detail::get_exit_code_(handle.native_handle(), exit_code, ec);
std::move(self).complete(ec, exit_code);
Expand Down

0 comments on commit 1e41629

Please sign in to comment.