18 #ifndef PSTORE_OS_DESCRIPTOR_HPP 19 #define PSTORE_OS_DESCRIPTOR_HPP 25 # include <netinet/in.h> 29 # include <Winsock2.h> 30 using in_port_t =
unsigned short;
58 template <
typename DescriptorTraits>
61 using value_type =
typename DescriptorTraits::type;
62 using error_type =
typename DescriptorTraits::error_type;
64 #if defined(_WIN32) && defined(_MSC_VER) 67 static value_type
const invalid;
68 static error_type
const error;
70 static constexpr value_type invalid = DescriptorTraits::invalid;
71 static constexpr error_type error = DescriptorTraits::error;
75 DescriptorTraits
const traits = DescriptorTraits ()) noexcept
78 value_type
const fd, DescriptorTraits
const traits = DescriptorTraits ()) noexcept
83 , traits_{std::move (rhs.traits_)} {}
87 auto const err = errno;
97 traits_ = std::move (rhs.traits_);
102 bool operator== (
descriptor const & rhs)
const noexcept {
return fd_ == rhs.fd_; }
103 bool operator!= (
descriptor const & rhs)
const noexcept {
return !operator== (rhs); }
104 bool operator< (
descriptor const & rhs)
const noexcept {
return fd_ < rhs.fd_; }
106 bool valid ()
const noexcept {
return traits_.is_valid (fd_); }
107 value_type native_handle ()
const noexcept {
return fd_; }
109 value_type release () noexcept {
115 void reset (value_type r = invalid) noexcept {
123 value_type fd_ = invalid;
124 DescriptorTraits traits_;
127 #if defined(_WIN32) && defined(_MSC_VER) 128 template <
typename DescriptorTraits>
129 typename descriptor<DescriptorTraits>::value_type
const 132 template <
typename DescriptorTraits>
133 typename descriptor<DescriptorTraits>::error_type
const 137 template <
typename DescriptorTraits>
138 inline std::ostream & operator<< (std::ostream & os,
140 return os << fd.get ();
149 using error_type = type;
151 static constexpr
bool is_valid (type
const fd) noexcept {
return fd >= 0; }
152 static void close (type
const fd) noexcept { ::close (fd); }
154 static constexpr type
const invalid = -1;
155 static constexpr error_type
const error = -1;
163 class win32_socket_descriptor_traits {
166 using error_type = int;
168 static constexpr
bool is_valid (type
const fd) noexcept {
return fd != invalid; }
169 static void close (type
const fd) noexcept { ::closesocket (fd); }
171 static constexpr type
const invalid = INVALID_SOCKET;
172 static constexpr error_type
const error = SOCKET_ERROR;
176 class win32_pipe_descriptor_traits {
179 using error_type = type;
181 static constexpr
bool is_valid (type
const h) noexcept {
return h != invalid; }
182 static void close (type
const h) noexcept { ::CloseHandle (h); }
184 static type
const invalid;
185 static error_type
const error;
203 template <
typename DescriptorTraits>
204 struct hash<
pstore::details::descriptor<DescriptorTraits>> {
206 using result_type = std::size_t;
208 result_type operator() (argument_type
const & s)
const noexcept {
209 return std::hash<typename argument_type::value_type> () (s.native_handle ());
215 #endif // PSTORE_OS_DESCRIPTOR_HPP Definition: descriptor.hpp:146
Definition: chunked_sequence.hpp:607
DescriptorTraits is a traits structure of the following form:
Definition: descriptor.hpp:59
Definition: nonpod2.cpp:40