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_WINDOWS_INITIALIZERS_PIPE_IN_HPP
11 #define BOOST_PROCESS_WINDOWS_INITIALIZERS_PIPE_IN_HPP
13 #include <boost/winapi/process.hpp>
14 #include <boost/winapi/handles.hpp>
15 #include <boost/process/detail/handler_base.hpp>
17 namespace boost { namespace process { namespace detail { namespace windows {
19 struct pipe_in : public ::boost::process::detail::handler_base
21 ::boost::winapi::HANDLE_ handle;
23 pipe_in(::boost::winapi::HANDLE_ handle) : handle(handle) {}
25 template<typename T> //async_pipe
26 pipe_in(T & p) : handle(p.native_source())
28 p.assign_source(::boost::winapi::INVALID_HANDLE_VALUE_);
31 template <class WindowsExecutor>
32 void on_setup(WindowsExecutor &e) const
34 boost::winapi::SetHandleInformation(handle,
35 boost::winapi::HANDLE_FLAG_INHERIT_,
36 boost::winapi::HANDLE_FLAG_INHERIT_);
38 e.startup_info.hStdInput = handle;
39 e.startup_info.dwFlags |= boost::winapi::STARTF_USESTDHANDLES_;
40 e.inherit_handles = true;
42 template<typename WindowsExecutor>
43 void on_error(WindowsExecutor &, const std::error_code &) const
45 ::boost::winapi::CloseHandle(handle);
48 template<typename WindowsExecutor>
49 void on_success(WindowsExecutor &) const
51 ::boost::winapi::CloseHandle(handle);
57 struct async_pipe_in : public pipe_in
61 template<typename AsyncPipe>
62 async_pipe_in(AsyncPipe & p) : pipe_in(p.native_source()), pipe(p)
66 template<typename Pipe, typename Executor>
67 static void close(Pipe & pipe, Executor &)
69 boost::system::error_code ec;
70 std::move(pipe).source().close(ec);
73 template<typename Executor>
74 void on_error(Executor & exec, const std::error_code &)
79 template<typename Executor>
80 void on_success(Executor &exec)