--- libev/ev_linuxaio.c 2019/06/25 18:07:44 1.32 +++ libev/ev_linuxaio.c 2019/06/26 00:11:24 1.35 @@ -291,15 +291,18 @@ if (iocb->io.aio_reqprio < 0) { /* we handed this fd over to epoll, so undo this first */ - /* we do it manually because the optimisations on epoll_modfy won't do us any good */ + /* we do it manually because the optimisations on epoll_modify won't do us any good */ epoll_ctl (backend_fd, EPOLL_CTL_DEL, fd, 0); anfds [fd].emask = 0; iocb->io.aio_reqprio = 0; } if (iocb->io.aio_buf) - /* io_cancel always returns some error on relevant kernels, but works */ - evsys_io_cancel (linuxaio_ctx, &iocb->io, (struct io_event *)0); + { + evsys_io_cancel (linuxaio_ctx, &iocb->io, (struct io_event *)0); + /* on relevant kernels, io_cancel fails with EINPROGRES if everything is fine */ + assert (("libev: linuxaio unexpected io_cancel failed", errno != EINPROGRESS)); + } if (nev) { @@ -321,7 +324,8 @@ epoll_poll (EV_A_ 0); } -static void +inline_speed +void linuxaio_fd_rearm (EV_P_ int fd) { anfds [fd].events = 0; @@ -347,7 +351,7 @@ | (res & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) ); - /* linux aio is oneshot: rearm fd. TODO: this does more work than needed */ + /* linux aio is oneshot: rearm fd. TODO: this does more work than strictly needed */ linuxaio_fd_rearm (EV_A_ fd); --nr; @@ -510,6 +514,7 @@ } else if (errno == EBADF) { + assert (("libev: event loop rejected bad fd", errno != EBADF)); fd_kill (EV_A_ linuxaio_submits [submitted]->aio_fildes); res = 1; /* skip this iocb */ @@ -572,7 +577,7 @@ { epoll_destroy (EV_A); linuxaio_free_iocbp (EV_A); - evsys_io_destroy (linuxaio_ctx); + evsys_io_destroy (linuxaio_ctx); /* fails in child, aio context is destroyed */ } inline_size @@ -588,6 +593,7 @@ while (linuxaio_io_setup (EV_A) < 0) ev_syserr ("(libev) linuxaio io_setup"); + /* forking epoll should also effectively unregister all fds from the backend */ epoll_fork (EV_A); ev_io_stop (EV_A_ &linuxaio_epoll_w);