Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:08

0001 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
0002 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
0003 // Copyright (c) 2009 Boris Schaeling
0004 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
0005 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 
0010 #ifndef BOOST_PROCESS_WINDOWS_INITIALIZERS_PIPE_IN_HPP
0011 #define BOOST_PROCESS_WINDOWS_INITIALIZERS_PIPE_IN_HPP
0012 
0013 #include <boost/winapi/process.hpp>
0014 #include <boost/winapi/handles.hpp>
0015 #include <boost/process/detail/used_handles.hpp>
0016 #include <boost/process/detail/handler_base.hpp>
0017 #include <boost/system/error_code.hpp>
0018 
0019 
0020 namespace boost { namespace process { namespace detail { namespace windows {
0021 
0022 struct pipe_in : public ::boost::process::detail::handler_base, ::boost::process::detail::uses_handles
0023 {
0024     ::boost::winapi::HANDLE_ handle;
0025 
0026     ::boost::winapi::HANDLE_ get_used_handles() const { return handle; }
0027 
0028     pipe_in(::boost::winapi::HANDLE_ handle) : handle(handle) {}
0029 
0030     template<typename T> //async_pipe
0031     pipe_in(T & p) : handle(p.native_source())
0032     {
0033         p.assign_source(::boost::winapi::INVALID_HANDLE_VALUE_);
0034     }
0035 
0036     template <class WindowsExecutor>
0037     void on_setup(WindowsExecutor &e) const
0038     {
0039         boost::winapi::SetHandleInformation(handle,
0040                 boost::winapi::HANDLE_FLAG_INHERIT_,
0041                 boost::winapi::HANDLE_FLAG_INHERIT_);
0042 
0043         e.startup_info.hStdInput = handle;
0044         e.startup_info.dwFlags  |= boost::winapi::STARTF_USESTDHANDLES_;
0045         e.inherit_handles = true;
0046     }
0047     template<typename WindowsExecutor>
0048     void on_error(WindowsExecutor &, const std::error_code &) const
0049     {
0050         ::boost::winapi::CloseHandle(handle);
0051     }
0052 
0053     template<typename WindowsExecutor>
0054     void on_success(WindowsExecutor &) const
0055     {
0056         ::boost::winapi::CloseHandle(handle);
0057     }
0058 };
0059 
0060 class async_pipe;
0061 
0062 struct async_pipe_in : public pipe_in
0063 {
0064     async_pipe &pipe;
0065 
0066     template<typename AsyncPipe>
0067     async_pipe_in(AsyncPipe & p) : pipe_in(p.native_source()), pipe(p)
0068     {
0069     }
0070 
0071     template<typename Pipe, typename Executor>
0072     static void close(Pipe & pipe, Executor &)
0073     {
0074         boost::system::error_code ec;
0075         std::move(pipe).source().close(ec);
0076     }
0077 
0078     template<typename Executor>
0079     void on_error(Executor & exec, const std::error_code &)
0080     {
0081         close(pipe, exec);
0082     }
0083 
0084     template<typename Executor>
0085     void on_success(Executor &exec)
0086     {
0087         close(pipe, exec);
0088     }
0089 };
0090 
0091 
0092 }}}}
0093 
0094 #endif