![]() |
|
|||
File indexing completed on 2025-04-19 08:44:21
0001 /* 0002 * Distributed under the Boost Software License, Version 1.0. 0003 * (See accompanying file LICENSE_1_0.txt or copy at 0004 * https://www.boost.org/LICENSE_1_0.txt) 0005 * 0006 * Copyright (c) 2023 Andrey Semashev 0007 */ 0008 /*! 0009 * \file scope/fd_deleter.hpp 0010 * 0011 * This header contains definition of a deleter function object for 0012 * POSIX-like file descriptors for use with \c unique_resource. 0013 */ 0014 0015 #ifndef BOOST_SCOPE_FD_DELETER_HPP_INCLUDED_ 0016 #define BOOST_SCOPE_FD_DELETER_HPP_INCLUDED_ 0017 0018 #include <boost/scope/detail/config.hpp> 0019 0020 #if !defined(BOOST_WINDOWS) 0021 #include <unistd.h> 0022 #if defined(hpux) || defined(_hpux) || defined(__hpux) 0023 #include <cerrno> 0024 #endif 0025 #else // !defined(BOOST_WINDOWS) 0026 #include <io.h> 0027 #endif // !defined(BOOST_WINDOWS) 0028 0029 #include <boost/scope/detail/header.hpp> 0030 0031 #ifdef BOOST_HAS_PRAGMA_ONCE 0032 #pragma once 0033 #endif 0034 0035 namespace boost { 0036 namespace scope { 0037 0038 //! POSIX-like file descriptor deleter 0039 struct fd_deleter 0040 { 0041 using result_type = void; 0042 0043 //! Closes the file descriptor 0044 result_type operator() (int fd) const noexcept 0045 { 0046 #if !defined(BOOST_WINDOWS) 0047 #if defined(hpux) || defined(_hpux) || defined(__hpux) 0048 // Some systems don't close the file descriptor in case if the thread is interrupted by a signal and close(2) returns EINTR. 0049 // Other (most) systems do close the file descriptor even when when close(2) returns EINTR, and attempting to close it 0050 // again could close a different file descriptor that was opened by a different thread. 0051 // 0052 // Future POSIX standards will likely fix this by introducing posix_close (see https://www.austingroupbugs.net/view.php?id=529) 0053 // and prohibiting returning EINTR from close(2), but we still have to support older systems where this new behavior is not available and close(2) 0054 // behaves differently between systems. 0055 int res; 0056 while (true) 0057 { 0058 res = ::close(fd); 0059 if (BOOST_UNLIKELY(res < 0)) 0060 { 0061 int err = errno; 0062 if (err == EINTR) 0063 continue; 0064 } 0065 0066 break; 0067 } 0068 #else 0069 ::close(fd); 0070 #endif 0071 #else // !defined(BOOST_WINDOWS) 0072 ::_close(fd); 0073 #endif // !defined(BOOST_WINDOWS) 0074 } 0075 }; 0076 0077 } // namespace scope 0078 } // namespace boost 0079 0080 #include <boost/scope/detail/footer.hpp> 0081 0082 #endif // BOOST_SCOPE_FD_DELETER_HPP_INCLUDED_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |