… | |
… | |
44 | |
44 | |
45 | epoll_ctl (epoll_fd, mode, fd, &ev); |
45 | epoll_ctl (epoll_fd, mode, fd, &ev); |
46 | } |
46 | } |
47 | |
47 | |
48 | static void |
48 | static void |
49 | epoll_postfork_child (EV_P) |
|
|
50 | { |
|
|
51 | int fd; |
|
|
52 | |
|
|
53 | epoll_fd = epoll_create (256); |
|
|
54 | fcntl (epoll_fd, F_SETFD, FD_CLOEXEC); |
|
|
55 | |
|
|
56 | /* re-register interest in fds */ |
|
|
57 | for (fd = 0; fd < anfdmax; ++fd) |
|
|
58 | if (anfds [fd].events)//D |
|
|
59 | epoll_modify (EV_A_ fd, EV_NONE, anfds [fd].events); |
|
|
60 | } |
|
|
61 | |
|
|
62 | static void |
|
|
63 | epoll_poll (EV_P_ ev_tstamp timeout) |
49 | epoll_poll (EV_P_ ev_tstamp timeout) |
64 | { |
50 | { |
65 | int eventcnt = epoll_wait (epoll_fd, events, eventmax, ceil (timeout * 1000.)); |
51 | int eventcnt = epoll_wait (epoll_fd, epoll_events, epoll_eventmax, ceil (timeout * 1000.)); |
66 | int i; |
52 | int i; |
67 | |
53 | |
68 | if (eventcnt < 0) |
54 | if (eventcnt < 0) |
69 | return; |
55 | return; |
70 | |
56 | |
71 | for (i = 0; i < eventcnt; ++i) |
57 | for (i = 0; i < eventcnt; ++i) |
72 | fd_event ( |
58 | fd_event ( |
73 | EV_A_ |
59 | EV_A_ |
74 | events [i].data.u64, |
60 | epoll_events [i].data.u64, |
75 | (events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0) |
61 | (epoll_events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0) |
76 | | (events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0) |
62 | | (epoll_events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0) |
77 | ); |
63 | ); |
78 | |
64 | |
79 | /* if the receive array was full, increase its size */ |
65 | /* if the receive array was full, increase its size */ |
80 | if (expect_false (eventcnt == eventmax)) |
66 | if (expect_false (eventcnt == epoll_eventmax)) |
81 | { |
67 | { |
82 | free (events); |
68 | free (epoll_events); |
83 | eventmax = array_roundsize (events, eventmax << 1); |
69 | epoll_eventmax = array_roundsize (epoll_events, epoll_eventmax << 1); |
84 | events = malloc (sizeof (struct epoll_event) * eventmax); |
70 | epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); |
85 | } |
71 | } |
86 | } |
72 | } |
87 | |
73 | |
88 | static int |
74 | static int |
89 | epoll_init (EV_P_ int flags) |
75 | epoll_init (EV_P_ int flags) |
… | |
… | |
97 | |
83 | |
98 | method_fudge = 1e-3; /* needed to compensate for epoll returning early */ |
84 | method_fudge = 1e-3; /* needed to compensate for epoll returning early */ |
99 | method_modify = epoll_modify; |
85 | method_modify = epoll_modify; |
100 | method_poll = epoll_poll; |
86 | method_poll = epoll_poll; |
101 | |
87 | |
102 | eventmax = 64; /* intiial number of events receivable per poll */ |
88 | epoll_eventmax = 64; /* intiial number of events receivable per poll */ |
103 | events = malloc (sizeof (struct epoll_event) * eventmax); |
89 | epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); |
104 | |
90 | |
105 | return EVMETHOD_EPOLL; |
91 | return EVMETHOD_EPOLL; |
106 | } |
92 | } |
107 | |
93 | |
|
|
94 | static void |
|
|
95 | epoll_destroy (EV_P) |
|
|
96 | { |
|
|
97 | close (epoll_fd); |
|
|
98 | |
|
|
99 | free (epoll_events); |
|
|
100 | } |
|
|
101 | |
|
|
102 | static void |
|
|
103 | epoll_fork (EV_P) |
|
|
104 | { |
|
|
105 | epoll_fd = epoll_create (256); |
|
|
106 | fcntl (epoll_fd, F_SETFD, FD_CLOEXEC); |
|
|
107 | |
|
|
108 | fd_rearm_all (EV_A); |
|
|
109 | } |
|
|
110 | |