master
h 44 lines 1.33 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #ifndef NETDATA_ND_POLL_H
4 #define NETDATA_ND_POLL_H
5
6 #include "libnetdata/libnetdata-base.h"
7
8 typedef enum __attribute__((packed)) {
9 ND_POLL_NONE = 0,
10
11 ND_POLL_READ = 1 << 0, // same as EPOLLIN, POLLIN
12 ND_POLL_WRITE = 1 << 2, // same as EPOLLOUT, POLLOUT
13 ND_POLL_ERROR = 1 << 3, // same as EPOLLERR, POLLERR
14 ND_POLL_HUP = 1 << 4, // same as EPOLLHUP, POLLHUP
15 ND_POLL_INVALID = 1 << 5, // same as POLLNVAL
16
17 ND_POLL_TIMEOUT = 1 << 6,
18 ND_POLL_POLL_FAILED = 1 << 7,
19 } nd_poll_event_t;
20
21 typedef struct {
22 nd_poll_event_t events;
23 const void *data;
24 } nd_poll_result_t;
25
26 typedef struct nd_poll_t nd_poll_t;
27
28 nd_poll_t *nd_poll_create() WARNUNUSED;
29 void nd_poll_destroy(nd_poll_t *ndpl);
30
31 // the events can be updated with nd_poll_upd
32 // the data pointer SHOULD NEVER be changed and cannot be NULL
33 bool nd_poll_add(nd_poll_t *ndpl, int fd, nd_poll_event_t events, const void *data);
34
35 // delete an fd
36 bool nd_poll_del(nd_poll_t *ndpl, int fd);
37
38 // update the expected events on an fd
39 bool nd_poll_upd(nd_poll_t *ndpl, int fd, nd_poll_event_t events);
40
41 // returns -1 = error, 0 = timeout, 1 = event in result
42 int nd_poll_wait(nd_poll_t *ndpl, int timeout_ms, nd_poll_result_t *result);
43
44 #endif //NETDATA_ND_POLL_H