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

Function test_async_addr

test/send-zerocopy.c:614–683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

612}
613
614static int test_async_addr(struct io_uring *ring)
615{
616 struct io_uring_sqe *sqe;
617 struct io_uring_cqe *cqe;
618 struct sockaddr_storage addr;
619 int sock_tx = -1, sock_rx = -1;
620 struct __kernel_timespec ts;
621 int ret;
622
623 ts.tv_sec = 1;
624 ts.tv_nsec = 0;
625 ret = create_socketpair_ip(&addr, &sock_tx, &sock_rx, true, false, false, false);
626 if (ret) {
627 fprintf(stderr, "sock prep failed %d\n", ret);
628 return 1;
629 }
630
631 sqe = io_uring_get_sqe(ring);
632 io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_ETIME_SUCCESS);
633 sqe->user_data = 1;
634 sqe->flags |= IOSQE_IO_LINK;
635
636 sqe = io_uring_get_sqe(ring);
637 io_uring_prep_send_zc(sqe, sock_tx, tx_buffer, 1, 0, 0);
638 sqe->user_data = 2;
639 io_uring_prep_send_set_addr(sqe, (const struct sockaddr *)&addr,
640 sizeof(struct sockaddr_in6));
641
642 ret = io_uring_submit(ring);
643 assert(ret == 2);
644 memset(&addr, 0, sizeof(addr));
645
646 ret = io_uring_wait_cqe(ring, &cqe);
647 if (ret) {
648 fprintf(stderr, "io_uring_wait_cqe failed %i\n", ret);
649 return 1;
650 }
651 if (cqe->user_data != 1 || cqe->res != -ETIME) {
652 fprintf(stderr, "invalid timeout res %i %i\n",
653 (int)cqe->user_data, cqe->res);
654 return 1;
655 }
656 io_uring_cqe_seen(ring, cqe);
657
658 ret = io_uring_wait_cqe(ring, &cqe);
659 if (ret) {
660 fprintf(stderr, "io_uring_wait_cqe failed %i\n", ret);
661 return 1;
662 }
663 if (cqe->user_data != 2 || cqe->res != 1) {
664 fprintf(stderr, "invalid send %i %i\n",
665 (int)cqe->user_data, cqe->res);
666 return 1;
667 }
668 io_uring_cqe_seen(ring, cqe);
669 ret = recv(sock_rx, rx_buffer, 1, MSG_TRUNC);
670 assert(ret == 1);
671

Callers 1

run_basic_testsFunction · 0.85

Calls 3

create_socketpair_ipFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected