1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include "poll.h"
static void event_callback(struct ev_loop *loop, ev_io *w, s32 revents)
{
(void)loop;
struct nn_poll *poll = (struct nn_poll *)w->data;
poll->callback(poll->userdata, revents);
}
void nn_poll_init(struct nn_poll *poll, void (*callback)(void *, s32 revents), void *userdata)
{
poll->callback = callback;
poll->userdata = userdata;
poll->event.data = poll;
ev_init_n(&poll->event, event_callback);
}
void nn_poll_set(struct nn_poll *poll, s32 fd, s32 events)
{
ev_io_set(&poll->event, fd, events);
}
void nn_poll_start(struct nn_poll *poll, struct nn_event_loop *loop)
{
poll->loop = loop;
ev_io_start(poll->loop->ev, &poll->event);
}
void nn_poll_stop(struct nn_poll *poll)
{
ev_io_stop(poll->loop->ev, &poll->event);
}
|