13 #ifndef __STOUT_OS_WINDOWS_FD_HPP__ 14 #define __STOUT_OS_WINDOWS_FD_HPP__ 23 #include <type_traits> 71 std::is_same<HANDLE, void*>::value,
72 "Expected `HANDLE` to be of type `void*`.");
76 overlapped_(overlapped),
77 iocp_(
std::make_shared<IOCPData>())
88 std::is_same<SOCKET, unsigned __int64>::value,
89 "Expected `SOCKET` to be of type `unsigned __int64`.");
91 : type_(
Type::SOCKET),
93 overlapped_(overlapped),
94 iocp_(
std::make_shared<IOCPData>())
108 }
else if (crt == 0) {
109 handle_ = ::GetStdHandle(STD_INPUT_HANDLE);
110 }
else if (crt == 1) {
111 handle_ = ::GetStdHandle(STD_OUTPUT_HANDLE);
112 }
else if (crt == 2) {
113 handle_ = ::GetStdHandle(STD_ERROR_HANDLE);
117 LOG(FATAL) <<
"Unexpected construction of `WindowsFD`";
142 return socket_ != INVALID_SOCKET;
159 return ::_open_osfhandle(reinterpret_cast<intptr_t>(
handle_), O_RDWR);
183 operator intptr_t()
const 186 return static_cast<intptr_t
>(
socket_);
211 synchronized (iocp_->lock) {
212 const HANDLE prev_handle = iocp_->handle;
213 if (prev_handle ==
nullptr) {
219 if (::CreateIoCompletionPort(fd_handle, target, key, 0) ==
nullptr) {
223 iocp_->handle = target;
231 synchronized (iocp_->lock) {
232 return iocp_->handle;
253 std::atomic_flag lock = ATOMIC_FLAG_INIT;
257 std::shared_ptr<IOCPData> iocp_;
266 int get_valid()
const 302 stream <<
"WindowsFD::Type::HANDLE";
306 stream <<
"WindowsFD::Type::SOCKET";
310 stream <<
"WindowsFD::Type::UNKNOWN";
319 stream << fd.
type() <<
"=";
322 stream << static_cast<HANDLE>(fd);
326 stream << static_cast<SOCKET>(fd);
344 return left < right.get_valid();
350 return left.get_valid() < right;
356 return left > right.get_valid();
362 return left.get_valid() > right;
368 return left <= right.get_valid();
374 return left.get_valid() <= right;
380 return left >= right.get_valid();
386 return left.get_valid() >= right;
392 return left == right.get_valid();
398 return left.get_valid() == right;
404 return left != right.get_valid();
410 return left.get_valid() != right;
430 switch (left.
type()) {
432 return static_cast<HANDLE>(left) == static_cast<HANDLE>(right);
435 return static_cast<SOCKET>(left) == static_cast<SOCKET>(right);
458 return std::hash<HANDLE>{}(
static_cast<HANDLE>(fd));
461 return std::hash<SOCKET>{}(
static_cast<SOCKET>(fd));
471 #endif // __STOUT_OS_WINDOWS_FD_HPP__
bool is_valid() const
Definition: fd.hpp:132
WindowsFD(SOCKET socket, bool overlapped=true)
Definition: fd.hpp:90
Type type() const
Definition: fd.hpp:189
SOCKET socket_
Definition: fd.hpp:242
WindowsFD(HANDLE handle, bool overlapped=false)
Definition: fd.hpp:73
Definition: error.hpp:108
Definition: type_utils.hpp:619
friend bool operator<=(int left, const WindowsFD &right)
Definition: fd.hpp:366
Definition: posix_signalhandler.hpp:23
WindowsFD()
Definition: fd.hpp:122
result_type operator()(const argument_type &fd) const noexcept
Definition: fd.hpp:454
Try< HANDLE > assign_iocp(HANDLE target, ULONG_PTR key) const
Definition: fd.hpp:209
friend bool operator==(int left, const WindowsFD &right)
Definition: fd.hpp:390
Type
Definition: fd.hpp:55
WindowsFD(int crt)
Definition: fd.hpp:104
friend bool operator!=(int left, const WindowsFD &right)
Definition: fd.hpp:402
friend bool operator<(int left, const WindowsFD &right)
Definition: fd.hpp:342
#define UNREACHABLE()
Definition: unreachable.hpp:22
int crt() const
Definition: fd.hpp:155
friend bool operator>(int left, const WindowsFD &right)
Definition: fd.hpp:354
bool is_overlapped() const
Definition: fd.hpp:191
std::ostream & operator<<(std::ostream &stream, const ProcessTree &tree)
Definition: process.hpp:126
friend bool operator>=(int left, const WindowsFD &right)
Definition: fd.hpp:378
WindowsFD & operator=(const WindowsFD &)=default
WindowsFD(intptr_t socket)
Definition: fd.hpp:98
friend Try< WindowsFD > dup(const WindowsFD &fd)
Try< Netlink< struct nl_sock > > socket(int protocol=NETLINK_ROUTE)
Definition: internal.hpp:91
HANDLE get_iocp() const
Definition: fd.hpp:229
size_t result_type
Definition: fd.hpp:452
HANDLE handle_
Definition: fd.hpp:241