diff options
Diffstat (limited to 'boost/process/detail/posix/async_pipe.hpp')
-rw-r--r-- | boost/process/detail/posix/async_pipe.hpp | 83 |
1 files changed, 38 insertions, 45 deletions
diff --git a/boost/process/detail/posix/async_pipe.hpp b/boost/process/detail/posix/async_pipe.hpp index d849559c20..8f138bdfa3 100644 --- a/boost/process/detail/posix/async_pipe.hpp +++ b/boost/process/detail/posix/async_pipe.hpp @@ -11,6 +11,7 @@ #include <boost/asio/posix/stream_descriptor.hpp> #include <system_error> #include <string> +#include <utility> namespace boost { namespace process { namespace detail { namespace posix { @@ -22,10 +23,10 @@ public: typedef int native_handle_type; typedef ::boost::asio::posix::stream_descriptor handle_type; - inline async_pipe(boost::asio::io_service & ios) : async_pipe(ios, ios) {} + inline async_pipe(boost::asio::io_context & ios) : async_pipe(ios, ios) {} - inline async_pipe(boost::asio::io_service & ios_source, - boost::asio::io_service & ios_sink) : _source(ios_source), _sink(ios_sink) + inline async_pipe(boost::asio::io_context & ios_source, + boost::asio::io_context & ios_sink) : _source(ios_source), _sink(ios_sink) { int fds[2]; if (::pipe(fds) == -1) @@ -34,11 +35,11 @@ public: _source.assign(fds[0]); _sink .assign(fds[1]); }; - inline async_pipe(boost::asio::io_service & ios, const std::string & name) + inline async_pipe(boost::asio::io_context & ios, const std::string & name) : async_pipe(ios, ios, name) {} - inline async_pipe(boost::asio::io_service & ios_source, - boost::asio::io_service & io_sink, const std::string & name); + inline async_pipe(boost::asio::io_context & ios_source, + boost::asio::io_context & io_sink, const std::string & name); inline async_pipe(const async_pipe& lhs); async_pipe(async_pipe&& lhs) : _source(std::move(lhs._source)), _sink(std::move(lhs._sink)) { @@ -47,15 +48,15 @@ public: } template<class CharT, class Traits = std::char_traits<CharT>> - explicit async_pipe(::boost::asio::io_service & ios_source, - ::boost::asio::io_service & ios_sink, + explicit async_pipe(::boost::asio::io_context & ios_source, + ::boost::asio::io_context & ios_sink, const basic_pipe<CharT, Traits> & p) : _source(ios_source, p.native_source()), _sink(ios_sink, p.native_sink()) { } template<class CharT, class Traits = std::char_traits<CharT>> - explicit async_pipe(boost::asio::io_service & ios, const basic_pipe<CharT, Traits> & p) + explicit async_pipe(boost::asio::io_context & ios, const basic_pipe<CharT, Traits> & p) : async_pipe(ios, ios, p) { } @@ -68,10 +69,10 @@ public: ~async_pipe() { - if (_sink .native() != -1) - ::close(_sink.native()); - if (_source.native() != -1) - ::close(_source.native()); + if (_sink .native_handle() != -1) + ::close(_sink.native_handle()); + if (_source.native_handle() != -1) + ::close(_source.native_handle()); } template<class CharT, class Traits = std::char_traits<CharT>> @@ -108,9 +109,9 @@ public: void async_close() { if (_sink.is_open()) - _sink.get_io_service(). post([this]{_sink.close();}); + _sink.get_io_context(). post([this]{_sink.close();}); if (_source.is_open()) - _source.get_io_service().post([this]{_source.close();}); + _source.get_io_context().post([this]{_source.close();}); } template<typename MutableBufferSequence> @@ -124,8 +125,8 @@ public: return _sink.write_some(buffers); } - native_handle_type native_source() const {return const_cast<boost::asio::posix::stream_descriptor&>(_source).native();} - native_handle_type native_sink () const {return const_cast<boost::asio::posix::stream_descriptor&>(_sink ).native();} + native_handle_type native_source() const {return const_cast<boost::asio::posix::stream_descriptor&>(_source).native_handle();} + native_handle_type native_sink () const {return const_cast<boost::asio::posix::stream_descriptor&>(_sink ).native_handle();} template<typename MutableBufferSequence, typename ReadHandler> @@ -156,32 +157,32 @@ public: handle_type && sink() && { return std::move(_sink); } handle_type && source()&& { return std::move(_source); } - handle_type source(::boost::asio::io_service& ios) && + handle_type source(::boost::asio::io_context& ios) && { ::boost::asio::posix::stream_descriptor stolen(ios, _source.release()); return stolen; } - handle_type sink (::boost::asio::io_service& ios) && + handle_type sink (::boost::asio::io_context& ios) && { ::boost::asio::posix::stream_descriptor stolen(ios, _sink.release()); return stolen; } - handle_type source(::boost::asio::io_service& ios) const & + handle_type source(::boost::asio::io_context& ios) const & { - auto source_in = const_cast<::boost::asio::posix::stream_descriptor &>(_source).native(); + auto source_in = const_cast<::boost::asio::posix::stream_descriptor &>(_source).native_handle(); return ::boost::asio::posix::stream_descriptor(ios, ::dup(source_in)); } - handle_type sink (::boost::asio::io_service& ios) const & + handle_type sink (::boost::asio::io_context& ios) const & { - auto sink_in = const_cast<::boost::asio::posix::stream_descriptor &>(_sink).native(); + auto sink_in = const_cast<::boost::asio::posix::stream_descriptor &>(_sink).native_handle(); return ::boost::asio::posix::stream_descriptor(ios, ::dup(sink_in)); } }; -async_pipe::async_pipe(boost::asio::io_service & ios_source, - boost::asio::io_service & ios_sink, +async_pipe::async_pipe(boost::asio::io_context & ios_source, + boost::asio::io_context & ios_sink, const std::string & name) : _source(ios_source), _sink(ios_sink) { auto fifo = mkfifo(name.c_str(), 0666 ); @@ -205,19 +206,19 @@ async_pipe::async_pipe(boost::asio::io_service & ios_source, } async_pipe::async_pipe(const async_pipe & p) : - _source(const_cast<async_pipe&>(p)._source.get_io_service()), - _sink( const_cast<async_pipe&>(p)._sink.get_io_service()) + _source(const_cast<async_pipe&>(p)._source.get_io_context()), + _sink( const_cast<async_pipe&>(p)._sink.get_io_context()) { //cannot get the handle from a const object. - auto source_in = const_cast<::boost::asio::posix::stream_descriptor &>(_source).native(); - auto sink_in = const_cast<::boost::asio::posix::stream_descriptor &>(_sink).native(); + auto source_in = const_cast<::boost::asio::posix::stream_descriptor &>(_source).native_handle(); + auto sink_in = const_cast<::boost::asio::posix::stream_descriptor &>(_sink).native_handle(); if (source_in == -1) _source.assign(-1); else { _source.assign(::dup(source_in)); - if (_source.native()== -1) + if (_source.native_handle()== -1) ::boost::process::detail::throw_last_error("dup()"); } @@ -226,7 +227,7 @@ async_pipe::async_pipe(const async_pipe & p) : else { _sink.assign(::dup(sink_in)); - if (_sink.native() == -1) + if (_sink.native_handle() == -1) ::boost::process::detail::throw_last_error("dup()"); } } @@ -237,8 +238,8 @@ async_pipe& async_pipe::operator=(const async_pipe & p) int sink; //cannot get the handle from a const object. - auto source_in = const_cast<::boost::asio::posix::stream_descriptor &>(_source).native(); - auto sink_in = const_cast<::boost::asio::posix::stream_descriptor &>(_sink).native(); + auto source_in = const_cast<::boost::asio::posix::stream_descriptor &>(_source).native_handle(); + auto sink_in = const_cast<::boost::asio::posix::stream_descriptor &>(_sink).native_handle(); if (source_in == -1) source = -1; else @@ -264,16 +265,8 @@ async_pipe& async_pipe::operator=(const async_pipe & p) async_pipe& async_pipe::operator=(async_pipe && lhs) { - if (_source.native_handle() == -1) - ::close(_source.native()); - - if (_sink.native_handle() == -1) - ::close(_sink.native()); - - _source.assign(lhs._source.native_handle()); - _sink .assign(lhs._sink .native_handle()); - lhs._source.assign(-1); - lhs._sink .assign(-1); + std::swap(_source, lhs._source); + std::swap(_sink, lhs._sink); return *this; } @@ -284,8 +277,8 @@ async_pipe::operator basic_pipe<CharT, Traits>() const int sink; //cannot get the handle from a const object. - auto source_in = const_cast<::boost::asio::posix::stream_descriptor &>(_source).native(); - auto sink_in = const_cast<::boost::asio::posix::stream_descriptor &>(_sink).native(); + auto source_in = const_cast<::boost::asio::posix::stream_descriptor &>(_source).native_handle(); + auto sink_in = const_cast<::boost::asio::posix::stream_descriptor &>(_sink).native_handle(); if (source_in == -1) |