… | |
… | |
286 | linuxaio_modify (EV_P_ int fd, int oev, int nev) |
286 | linuxaio_modify (EV_P_ int fd, int oev, int nev) |
287 | { |
287 | { |
288 | array_needsize (ANIOCBP, linuxaio_iocbps, linuxaio_iocbpmax, fd + 1, linuxaio_array_needsize_iocbp); |
288 | array_needsize (ANIOCBP, linuxaio_iocbps, linuxaio_iocbpmax, fd + 1, linuxaio_array_needsize_iocbp); |
289 | ANIOCBP iocb = linuxaio_iocbps [fd]; |
289 | ANIOCBP iocb = linuxaio_iocbps [fd]; |
290 | |
290 | |
291 | if (iocb->io.aio_reqprio < 0) |
291 | if (expect_false (iocb->io.aio_reqprio < 0)) |
292 | { |
292 | { |
293 | /* we handed this fd over to epoll, so undo this first */ |
293 | /* we handed this fd over to epoll, so undo this first */ |
294 | /* we do it manually because the optimisations on epoll_modify won't do us any good */ |
294 | /* we do it manually because the optimisations on epoll_modify won't do us any good */ |
295 | epoll_ctl (backend_fd, EPOLL_CTL_DEL, fd, 0); |
295 | epoll_ctl (backend_fd, EPOLL_CTL_DEL, fd, 0); |
296 | anfds [fd].emask = 0; |
296 | anfds [fd].emask = 0; |
297 | iocb->io.aio_reqprio = 0; |
297 | iocb->io.aio_reqprio = 0; |
298 | } |
298 | } |
299 | |
299 | |
300 | if (iocb->io.aio_buf) |
300 | if (expect_false (iocb->io.aio_buf)) |
301 | { |
301 | { |
|
|
302 | /* iocb active, so cancel it first before resubmit */ |
|
|
303 | for (;;) |
|
|
304 | { |
|
|
305 | /* on all relevant kernels, io_cancel fails with EINPROGRESS on "success" */ |
302 | evsys_io_cancel (linuxaio_ctx, &iocb->io, (struct io_event *)0); |
306 | if (expect_false (evsys_io_cancel (linuxaio_ctx, &iocb->io, (struct io_event *)0) == 0)) |
303 | /* on relevant kernels, io_cancel fails with EINPROGRES if everything is fine */ |
307 | break; |
|
|
308 | |
|
|
309 | if (expect_true (errno == EINPROGRESS)) |
|
|
310 | break; |
|
|
311 | |
|
|
312 | /* the EINPROGRESS test is for nicer error message. clumsy. */ |
304 | assert (("libev: linuxaio unexpected io_cancel failed", errno == EINPROGRESS)); |
313 | assert (("libev: linuxaio unexpected io_cancel failed", errno != EINPROGRESS && errno != EINTR)); |
305 | } |
314 | } |
|
|
315 | } |
|
|
316 | |
|
|
317 | iocb->io.aio_buf = |
|
|
318 | (nev & EV_READ ? POLLIN : 0) |
|
|
319 | | (nev & EV_WRITE ? POLLOUT : 0); |
306 | |
320 | |
307 | if (nev) |
321 | if (nev) |
308 | { |
322 | { |
309 | iocb->io.aio_buf = |
|
|
310 | (nev & EV_READ ? POLLIN : 0) |
|
|
311 | | (nev & EV_WRITE ? POLLOUT : 0); |
|
|
312 | |
|
|
313 | /* queue iocb up for io_submit */ |
323 | /* queue iocb up for io_submit */ |
314 | /* this assumes we only ever get one call per fd per loop iteration */ |
324 | /* this assumes we only ever get one call per fd per loop iteration */ |
315 | ++linuxaio_submitcnt; |
325 | ++linuxaio_submitcnt; |
316 | array_needsize (struct iocb *, linuxaio_submits, linuxaio_submitmax, linuxaio_submitcnt, array_needsize_noinit); |
326 | array_needsize (struct iocb *, linuxaio_submits, linuxaio_submitmax, linuxaio_submitcnt, array_needsize_noinit); |
317 | linuxaio_submits [linuxaio_submitcnt - 1] = &iocb->io; |
327 | linuxaio_submits [linuxaio_submitcnt - 1] = &iocb->io; |
… | |
… | |
553 | assert (("libev: event loop rejected bad fd", errno != EBADF)); |
563 | assert (("libev: event loop rejected bad fd", errno != EBADF)); |
554 | fd_kill (EV_A_ linuxaio_submits [submitted]->aio_fildes); |
564 | fd_kill (EV_A_ linuxaio_submits [submitted]->aio_fildes); |
555 | |
565 | |
556 | res = 1; /* skip this iocb */ |
566 | res = 1; /* skip this iocb */ |
557 | } |
567 | } |
|
|
568 | else if (errno == EINTR) /* not seen in reality, not documented */ |
|
|
569 | res = 0; /* silently ignore and retry */ |
558 | else |
570 | else |
559 | ev_syserr ("(libev) linuxaio io_submit"); |
571 | ev_syserr ("(libev) linuxaio io_submit"); |
560 | |
572 | |
561 | submitted += res; |
573 | submitted += res; |
562 | } |
574 | } |