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

Function test

test/fixed-buf-iter.c:20–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18#define OUT_FD "/dev/zero"
19
20static int test(struct io_uring *ring)
21{
22 struct iovec iov[BUFFERS];
23 struct io_uring_sqe *sqe;
24 struct io_uring_cqe *cqe;
25 int ret, fd_in, fd_out, i;
26
27 fd_in = open(IN_FD, O_RDONLY, 0644);
28 if (fd_in < 0) {
29 perror("open in");
30 return 1;
31 }
32
33 fd_out = open(OUT_FD, O_RDWR, 0644);
34 if (fd_out < 0) {
35 perror("open out");
36 return 1;
37 }
38
39 for (i = 0; i < BUFFERS; i++) {
40 iov[i].iov_base = malloc(BUF_SIZE);
41 iov[i].iov_len = BUF_SIZE;
42 memset(iov[i].iov_base, 0, BUF_SIZE);
43 }
44
45 ret = io_uring_register_buffers(ring, iov, BUFFERS);
46 if (ret) {
47 fprintf(stderr, "Error registering buffers: %s", strerror(-ret));
48 return 1;
49 }
50
51 sqe = io_uring_get_sqe(ring);
52 if (!sqe) {
53 fprintf(stderr, "Could not get SQE.\n");
54 return 1;
55 }
56
57 io_uring_prep_read_fixed(sqe, fd_in, iov[0].iov_base, BUF_SIZE, 0, 0);
58 io_uring_submit(ring);
59
60 ret = io_uring_wait_cqe(ring, &cqe);
61 if (ret < 0) {
62 fprintf(stderr, "Error waiting for completion: %s\n", strerror(-ret));
63 return 1;
64 }
65
66 if (cqe->res < 0) {
67 fprintf(stderr, "Error in async operation: %s\n", strerror(-cqe->res));
68 return 1;
69 }
70 io_uring_cqe_seen(ring, cqe);
71
72 sqe = io_uring_get_sqe(ring);
73 if (!sqe) {
74 fprintf(stderr, "Could not get SQE.\n");
75 return 1;
76 }
77 io_uring_prep_write_fixed(sqe, fd_out, iov[0].iov_base, BUF_SIZE, 0, 0);

Callers 1

mainFunction · 0.70

Calls 3

io_uring_submitFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected