… | |
… | |
268 | |
268 | |
269 | /* increment generation counter to avoid handling old events */ |
269 | /* increment generation counter to avoid handling old events */ |
270 | ++anfd->egen; |
270 | ++anfd->egen; |
271 | } |
271 | } |
272 | |
272 | |
273 | iocb->io.aio_buf = |
273 | iocb->io.aio_buf = (nev & EV_READ ? POLLIN : 0) |
274 | (nev & EV_READ ? POLLIN : 0) |
|
|
275 | | (nev & EV_WRITE ? POLLOUT : 0); |
274 | | (nev & EV_WRITE ? POLLOUT : 0); |
276 | |
275 | |
277 | if (nev) |
276 | if (nev) |
278 | { |
277 | { |
279 | iocb->io.aio_data = (uint32_t)fd | ((__u64)(uint32_t)anfd->egen << 32); |
278 | iocb->io.aio_data = (uint32_t)fd | ((__u64)(uint32_t)anfd->egen << 32); |
280 | |
279 | |
… | |
… | |
310 | uint32_t gen = ev->data >> 32; |
309 | uint32_t gen = ev->data >> 32; |
311 | int res = ev->res; |
310 | int res = ev->res; |
312 | |
311 | |
313 | assert (("libev: iocb fd must be in-bounds", fd >= 0 && fd < anfdmax)); |
312 | assert (("libev: iocb fd must be in-bounds", fd >= 0 && fd < anfdmax)); |
314 | |
313 | |
315 | /* ignore event if generation doesn't match */ |
314 | /* only accept events if generation counter matches */ |
316 | if (ecb_expect_false (gen != (uint32_t)anfds [fd].egen)) |
315 | if (ecb_expect_true (gen == (uint32_t)anfds [fd].egen)) |
317 | continue; |
316 | { |
318 | |
|
|
319 | /* feed events, we do not expect or handle POLLNVAL */ |
317 | /* feed events, we do not expect or handle POLLNVAL */ |
320 | fd_event ( |
318 | fd_event ( |
321 | EV_A_ |
319 | EV_A_ |
322 | fd, |
320 | fd, |
323 | (res & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) |
321 | (res & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) |
324 | | (res & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) |
322 | | (res & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) |
325 | ); |
323 | ); |
326 | |
324 | |
327 | /* linux aio is oneshot: rearm fd. TODO: this does more work than strictly needed */ |
325 | /* linux aio is oneshot: rearm fd. TODO: this does more work than strictly needed */ |
328 | linuxaio_fd_rearm (EV_A_ fd); |
326 | linuxaio_fd_rearm (EV_A_ fd); |
|
|
327 | } |
329 | |
328 | |
330 | --nr; |
329 | --nr; |
331 | ++ev; |
330 | ++ev; |
332 | } |
331 | } |
333 | } |
332 | } |
… | |
… | |
437 | break; |
436 | break; |
438 | } |
437 | } |
439 | else |
438 | else |
440 | break; /* no events from the kernel, we are done */ |
439 | break; /* no events from the kernel, we are done */ |
441 | |
440 | |
442 | timeout = 0; /* only wait in the first iteration */ |
441 | timeout = EV_TS_CONST (0.); /* only wait in the first iteration */ |
443 | } |
442 | } |
444 | } |
443 | } |
445 | |
444 | |
446 | inline_size |
445 | inline_size |
447 | int |
446 | int |
… | |
… | |
517 | backend = EVBACKEND_EPOLL; |
516 | backend = EVBACKEND_EPOLL; |
518 | backend_modify = epoll_modify; |
517 | backend_modify = epoll_modify; |
519 | backend_poll = epoll_poll; |
518 | backend_poll = epoll_poll; |
520 | } |
519 | } |
521 | |
520 | |
522 | timeout = 0; |
521 | timeout = EV_TS_CONST (0.); |
523 | /* it's easiest to handle this mess in another iteration */ |
522 | /* it's easiest to handle this mess in another iteration */ |
524 | return; |
523 | return; |
525 | } |
524 | } |
526 | else if (errno == EBADF) |
525 | else if (errno == EBADF) |
527 | { |
526 | { |
… | |
… | |
567 | { |
566 | { |
568 | epoll_destroy (EV_A); |
567 | epoll_destroy (EV_A); |
569 | return 0; |
568 | return 0; |
570 | } |
569 | } |
571 | |
570 | |
572 | ev_io_init (EV_A_ &linuxaio_epoll_w, linuxaio_epoll_cb, backend_fd, EV_READ); |
571 | ev_io_init (&linuxaio_epoll_w, linuxaio_epoll_cb, backend_fd, EV_READ); |
573 | ev_set_priority (&linuxaio_epoll_w, EV_MAXPRI); |
572 | ev_set_priority (&linuxaio_epoll_w, EV_MAXPRI); |
574 | ev_io_start (EV_A_ &linuxaio_epoll_w); |
573 | ev_io_start (EV_A_ &linuxaio_epoll_w); |
575 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
574 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
576 | |
575 | |
577 | backend_modify = linuxaio_modify; |
576 | backend_modify = linuxaio_modify; |