1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_PROCESS_POSIX_PIPE_IN_HPP
11 #define BOOST_PROCESS_POSIX_PIPE_IN_HPP
13 #include <boost/process/pipe.hpp>
14 #include <boost/process/detail/posix/handler.hpp>
16 #include <boost/process/detail/used_handles.hpp>
19 namespace boost { namespace process { namespace detail { namespace posix {
21 struct pipe_in : handler_base_ext, ::boost::process::detail::uses_handles
24 int sink; //opposite end
26 pipe_in(int sink, int source) : source(source), sink(sink) {}
28 std::array<int, 3> get_used_handles()
30 return {{STDIN_FILENO, source, sink}};
35 pipe_in(T & p) : source(p.native_source()), sink(p.native_sink())
40 template<typename Executor>
41 void on_error(Executor &, const std::error_code &) const
46 template<typename Executor>
47 void on_success(Executor &) const
52 template <class Executor>
53 void on_exec_setup(Executor &e) const
55 if (::dup2(source, STDIN_FILENO) == -1)
56 e.set_error(::boost::process::detail::get_last_error(), "dup2() failed");
57 if (source != STDIN_FILENO)
67 struct async_pipe_in : public pipe_in
71 template<typename AsyncPipe>
72 async_pipe_in(AsyncPipe & p) : pipe_in(p.native_sink(), p.native_source()), pipe(p)
76 template<typename Pipe, typename Executor>
77 static void close(Pipe & pipe, Executor &)
79 boost::system::error_code ec;
80 std::move(pipe).source().close(ec);
83 template<typename Executor>
84 void on_error(Executor & exec, const std::error_code &)
89 template<typename Executor>
90 void on_success(Executor &exec)