uvw  2.12.1
poll.h
1 #ifndef UVW_POLL_INCLUDE_H
2 #define UVW_POLL_INCLUDE_H
3 
4 #include <memory>
5 #include <type_traits>
6 #include <uv.h>
7 #include "handle.hpp"
8 #include "util.h"
9 
10 namespace uvw {
11 
12 namespace details {
13 
14 enum class UVPollEvent : std::underlying_type_t<uv_poll_event> {
15  READABLE = UV_READABLE,
16  WRITABLE = UV_WRITABLE,
17  DISCONNECT = UV_DISCONNECT,
18  PRIORITIZED = UV_PRIORITIZED
19 };
20 
21 }
22 
28 struct PollEvent {
29  explicit PollEvent(Flags<details::UVPollEvent> events) noexcept;
30 
42 };
43 
60 class PollHandle final: public Handle<PollHandle, uv_poll_t> {
61  static void startCallback(uv_poll_t *handle, int status, int events);
62 
63 public:
64  using Event = details::UVPollEvent;
65 
66  explicit PollHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, int desc);
67  explicit PollHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, OSSocketHandle sock);
68 
73  bool init();
74 
94  void start(Flags<Event> flags);
95 
115  void start(Event event);
116 
120  void stop();
121 
122 private:
123  enum {
124  FD,
125  SOCKET
126  } tag;
127 
128  union {
129  int file_desc;
130  OSSocketHandle::Type socket;
131  };
132 };
133 
134 } // namespace uvw
135 
136 #ifndef UVW_AS_LIB
137 # include "poll.cpp"
138 #endif
139 
140 #endif // UVW_POLL_INCLUDE_H
Handle base class.
Definition: handle.hpp:26
The PollHandle handle.
Definition: poll.h:60
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:8
details::UVTypeWrapper< uv_os_sock_t > OSSocketHandle
Definition: util.h:205
PollEvent event.
Definition: poll.h:28
Flags< details::UVPollEvent > flags
Detected events all in one.
Definition: poll.h:41