MCPcopy Create free account
hub / github.com/axboe/liburing / test_single_link_timeout

Function test_single_link_timeout

test/link-timeout.c:467–539  ·  view source on GitHub ↗

* Test read that will not complete, with a linked timeout behind it */

Source from the content-addressed store, hash-verified

465 * Test read that will not complete, with a linked timeout behind it
466 */
467static int test_single_link_timeout(struct io_uring *ring, unsigned nsec)
468{
469 struct __kernel_timespec ts;
470 struct io_uring_cqe *cqe;
471 struct io_uring_sqe *sqe;
472 int fds[2], ret, i;
473 struct iovec iov;
474 char buffer[128];
475
476 if (pipe(fds)) {
477 perror("pipe");
478 return 1;
479 }
480
481 sqe = io_uring_get_sqe(ring);
482 if (!sqe) {
483 printf("get sqe failed\n");
484 goto err;
485 }
486
487 iov.iov_base = buffer;
488 iov.iov_len = sizeof(buffer);
489 io_uring_prep_readv(sqe, fds[0], &iov, 1, 0);
490 sqe->flags |= IOSQE_IO_LINK;
491 sqe->user_data = 1;
492
493 sqe = io_uring_get_sqe(ring);
494 if (!sqe) {
495 printf("get sqe failed\n");
496 goto err;
497 }
498
499 ts.tv_sec = 0;
500 ts.tv_nsec = nsec;
501 io_uring_prep_link_timeout(sqe, &ts, 0);
502 sqe->user_data = 2;
503
504 ret = io_uring_submit(ring);
505 if (ret != 2) {
506 printf("sqe submit failed: %d\n", ret);
507 goto err;
508 }
509
510 for (i = 0; i < 2; i++) {
511 ret = io_uring_wait_cqe(ring, &cqe);
512 if (ret < 0) {
513 printf("wait completion %d\n", ret);
514 goto err;
515 }
516 switch (cqe->user_data) {
517 case 1:
518 if (cqe->res != -EINTR && cqe->res != -ECANCELED) {
519 fprintf(stderr, "Read got %d\n", cqe->res);
520 goto err;
521 }
522 break;
523 case 2:
524 if (cqe->res != -EALREADY && cqe->res != -ETIME &&

Callers 1

mainFunction · 0.85

Calls 2

io_uring_submitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected