source: examples/io_uring.c @ 3a3b2b9

arm-ehenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-expr
Last change on this file since 3a3b2b9 was 3a3b2b9, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Added hello world example using io_uring. Works in 19.10

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <fcntl.h>
2#include <liburing.h>
3#include <stdio.h>
4#include <unistd.h>
5
6struct io_uring ring;
7
8int main(int argc,  char * argv[]) {
9      if(argc != 2) {
10            printf("usage:   %s FILE - prints file to console.\n", argv[0]);
11            return 1;
12      }
13
14      int fd = open(argv[1], 0);
15      if(fd < 0) {
16            printf("Could not open file %s.\n", argv[1]);
17            return 2;
18      }
19
20      /* prep the array */
21      char data[512];
22      struct iovec iov = { data, 512 };
23
24      /* init liburing */
25      io_uring_queue_init(256, &ring, 0);
26
27      /* declare required structs */
28      struct io_uring_sqe * sqe;
29      struct io_uring_cqe * cqe;
30
31      /* get an sqe and fill in a READV operation */
32      sqe = io_uring_get_sqe(&ring);
33      io_uring_prep_readv(sqe, fd, &iov, 1, 0);
34
35      /* tell the kernel we have an sqe ready for consumption */
36      io_uring_submit(&ring);
37
38      /* wait for the sqe to complete */
39      int ret = io_uring_wait_cqe(&ring, &cqe);
40      printf("%d\n", ret);
41
42      /* read and process cqe event */
43      printf("%s", data);
44      io_uring_cqe_seen(&ring, cqe);
45
46      io_uring_queue_exit(&ring);
47
48      close(fd);
49}
Note: See TracBrowser for help on using the repository browser.