![]() |
|
|||
File indexing completed on 2025-04-10 08:42:59
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/v1/detail/config.hpp> 0016 0017 #if defined(BOOST_POSIX_API) 0018 #include <boost/process/v1/detail/posix/handles.hpp> 0019 #elif defined(BOOST_WINDOWS_API) 0020 #include <boost/process/v1/detail/windows/handles.hpp> 0021 #endif 0022 0023 #include <boost/process/v1/detail/used_handles.hpp> 0024 0025 0026 namespace boost 0027 { 0028 namespace this_process 0029 { 0030 0031 ///The native type for handles 0032 using native_handle_type = ::boost::process::v1::detail::api::native_handle_type; 0033 0034 /** 0035 * Get a snapshot of all handles of the process (i.e. file descriptors on posix and handles on windows) of the current process. 0036 * 0037 * \note This function might not work on certain posix systems. 0038 * 0039 * \note On Windows version older than windows 8 this function will iterate all the system handles, meaning it might be quite slow. 0040 * 0041 * \warning This functionality is utterly prone to race conditions, since other threads might open or close handles. 0042 * 0043 * \return The list of all open handles of the current process 0044 */ 0045 inline std::vector <native_handle_type> get_handles() 0046 { 0047 return ::boost::process::v1::detail::api::get_handles(); 0048 } 0049 0050 0051 /** \overload std::vector<native_handle_type> get_handles() */ 0052 inline std::vector <native_handle_type> get_handles(std::error_code &ec) 0053 { 0054 return ::boost::process::v1::detail::api::get_handles(ec); 0055 } 0056 0057 /** Determines if a given handle is a a stream-handle, i.e. any handle that can be used with read and write functions. 0058 * Stream handles include pipes, regular files and sockets. 0059 * 0060 * \return Indicates if it's a stream handle. 0061 */ 0062 inline bool is_stream_handle(native_handle_type handle) 0063 { 0064 return ::boost::process::v1::detail::api::is_stream_handle(handle); 0065 } 0066 0067 0068 /** \overload bool is_stream_handle(native_handle_type handle) */ 0069 inline bool is_stream_handle(native_handle_type handle, std::error_code &ec) 0070 { 0071 return ::boost::process::v1::detail::api::is_stream_handle(handle, ec); 0072 } 0073 0074 } 0075 namespace process 0076 { 0077 BOOST_PROCESS_V1_INLINE 0078 namespace v1 0079 { 0080 0081 namespace detail 0082 { 0083 0084 using limit_handles_ = ::boost::process::v1::detail::api::limit_handles_; 0085 0086 0087 } 0088 0089 /** 0090 * The limit_handles property sets all properties to be inherited only explicitly. It closes all unused file-descriptors on posix after the fork and 0091 * removes the inherit flags on windows. 0092 * 0093 * \note This is executed after the fork on posix. 0094 * 0095 * \code{.cpp} 0096 * system("gcc", limit_handles); 0097 * \endcode 0098 * 0099 * Since limit also closes the standard handles unless they are explicitly redirected they can be ignored by `limit_handles` in the following way. 0100 * 0101 * \code{.cpp} 0102 * system("gcc", limit_handles.allowStd()) 0103 * \endcode 0104 * 0105 */ 0106 const static ::boost::process::v1::detail::api::limit_handles_ limit_handles; 0107 0108 0109 } 0110 } 0111 } 0112 0113 #endif //BOOST_PROCESS_HANDLES_HPP_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |