uvw 3.1.0
Loading...
Searching...
No Matches
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 "config.h"
8#include "enum.hpp"
9#include "handle.hpp"
10#include "util.h"
11
12namespace uvw {
13
14namespace details {
15
16enum class uvw_poll_event : std::underlying_type_t<uv_poll_event> {
17 READABLE = UV_READABLE,
18 WRITABLE = UV_WRITABLE,
19 DISCONNECT = UV_DISCONNECT,
20 PRIORITIZED = UV_PRIORITIZED,
21 _UVW_ENUM = 0
22};
23
24}
25
27struct poll_event {
28 explicit poll_event(details::uvw_poll_event events) noexcept;
29
40 details::uvw_poll_event flags;
41};
42
59class poll_handle final: public handle<poll_handle, uv_poll_t, poll_event> {
60 static void start_callback(uv_poll_t *hndl, int status, int events);
61
62public:
63 using poll_event_flags = details::uvw_poll_event;
64
65 explicit poll_handle(loop::token token, std::shared_ptr<loop> ref, int desc);
66 explicit poll_handle(loop::token token, std::shared_ptr<loop> ref, os_socket_handle sock);
67
72 int init() final;
73
93 int start(poll_event_flags flags);
94
99 int stop();
100
101private:
102 enum {
103 FD,
104 SOCKET
105 } tag;
106
107 union {
108 int file_desc;
109 os_socket_handle socket;
110 };
111};
112
113} // namespace uvw
114
115#ifndef UVW_AS_LIB
116# include "poll.cpp"
117#endif
118
119#endif // UVW_POLL_INCLUDE_H
Handle base class.
Definition: handle.hpp:23
The poll handle.
Definition: poll.h:59
int start(poll_event_flags flags)
Starts polling the file descriptor.
int init() final
Initializes the handle.
int stop()
Stops polling the file descriptor.
uvw default namespace.
Definition: async.h:8
details::uv_type_wrapper< uv_os_sock_t > os_socket_handle
Definition: util.h:86
Poll event.
Definition: poll.h:27
details::uvw_poll_event flags
Detected events all in one.
Definition: poll.h:40