uvw  2.11.0
poll.h
1 #ifndef UVW_POLL_INCLUDE_H
2 #define UVW_POLL_INCLUDE_H
3 
4 
5 #include <type_traits>
6 #include <memory>
7 #include <uv.h>
8 #include "handle.hpp"
9 #include "util.h"
10 
11 
12 namespace uvw {
13 
14 
15 namespace details {
16 
17 
18 enum class UVPollEvent: std::underlying_type_t<uv_poll_event> {
19  READABLE = UV_READABLE,
20  WRITABLE = UV_WRITABLE,
21  DISCONNECT = UV_DISCONNECT,
22  PRIORITIZED = UV_PRIORITIZED
23 };
24 
25 
26 }
27 
28 
34 struct PollEvent {
35  explicit PollEvent(Flags<details::UVPollEvent> events) noexcept;
36 
48 };
49 
50 
67 class PollHandle final: public Handle<PollHandle, uv_poll_t> {
68  static void startCallback(uv_poll_t *handle, int status, int events);
69 
70 public:
71  using Event = details::UVPollEvent;
72 
73  explicit PollHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, int desc);
74  explicit PollHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, OSSocketHandle sock);
75 
80  bool init();
81 
101  void start(Flags<Event> flags);
102 
122  void start(Event event);
123 
127  void stop();
128 
129 private:
130  enum { FD, SOCKET } tag;
131  union {
132  int file_desc;
133  OSSocketHandle::Type socket;
134  };
135 };
136 
137 
138 }
139 
140 
141 #ifndef UVW_AS_LIB
142 #include "poll.cpp"
143 #endif
144 
145 #endif // UVW_POLL_INCLUDE_H
Handle base class.
Definition: handle.hpp:30
The PollHandle handle.
Definition: poll.h:67
void start(Event event)
Starts polling the file descriptor.
void stop()
Stops polling the file descriptor.
bool init()
Initializes the handle.
void start(Flags< Event > flags)
Starts polling the file descriptor.
uvw default namespace.
Definition: async.h:10
details::UVTypeWrapper< uv_os_sock_t > OSSocketHandle
Definition: util.h:190
PollEvent event.
Definition: poll.h:34
Flags< details::UVPollEvent > flags
Detected events all in one.
Definition: poll.h:47