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

Function main

test/short-read.c:18–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16#define FILE_SIZE 1024
17
18int main(int argc, char *argv[])
19{
20 int ret, fd, save_errno;
21 struct io_uring ring;
22 struct io_uring_sqe *sqe;
23 struct io_uring_cqe *cqe;
24 struct iovec vec;
25
26 if (argc > 1)
27 return 0;
28
29 vec.iov_base = t_malloc(BUF_SIZE);
30 vec.iov_len = BUF_SIZE;
31
32 t_create_file(".short-read", FILE_SIZE);
33
34 fd = open(".short-read", O_RDONLY);
35 save_errno = errno;
36 unlink(".short-read");
37 errno = save_errno;
38 if (fd < 0) {
39 perror("file open");
40 return 1;
41 }
42
43 ret = io_uring_queue_init(32, &ring, 0);
44 if (ret) {
45 fprintf(stderr, "queue init failed: %d\n", ret);
46 return ret;
47 }
48
49 sqe = io_uring_get_sqe(&ring);
50 if (!sqe) {
51 fprintf(stderr, "sqe get failed\n");
52 return 1;
53 }
54 io_uring_prep_readv(sqe, fd, &vec, 1, 0);
55
56 ret = io_uring_submit(&ring);
57 if (ret != 1) {
58 fprintf(stderr, "submit failed: %d\n", ret);
59 return 1;
60 }
61
62 ret = io_uring_wait_cqes(&ring, &cqe, 1, 0, 0);
63 if (ret) {
64 fprintf(stderr, "wait_cqe failed: %d\n", ret);
65 return 1;
66 }
67
68 if (cqe->res != FILE_SIZE) {
69 fprintf(stderr, "Read failed: %d\n", cqe->res);
70 return 1;
71 }
72
73 io_uring_cqe_seen(&ring, cqe);
74 free(vec.iov_base);
75 return 0;

Callers

nothing calls this directly

Calls 6

t_mallocFunction · 0.85
t_create_fileFunction · 0.85
io_uring_queue_initFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_wait_cqesFunction · 0.85
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected