Changeset 22f94a4 for examples/io/cat.c
- Timestamp:
- Aug 11, 2020, 4:40:15 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 0d070ca
- Parents:
- 07d867b (diff), 129674b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 moved
-
examples/io/cat.c (moved) (moved from examples/io_uring.c ) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
examples/io/cat.c
r07d867b r22f94a4 1 /* 2 This is a simple "cat" example that uses io_uring in IORING_SETUP_IOPOLL mode. 3 It demonstrates the bare minimum needed to use io_uring in polling mode. 4 It uses liburing for simplicity. 5 */ 6 7 8 #ifndef _GNU_SOURCE 9 #define _GNU_SOURCE 10 #endif 11 1 12 #include <fcntl.h> 2 13 #include <liburing.h> 3 14 #include <stdio.h> 15 #include <string.h> 4 16 #include <unistd.h> 5 17 6 18 struct io_uring ring; 19 20 __attribute__((aligned(1024))) char data[1024]; 7 21 8 22 int main(int argc, char * argv[]) { … … 12 26 } 13 27 14 int fd = open(argv[1], 0);28 int fd = open(argv[1], O_DIRECT); 15 29 if(fd < 0) { 16 30 printf("Could not open file %s.\n", argv[1]); … … 19 33 20 34 /* prep the array */ 21 char data[512]; 22 struct iovec iov = { data, 512 }; 35 struct iovec iov = { data, 1024 }; 23 36 24 37 /* init liburing */ 25 io_uring_queue_init(256, &ring, 0);38 io_uring_queue_init(256, &ring, IORING_SETUP_IOPOLL); 26 39 27 40 /* declare required structs */ … … 32 45 sqe = io_uring_get_sqe(&ring); 33 46 io_uring_prep_readv(sqe, fd, &iov, 1, 0); 47 // io_uring_prep_read(sqe, fd, data, 1024, 0); 34 48 35 sqe->user_data = data;49 sqe->user_data = (uint64_t)(uintptr_t)data; 36 50 37 51 /* tell the kernel we have an sqe ready for consumption */ … … 40 54 /* wait for the sqe to complete */ 41 55 int ret = io_uring_wait_cqe(&ring, &cqe); 42 56 43 57 /* read and process cqe event */ 44 58 if(ret == 0) { 45 char * out = cqe->user_data;59 char * out = (char *)(uintptr_t)cqe->user_data; 46 60 signed int len = cqe->res; 47 61 io_uring_cqe_seen(&ring, cqe); … … 49 63 if(len > 0) { 50 64 printf("%.*s", len, out); 65 } 66 else if( len < 0 ) { 67 fprintf(stderr, "readv/read returned error : %s\n", strerror(-len)); 51 68 } 52 69 }
Note:
See TracChangeset
for help on using the changeset viewer.