Skip to content

Commit

Permalink
reduced asio related macro usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Oct 30, 2024
1 parent f218a6a commit e827d14
Show file tree
Hide file tree
Showing 19 changed files with 238 additions and 234 deletions.
24 changes: 12 additions & 12 deletions include/boost/process/v2/bind_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct bound_launcher
template<typename ExecutionContext, typename Args, typename ... Inits>
auto operator()(ExecutionContext & context,
const typename std::enable_if<std::is_convertible<
ExecutionContext&, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
ExecutionContext&, net::execution_context&>::value,
filesystem::path >::type & executable,
Args && args,
Inits && ... inits) -> basic_process<typename ExecutionContext::executor_type>
Expand All @@ -88,7 +88,7 @@ struct bound_launcher
auto operator()(ExecutionContext & context,
error_code & ec,
const typename std::enable_if<std::is_convertible<
ExecutionContext&, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
ExecutionContext&, net::execution_context&>::value,
filesystem::path >::type & executable,
Args && args,
Inits && ... inits ) -> basic_process<typename ExecutionContext::executor_type>
Expand All @@ -103,8 +103,8 @@ struct bound_launcher
template<typename Executor, typename Args, typename ... Inits>
auto operator()(Executor exec,
const typename std::enable_if<
BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor<Executor>::value ||
BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor<Executor>::value,
net::execution::is_executor<Executor>::value ||
net::is_executor<Executor>::value,
filesystem::path >::type & executable,
Args && args,
Inits && ... inits ) -> basic_process<Executor>
Expand All @@ -120,8 +120,8 @@ struct bound_launcher
auto operator()(Executor exec,
error_code & ec,
const typename std::enable_if<
BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor<Executor>::value ||
BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor<Executor>::value,
net::execution::is_executor<Executor>::value ||
net::is_executor<Executor>::value,
filesystem::path >::type & executable,
Args && args,
Inits && ... inits ) -> basic_process<Executor>
Expand All @@ -138,7 +138,7 @@ struct bound_launcher
auto invoke(detail::index_sequence<Idx...>,
ExecutionContext & context,
const typename std::enable_if<std::is_convertible<
ExecutionContext&, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
ExecutionContext&, net::execution_context&>::value,
filesystem::path >::type & executable,
Args && args,
Inits && ... inits) -> basic_process<typename ExecutionContext::executor_type>
Expand All @@ -156,7 +156,7 @@ struct bound_launcher
ExecutionContext & context,
error_code & ec,
const typename std::enable_if<std::is_convertible<
ExecutionContext&, BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
ExecutionContext&, net::execution_context&>::value,
filesystem::path >::type & executable,
Args && args,
Inits && ... inits ) -> basic_process<typename ExecutionContext::executor_type>
Expand All @@ -172,8 +172,8 @@ struct bound_launcher
auto invoke(detail::index_sequence<Idx...>,
Executor exec,
const typename std::enable_if<
BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor<Executor>::value ||
BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor<Executor>::value,
net::execution::is_executor<Executor>::value ||
net::is_executor<Executor>::value,
filesystem::path >::type & executable,
Args && args,
Inits && ... inits ) -> basic_process<Executor>
Expand All @@ -190,8 +190,8 @@ struct bound_launcher
Executor exec,
error_code & ec,
const typename std::enable_if<
BOOST_PROCESS_V2_ASIO_NAMESPACE::execution::is_executor<Executor>::value ||
BOOST_PROCESS_V2_ASIO_NAMESPACE::is_executor<Executor>::value,
net::execution::is_executor<Executor>::value ||
net::is_executor<Executor>::value,
filesystem::path >::type & executable,
Args && args,
Inits && ... inits ) -> basic_process<Executor>
Expand Down
21 changes: 11 additions & 10 deletions include/boost/process/v2/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

#if defined(BOOST_PROCESS_V2_STANDALONE)

#define BOOST_PROCESS_V2_ASIO_NAMESPACE asio

#define BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(Sig) ASIO_COMPLETION_TOKEN_FOR(Sig)
#define BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN_TYPE(Executor) ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)
#define BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(Token, Signature) ASIO_INITFN_AUTO_RESULT_TYPE(Token, Signature)
#define BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN(Executor) ASIO_DEFAULT_COMPLETION_TOKEN(Executor)
#define BOOST_PROCESS_V2_INITFN_DEDUCED_RESULT_TYPE(x,y,z) ASIO_INITFN_DEDUCED_RESULT_TYPE(x,y,z)

#include <asio/detail/config.hpp>
#include <system_error>
Expand All @@ -38,14 +34,14 @@
#define BOOST_PROCESS_V2_END_NAMESPACE }
#define BOOST_PROCESS_V2_NAMESPACE process_v2

namespace asio {}
BOOST_PROCESS_V2_BEGIN_NAMESPACE
namespace net = ::asio;
BOOST_PROCESS_V2_END_NAMESPACE

#else

#define BOOST_PROCESS_V2_ASIO_NAMESPACE boost::asio
#define BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(Sig) BOOST_ASIO_COMPLETION_TOKEN_FOR(Sig)
#define BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN_TYPE(Executor) BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)
#define BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(Token, Signature) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(Token, Signature)
#define BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN(Executor) BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor)
#define BOOST_PROCESS_V2_INITFN_DEDUCED_RESULT_TYPE(x,y,z) BOOST_ASIO_INITFN_DEDUCED_RESULT_TYPE(x,y,z)

#include <boost/config.hpp>
#include <boost/io/quoted.hpp>
Expand Down Expand Up @@ -94,6 +90,11 @@
#define BOOST_PROCESS_V2_END_NAMESPACE } } }
#define BOOST_PROCESS_V2_NAMESPACE boost::process::v2

namespace boost { namespace asio {} }
BOOST_PROCESS_V2_BEGIN_NAMESPACE
namespace net = ::boost::asio;
BOOST_PROCESS_V2_END_NAMESPACE

#endif

BOOST_PROCESS_V2_BEGIN_NAMESPACE
Expand Down
37 changes: 19 additions & 18 deletions include/boost/process/v2/detail/process_handle_fd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE
namespace detail
{

template<typename Executor = BOOST_PROCESS_V2_ASIO_NAMESPACE::any_io_executor>
template<typename Executor = net::any_io_executor>
struct basic_process_handle_fd
{
using native_handle_type = int;
Expand All @@ -56,7 +56,7 @@ struct basic_process_handle_fd
basic_process_handle_fd(ExecutionContext &context,
typename std::enable_if<
std::is_convertible<ExecutionContext &,
BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context &>::value>::type * = nullptr)
net::execution_context &>::value>::type * = nullptr)
: pid_(-1), descriptor_(context)
{
}
Expand Down Expand Up @@ -275,25 +275,16 @@ struct basic_process_handle_fd
return pid_ != -1;
}

template<BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(void(error_code, native_exit_code_type))
WaitHandler BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WaitHandler, void (error_code, native_exit_code_type))
async_wait(WaitHandler &&handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
{
return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose<WaitHandler, void(error_code, native_exit_code_type)>(
async_wait_op_{descriptor_, pid_}, handler, descriptor_);
}

private:
template<typename>
friend
struct basic_process_handle_fd;
pid_type pid_ = -1;
BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::basic_stream_descriptor<Executor> descriptor_;
net::posix::basic_stream_descriptor<Executor> descriptor_;

struct async_wait_op_
{
BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::basic_descriptor<Executor> &descriptor;
net::posix::basic_descriptor<Executor> &descriptor;
pid_type pid_;

template<typename Self>
Expand All @@ -304,7 +295,7 @@ struct basic_process_handle_fd
native_exit_code_type exit_code{};
int wait_res = -1;
if (pid_ <= 0) // error, complete early
ec = BOOST_PROCESS_V2_ASIO_NAMESPACE::error::bad_descriptor;
ec = net::error::bad_descriptor;
else
{
wait_res = ::waitpid(pid_, &exit_code, WNOHANG);
Expand All @@ -315,8 +306,7 @@ struct basic_process_handle_fd

if (!ec && (wait_res == 0))
{
descriptor.async_wait(
BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::descriptor_base::wait_read, std::move(self));
descriptor.async_wait(net::posix::descriptor_base::wait_read, std::move(self));
return;
}

Expand All @@ -331,8 +321,7 @@ struct basic_process_handle_fd
self.complete(ec, code);
}
};
BOOST_PROCESS_V2_ASIO_NAMESPACE::post(descriptor.get_executor(),
completer{ec, exit_code, std::move(self)});
net::post(descriptor.get_executor(), completer{ec, exit_code, std::move(self)});

}

Expand All @@ -346,6 +335,18 @@ struct basic_process_handle_fd
std::move(self).complete(ec, exit_code);
}
};
public:

template<BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(void(error_code, native_exit_code_type))
WaitHandler = net::default_completion_token_t<executor_type>>
auto async_wait(WaitHandler &&handler = net::default_completion_token_t<executor_type>())
-> decltype(net::async_compose<WaitHandler, void(error_code, native_exit_code_type)>(
async_wait_op_{descriptor_, pid_}, handler, descriptor_))
{
return net::async_compose<WaitHandler, void(error_code, native_exit_code_type)>(
async_wait_op_{descriptor_, pid_}, handler, descriptor_);
}

};
}

Expand Down
45 changes: 23 additions & 22 deletions include/boost/process/v2/detail/process_handle_fd_or_signal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ BOOST_PROCESS_V2_BEGIN_NAMESPACE
namespace detail
{

template<typename Executor = BOOST_PROCESS_V2_ASIO_NAMESPACE::any_io_executor>
template<typename Executor = net::any_io_executor>
struct basic_process_handle_fd_or_signal
{
using native_handle_type = int;
Expand All @@ -59,7 +59,7 @@ struct basic_process_handle_fd_or_signal
basic_process_handle_fd_or_signal(ExecutionContext &context,
typename std::enable_if<
std::is_convertible<ExecutionContext &,
BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context &>::value
net::execution_context &>::value
>::type * = nullptr)
: pid_(-1), descriptor_(context)
{
Expand All @@ -70,7 +70,7 @@ struct basic_process_handle_fd_or_signal
pid_type pid,
typename std::enable_if<
std::is_convertible<ExecutionContext &,
BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context &>::value
net::execution_context &>::value
>::type * = nullptr)
: pid_(pid), descriptor_(context)
{
Expand All @@ -81,7 +81,7 @@ struct basic_process_handle_fd_or_signal
pid_type pid, native_handle_type process_handle,
typename std::enable_if<
std::is_convertible<ExecutionContext &,
BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context &>::value
net::execution_context &>::value
>::type * = nullptr)
: pid_(pid), descriptor_(context, process_handle)
{
Expand Down Expand Up @@ -305,31 +305,22 @@ struct basic_process_handle_fd_or_signal
return pid_ != -1;
}

template<BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(void(error_code, int))
WaitHandler BOOST_PROCESS_V2_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WaitHandler, void (error_code, native_exit_code_type))
async_wait(WaitHandler &&handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
{
return BOOST_PROCESS_V2_ASIO_NAMESPACE::async_compose<WaitHandler, void(error_code, native_exit_code_type)>(
async_wait_op_{descriptor_, signal_set_, pid_}, handler, descriptor_);
}

private:
template<typename>
friend
struct basic_process_handle_fd_or_signal;
pid_type pid_ = -1;
BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::basic_stream_descriptor<Executor> descriptor_;
BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_signal_set<Executor> signal_set_{descriptor_.get_executor(), SIGCHLD};
net::posix::basic_stream_descriptor<Executor> descriptor_;
net::basic_signal_set<Executor> signal_set_{descriptor_.get_executor(), SIGCHLD};

struct async_wait_op_
{
BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::basic_descriptor<Executor> &descriptor;
BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_signal_set<Executor> &handle;
net::posix::basic_descriptor<Executor> &descriptor;
net::basic_signal_set<Executor> &handle;
pid_type pid_;
bool needs_post = true;

template<typename Self.
template<typename Self>
void operator()(Self && self)
{
self.reset_cancellation_state(asio::enable_total_cancellation());
Expand All @@ -342,7 +333,7 @@ struct basic_process_handle_fd_or_signal
native_exit_code_type exit_code{};
int wait_res = -1;
if (pid_ <= 0) // error, complete early
ec = BOOST_PROCESS_V2_ASIO_NAMESPACE::error::bad_descriptor;
ec = net::error::bad_descriptor;
else
{
wait_res = ::waitpid(pid_, &exit_code, WNOHANG);
Expand All @@ -355,7 +346,7 @@ struct basic_process_handle_fd_or_signal
needs_post = false;
if (descriptor.is_open())
descriptor.async_wait(
BOOST_PROCESS_V2_ASIO_NAMESPACE::posix::descriptor_base::wait_read,
net::posix::descriptor_base::wait_read,
std::move(self));
else
handle.async_wait(std::move(self));
Expand All @@ -377,12 +368,22 @@ struct basic_process_handle_fd_or_signal
const auto exec = self.get_executor();
completer cpl{ec, exit_code, std::move(self)};
if (needs_post)
BOOST_PROCESS_V2_ASIO_NAMESPACE::post(exec, std::move(cpl));
net::post(exec, std::move(cpl));
else
BOOST_PROCESS_V2_ASIO_NAMESPACE::dispatch(exec, std::move(cpl));
net::dispatch(exec, std::move(cpl));

}
};
public:
template<BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(void(error_code, int))
WaitHandler = net::default_completion_token_t<executor_type>>
auto async_wait(WaitHandler &&handler = net::default_completion_token_t<executor_type>())
-> decltype(net::async_compose<WaitHandler, void(error_code, native_exit_code_type)>(
async_wait_op_{descriptor_, signal_set_, pid_}, handler, descriptor_))
{
return net::async_compose<WaitHandler, void(error_code, native_exit_code_type)>(
async_wait_op_{descriptor_, signal_set_, pid_}, handler, descriptor_);
}
};
}

Expand Down
Loading

0 comments on commit e827d14

Please sign in to comment.