Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:58:04

0001 // Copyright (c) 2019 Klemens D. Morgenstern
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_PROCESS_HANDLES_HPP_
0007 #define BOOST_PROCESS_HANDLES_HPP_
0008 
0009 /**
0010  * \file boost/process/handles.hpp
0011  *
0012  * Defines functions to obtain handles of the current process and limit the amount for inherited ones.
0013  */
0014 
0015 #include <boost/process/detail/config.hpp>
0016 
0017 #if defined(BOOST_POSIX_API)
0018 #include <boost/process/detail/posix/handles.hpp>
0019 #elif defined(BOOST_WINDOWS_API)
0020 #include <boost/process/detail/windows/handles.hpp>
0021 #endif
0022 
0023 #include <boost/process/detail/used_handles.hpp>
0024 
0025 
0026 namespace boost { namespace this_process
0027 {
0028 
0029 ///The native type for handles
0030 using native_handle_type = ::boost::process::detail::api::native_handle_type;
0031 
0032 /**
0033  * Get a snapshot of all handles of the process (i.e. file descriptors on posix and handles on windows) of the current process.
0034  *
0035  * \note This function might not work on certain posix systems.
0036  *
0037  * \note On Windows version older than windows 8 this function will iterate all the system handles, meaning it might be quite slow.
0038  *
0039  * \warning This functionality is utterly prone to race conditions, since other threads might open or close handles.
0040  *
0041  * \return The list of all open handles of the current process
0042  */
0043 inline std::vector<native_handle_type> get_handles()
0044 {
0045     return ::boost::process::detail::api::get_handles();
0046 }
0047 
0048 
0049 /** \overload std::vector<native_handle_type> get_handles() */
0050 inline std::vector<native_handle_type> get_handles(std::error_code &ec)
0051 {
0052     return ::boost::process::detail::api::get_handles(ec);
0053 }
0054 
0055 /** Determines if a given handle is a a stream-handle, i.e. any handle that can be used with read and write functions.
0056  * Stream handles include pipes, regular files and sockets.
0057  *
0058  * \return Indicates if it's a stream handle.
0059  */
0060 inline bool is_stream_handle(native_handle_type handle)
0061 {
0062     return ::boost::process::detail::api::is_stream_handle(handle);
0063 }
0064 
0065 
0066 /** \overload bool is_stream_handle(native_handle_type handle) */
0067 inline bool is_stream_handle(native_handle_type handle, std::error_code &ec)
0068 {
0069     return ::boost::process::detail::api::is_stream_handle(handle, ec);
0070 }
0071 
0072 }
0073 namespace process
0074 {
0075 
0076 namespace detail
0077 {
0078 
0079 using limit_handles_ = ::boost::process::detail::api::limit_handles_;
0080 
0081 
0082 }
0083 
0084 /**
0085  * The limit_handles property sets all properties to be inherited only explicitly. It closes all unused file-descriptors on posix after the fork and
0086  * removes the inherit flags on windows.
0087  *
0088  * \note This is executed after the fork on posix.
0089  *
0090  * \code{.cpp}
0091  * system("gcc", limit_handles);
0092  * \endcode
0093  *
0094  * Since limit also closes the standard handles unless they are explicitly redirected they can be ignored by `limit_handles` in the following way.
0095  *
0096  * \code{.cpp}
0097  * system("gcc", limit_handles.allowStd())
0098  * \endcode
0099  *
0100 */
0101 const static ::boost::process::detail::api::limit_handles_ limit_handles;
0102 
0103 
0104 }
0105 }
0106 
0107 #endif //BOOST_PROCESS_HANDLES_HPP_