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 // Copyright (c) 2016 Klemens D. Morgenstern
0007 //
0008 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0009 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_PROCESS_WINDOWS_PIPE_OUT_HPP
0012 #define BOOST_PROCESS_WINDOWS_PIPE_OUT_HPP
0013 
0014 #include <boost/winapi/process.hpp>
0015 #include <boost/winapi/handles.hpp>
0016 #include <boost/process/detail/used_handles.hpp>
0017 #include <boost/process/detail/handler_base.hpp>
0018 #include <boost/system/error_code.hpp>
0019 
0020 
0021 namespace boost { namespace process { namespace detail { namespace windows {
0022 
0023 template<int p1, int p2>
0024 struct pipe_out : public ::boost::process::detail::handler_base, ::boost::process::detail::uses_handles
0025 {
0026     ::boost::winapi::HANDLE_ handle;
0027 
0028     ::boost::winapi::HANDLE_ get_used_handles() const { return handle; }
0029 
0030     pipe_out(::boost::winapi::HANDLE_ handle) : handle(handle) {}
0031     template<typename T>
0032     pipe_out(T & p) : handle(p.native_sink())
0033     {
0034         p.assign_sink(::boost::winapi::INVALID_HANDLE_VALUE_);
0035     }
0036 
0037     template<typename WindowsExecutor>
0038     void on_setup(WindowsExecutor &e) const;
0039 
0040     template<typename WindowsExecutor>
0041     void on_error(WindowsExecutor &, const std::error_code &) const
0042     {
0043         ::boost::winapi::CloseHandle(handle);
0044     }
0045 
0046     template<typename WindowsExecutor>
0047     void on_success(WindowsExecutor &) const
0048     {
0049         ::boost::winapi::CloseHandle(handle);
0050     }
0051 };
0052 
0053 template<>
0054 template<typename WindowsExecutor>
0055 void pipe_out<1,-1>::on_setup(WindowsExecutor &e) const
0056 {
0057     boost::winapi::SetHandleInformation(handle,
0058             boost::winapi::HANDLE_FLAG_INHERIT_,
0059             boost::winapi::HANDLE_FLAG_INHERIT_);
0060 
0061     e.startup_info.hStdOutput = handle;
0062     e.startup_info.dwFlags   |= ::boost::winapi::STARTF_USESTDHANDLES_;
0063     e.inherit_handles = true;
0064 }
0065 
0066 template<>
0067 template<typename WindowsExecutor>
0068 void pipe_out<2,-1>::on_setup(WindowsExecutor &e) const
0069 {
0070     boost::winapi::SetHandleInformation(handle,
0071             boost::winapi::HANDLE_FLAG_INHERIT_,
0072             boost::winapi::HANDLE_FLAG_INHERIT_);
0073 
0074 
0075     e.startup_info.hStdError = handle;
0076     e.startup_info.dwFlags  |= ::boost::winapi::STARTF_USESTDHANDLES_;
0077     e.inherit_handles = true;
0078 }
0079 
0080 template<>
0081 template<typename WindowsExecutor>
0082 void pipe_out<1,2>::on_setup(WindowsExecutor &e) const
0083 {
0084     boost::winapi::SetHandleInformation(handle,
0085             boost::winapi::HANDLE_FLAG_INHERIT_,
0086             boost::winapi::HANDLE_FLAG_INHERIT_);
0087 
0088     e.startup_info.hStdOutput = handle;
0089     e.startup_info.hStdError  = handle;
0090     e.startup_info.dwFlags   |= ::boost::winapi::STARTF_USESTDHANDLES_;
0091     e.inherit_handles = true;
0092 }
0093 
0094 template<int p1, int p2>
0095 struct async_pipe_out : public pipe_out<p1, p2>
0096 {
0097     async_pipe &pipe;
0098     template<typename AsyncPipe>
0099     async_pipe_out(AsyncPipe & p) : pipe_out<p1, p2>(p.native_sink()), pipe(p)
0100     {
0101     }
0102 
0103     template<typename Pipe, typename Executor>
0104     static void close(Pipe & pipe, Executor &)
0105     {
0106         boost::system::error_code ec;
0107         std::move(pipe).sink().close(ec);
0108     }
0109 
0110     template<typename Executor>
0111     void on_error(Executor & exec, const std::error_code &)
0112     {
0113         close(pipe, exec);
0114     }
0115 
0116     template<typename Executor>
0117     void on_success(Executor &exec)
0118     {
0119         close(pipe, exec);
0120     }
0121 };
0122 
0123 }}}}
0124 
0125 #endif