… | |
… | |
77 | return; |
77 | return; |
78 | |
78 | |
79 | oldmask = anfds [fd].emask; |
79 | oldmask = anfds [fd].emask; |
80 | anfds [fd].emask = nev; |
80 | anfds [fd].emask = nev; |
81 | |
81 | |
82 | /* store the generation counter in the upper 32 bits */ |
82 | /* store the generation counter in the upper 32 bits, the fd in the lower 32 bits */ |
83 | ev.data.u64 = fd | ((uint64_t)++anfds [fd].egen << 32); |
83 | ev.data.u64 = (uint64_t)(uint32_t)fd |
|
|
84 | | ((uint64_t)(uint32_t)++anfds [fd].egen << 32); |
84 | ev.events = (nev & EV_READ ? EPOLLIN : 0) |
85 | ev.events = (nev & EV_READ ? EPOLLIN : 0) |
85 | | (nev & EV_WRITE ? EPOLLOUT : 0); |
86 | | (nev & EV_WRITE ? EPOLLOUT : 0); |
86 | |
87 | |
87 | if (expect_true (!epoll_ctl (backend_fd, oev ? EPOLL_CTL_MOD : EPOLL_CTL_ADD, fd, &ev))) |
88 | if (expect_true (!epoll_ctl (backend_fd, oev ? EPOLL_CTL_MOD : EPOLL_CTL_ADD, fd, &ev))) |
88 | return; |
89 | return; |
… | |
… | |
121 | int eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.)); |
122 | int eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.)); |
122 | |
123 | |
123 | if (expect_false (eventcnt < 0)) |
124 | if (expect_false (eventcnt < 0)) |
124 | { |
125 | { |
125 | if (errno != EINTR) |
126 | if (errno != EINTR) |
126 | syserr ("(libev) epoll_wait"); |
127 | ev_syserr ("(libev) epoll_wait"); |
127 | |
128 | |
128 | return; |
129 | return; |
129 | } |
130 | } |
130 | |
131 | |
131 | for (i = 0; i < eventcnt; ++i) |
132 | for (i = 0; i < eventcnt; ++i) |
… | |
… | |
136 | int want = anfds [fd].events; |
137 | int want = anfds [fd].events; |
137 | int got = (ev->events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0) |
138 | int got = (ev->events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0) |
138 | | (ev->events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0); |
139 | | (ev->events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0); |
139 | |
140 | |
140 | /* check for spurious notification */ |
141 | /* check for spurious notification */ |
141 | if (expect_false (anfds [fd].egen != (unsigned char)(ev->data.u64 >> 32))) |
142 | if (expect_false ((uint32_t)anfds [fd].egen != (uint32_t)(ev->data.u64 >> 32))) |
142 | { |
143 | { |
143 | /* recreate kernel state */ |
144 | /* recreate kernel state */ |
144 | postfork = 1; |
145 | postfork = 1; |
145 | continue; |
146 | continue; |
146 | } |
147 | } |
… | |
… | |
203 | epoll_fork (EV_P) |
204 | epoll_fork (EV_P) |
204 | { |
205 | { |
205 | close (backend_fd); |
206 | close (backend_fd); |
206 | |
207 | |
207 | while ((backend_fd = epoll_create (256)) < 0) |
208 | while ((backend_fd = epoll_create (256)) < 0) |
208 | syserr ("(libev) epoll_create"); |
209 | ev_syserr ("(libev) epoll_create"); |
209 | |
210 | |
210 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |
211 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |
211 | |
212 | |
212 | fd_rearm_all (EV_A); |
213 | fd_rearm_all (EV_A); |
213 | } |
214 | } |