COROIO: coroio/select.hpp Source File
COROIO
 
Loading...
Searching...
No Matches
select.hpp
1#pragma once
2
3#ifdef _WIN32
4#include <winsock2.h>
5#else
6#include <sys/select.h>
7#endif
8#include <assert.h>
9#include <system_error>
10
11#include "poller.hpp"
12#include "socket.hpp"
13
14namespace NNet {
15
36class TSelect: public TPollerBase {
37public:
48 void Poll();
49
50#ifdef _WIN32
56 TSelect();
57#endif
58
59private:
68 fd_set* ReadFds() {
69#ifdef _WIN32
70 return &ReadFds_;
71#else
72 return reinterpret_cast<fd_set*>(&ReadFds_[0]);
73#endif
74 }
75
84 fd_set* WriteFds() {
85#ifdef _WIN32
86 return &WriteFds_;
87#else
88 return reinterpret_cast<fd_set*>(&WriteFds_[0]);
89#endif
90 }
91
92 std::vector<THandlePair> InEvents_;
93#ifdef _WIN32
94 fd_set ReadFds_;
95 fd_set WriteFds_;
96 TSocket DummySocket_;
97#else
98 std::vector<fd_mask> ReadFds_;
99 std::vector<fd_mask> WriteFds_;
100#endif
101};
102
103} // namespace NNet
Asynchronous file handle that owns its file descriptor.
Definition socket.hpp:317
TPollerBase()=default
Default constructor.
Poller implementation based on the select() system call.
Definition select.hpp:36
NNet::TFileHandle TFileHandle
Alias for the file handle type.
Definition select.hpp:41
void Poll()
Polls for I/O events using the select() system call.
NNet::TSocket TSocket
Alias for the socket type.
Definition select.hpp:39
High-level asynchronous socket for network communication.
Definition socket.hpp:364