mirror of
https://github.com/boostorg/process.git
synced 2026-01-19 04:22:15 +00:00
added asnyc_close to async_pipe
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
|
||||
namespace boost { namespace process { namespace detail {
|
||||
|
||||
struct env_tag {};
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct env_set
|
||||
{
|
||||
@@ -147,19 +150,16 @@ auto build_env(boost::hana::tuple<> && e)
|
||||
}
|
||||
|
||||
template<class String>
|
||||
inline constexpr std:: true_type is_env_setter(const env_set<String>&) {return {};}
|
||||
inline constexpr env_tag initializer_tag(const env_set<String>&) {return {};}
|
||||
template<class String>
|
||||
inline constexpr std:: true_type is_env_setter(const env_append<String>&) {return {};}
|
||||
inline constexpr std:: true_type is_env_setter(const env_reset&) {return {};}
|
||||
inline constexpr env_tag initializer_tag(const env_append<String>&) {return {};}
|
||||
inline constexpr env_tag initializer_tag(const env_reset&) {return {};}
|
||||
|
||||
inline constexpr std:: true_type is_env_setter(const environment&) {return {};}
|
||||
inline constexpr std:: true_type is_env_setter(const wenvironment&) {return {};}
|
||||
inline constexpr env_tag initializer_tag(const environment&) {return {};}
|
||||
inline constexpr env_tag initializer_tag(const wenvironment&) {return {};}
|
||||
|
||||
inline constexpr std:: true_type is_env_setter(const empty_env&) {return {};}
|
||||
inline constexpr std:: true_type is_env_setter(const wempty_env&) {return {};}
|
||||
|
||||
template<typename T>
|
||||
inline constexpr std::false_type is_env_setter(const T &) {return {};}
|
||||
inline constexpr env_tag initializer_tag(const empty_env&) {return {};}
|
||||
inline constexpr env_tag initializer_tag(const wempty_env&) {return {};}
|
||||
|
||||
template<typename T>
|
||||
struct is_env_t : decltype(is_env_setter(T())) {};
|
||||
|
||||
@@ -125,7 +125,6 @@ struct std_out_
|
||||
api::async_out_buffer<p1, p2, asio::mutable_buffer> operator>(asio::mutable_buffer & buf) const {return buf;}
|
||||
api::async_out_buffer<p1, p2, asio::streambuf> operator>(asio::streambuf & os) const {return os ;}
|
||||
|
||||
|
||||
#if defined (BOOST_PROCESS_USE_FUTURE)
|
||||
api::async_out_future<p1,p2, std::string> operator=(std::future<std::string> & fut) const;
|
||||
api::async_out_future<p1,p2, std::string> operator>(std::future<std::string> & fut) const;
|
||||
|
||||
@@ -46,33 +46,14 @@ struct pipe
|
||||
|
||||
pipe() : pipe(boost::process::detail::api::pipe::create()) {}
|
||||
|
||||
pipe(const std::string & name) : pipe(native_pipe::create_named(name)) {}
|
||||
|
||||
pipe( pipe&&) = default;
|
||||
pipe(const pipe& ) = delete;
|
||||
|
||||
pipe& operator=( pipe&&) = default;
|
||||
pipe& operator=(const pipe& ) = delete;
|
||||
|
||||
static pipe create() { return pipe(native_pipe::create()); }
|
||||
static pipe create(std::error_code &ec) { return pipe(native_pipe::create(ec));}
|
||||
|
||||
static pipe create(const std::string & name) { return create_named(name); }
|
||||
static pipe create(const std::string & name, std::error_code &ec) { return create_named(name, ec);}
|
||||
|
||||
|
||||
inline static std::string make_pipe_name() {return native_pipe::make_pipe_name(); }
|
||||
|
||||
inline static pipe create_named(const std::string & name = make_pipe_name()) {return native_pipe::create_named(name);}
|
||||
inline static pipe create_named(const std::string & name, std::error_code & ec) {return native_pipe::create_named(name,ec);}
|
||||
|
||||
|
||||
inline static pipe create_named(std::error_code & ec) {return create_named(make_pipe_name(), ec);}
|
||||
|
||||
inline static pipe create_async() {return native_pipe::create_async(); }
|
||||
inline static pipe create_async(std::error_code & ec) {return native_pipe::create_async(ec); }
|
||||
|
||||
|
||||
|
||||
|
||||
std::streamsize read(char_type* s, std::streamsize n)
|
||||
{
|
||||
return _source.read(s, n);
|
||||
@@ -127,7 +108,13 @@ struct async_pipe : pipe
|
||||
{
|
||||
return _sink.is_open() || _source.is_open();
|
||||
}
|
||||
|
||||
void async_close()
|
||||
{
|
||||
if (_sink.is_open())
|
||||
_sink.get_io_service(). post([this]{_sink.close();});
|
||||
if (_source.is_open())
|
||||
_source.get_io_service().post([this]{_source.close();});
|
||||
}
|
||||
|
||||
|
||||
template<typename MutableBufferSequence>
|
||||
@@ -165,17 +152,32 @@ struct async_pipe : pipe
|
||||
}
|
||||
|
||||
boost::asio::io_service& get_io_service() {return *_ios;}
|
||||
async_pipe(boost::asio::io_service & ios) : _ios(&ios),
|
||||
async_pipe(boost::asio::io_service & ios) :
|
||||
pipe(native_pipe::create_async()),
|
||||
_ios(&ios),
|
||||
_sink (ios, pipe::sink(). handle()),
|
||||
_source(ios, pipe::source().handle())
|
||||
{}
|
||||
async_pipe(boost::asio::io_service & ios, const std::string & name) :
|
||||
pipe(name),
|
||||
_ios(&ios),
|
||||
_sink (ios, pipe::sink(). handle()),
|
||||
_source(ios, pipe::source().handle())
|
||||
{}
|
||||
async_pipe(const async_pipe &) = default;
|
||||
async_pipe(async_pipe &&) = default;
|
||||
|
||||
~async_pipe() {if (_destruction_notifier) _destruction_notifier->store(false);}
|
||||
async_pipe& operator=(const async_pipe &) = default;
|
||||
async_pipe& operator=(async_pipe &&) = default;
|
||||
|
||||
std::shared_ptr<std::atomic<bool>> make_destruction_notifier()
|
||||
{
|
||||
return _destruction_notifier = std::make_shared<std::atomic<bool>>(true);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::atomic<bool>> _destruction_notifier;
|
||||
boost::asio::io_service * _ios;
|
||||
native_async_handle _sink;
|
||||
native_async_handle _source;
|
||||
|
||||
@@ -65,8 +65,6 @@ void apply_out_handles(Executor &e, void* handle, std::integral_constant<int, 1>
|
||||
e.inherit_handles = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<int p1, int p2, typename Buffer>
|
||||
struct async_out_buffer : ::boost::process::detail::windows::async_handler
|
||||
{
|
||||
@@ -116,6 +114,8 @@ struct async_out_buffer : ::boost::process::detail::windows::async_handler
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#if defined (BOOST_PROCESS_USE_FUTURE)
|
||||
|
||||
template<int p1, int p2, typename Type>
|
||||
|
||||
Reference in New Issue
Block a user