From b5c87084afaef42b2d058f68091be31988a6a874 Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Wed, 13 Sep 2017 11:08:07 +0900 Subject: Imported Upstream version 1.64.0 Change-Id: Id9212edd016dd55f21172c427aa7894d1d24148b Signed-off-by: DongHun Kwak --- boost/process/detail/posix/async_in.hpp | 95 +++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 boost/process/detail/posix/async_in.hpp (limited to 'boost/process/detail/posix/async_in.hpp') diff --git a/boost/process/detail/posix/async_in.hpp b/boost/process/detail/posix/async_in.hpp new file mode 100644 index 0000000000..9814c593f2 --- /dev/null +++ b/boost/process/detail/posix/async_in.hpp @@ -0,0 +1,95 @@ +// Copyright (c) 2006, 2007 Julio M. Merino Vidal +// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling +// Copyright (c) 2009 Boris Schaeling +// Copyright (c) 2010 Felipe Tanus, Boris Schaeling +// Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_PROCESS_DETAIL_POSIX_ASYNC_IN_HPP +#define BOOST_PROCESS_DETAIL_POSIX_ASYNC_IN_HPP + +#include +#include +#include +#include +#include +#include + +namespace boost { namespace process { namespace detail { namespace posix { + + +template +struct async_in_buffer : ::boost::process::detail::posix::handler_base_ext, + ::boost::process::detail::posix::require_io_service +{ + Buffer & buf; + + std::shared_ptr> promise; + async_in_buffer operator>(std::future & fut) + { + promise = std::make_shared>(); + fut = promise->get_future(); return std::move(*this); + } + + std::shared_ptr pipe; + + async_in_buffer(Buffer & buf) : buf(buf) + { + } + template + inline void on_success(Executor &exec) + { + auto pipe = this->pipe; + if (this->promise) + { + auto promise = this->promise; + + boost::asio::async_write(*pipe, buf, + [pipe, promise](const boost::system::error_code & ec, std::size_t) + { + if (ec && (ec.value() != EBADF) && (ec.value() != EPERM) && (ec.value() != ENOENT)) + { + std::error_code e(ec.value(), std::system_category()); + promise->set_exception(std::make_exception_ptr(process_error(e))); + } + else + promise->set_value(); + }); + } + else + boost::asio::async_write(*pipe, buf, + [pipe](const boost::system::error_code&ec, std::size_t size){}); + + std::move(*pipe).source().close(); + + this->pipe = nullptr; + } + + template + void on_error(Executor &, const std::error_code &) const + { + std::move(*pipe).source().close(); + } + + template + void on_setup(Executor & exec) + { + pipe = std::make_shared(get_io_service(exec.seq)); + } + + template + void on_exec_setup(Executor &exec) + { + if (::dup2(pipe->native_source(), STDIN_FILENO) == -1) + exec.set_error(::boost::process::detail::get_last_error(), "dup2() failed"); + + ::close(pipe->native_source()); + } +}; + + +}}}} + +#endif -- cgit v1.2.3