-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_net_poll.c
57 lines (48 loc) · 1.02 KB
/
_net_poll.c
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <sys/epoll.h>
#include "_net_poll.h"
#include "_net_socket.h"
int
sp_create(int size) {
return epoll_create(size);
}
int
sp_wait(int efd, struct event *ev, int maxevs) {
int i,n;
struct epoll_event events[maxevs];
n = epoll_wait(efd, events, maxevs, -1);
for (i = 0; i < n; i++) {
if (events[i].events & EPOLLIN) {
ev[i].is_read = 1;
}
if (events[i].events & EPOLLOUT) {
ev[i].is_write = 1;
}
ev[i].s = events[i].data.ptr;
}
return n;
}
int
sp_add(int efd, int fd, void *s) {
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.ptr = s;
return epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
}
int
sp_write(int efd, int fd, void *s) {
struct epoll_event ev;
ev.events = EPOLLIN | EPOLLOUT;
ev.data.ptr = s;
return epoll_ctl(efd, EPOLL_CTL_MOD, fd, &ev);
}
int
sp_unwrite(int efd, int fd, void *s) {
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.ptr = s;
return epoll_ctl(efd, EPOLL_CTL_MOD, fd, &ev);
}
int
sp_del(int efd, int fd) {
return epoll_ctl(efd, EPOLL_CTL_DEL, fd, 0);
}