Changeset f3ed2af


Ignore:
Timestamp:
Jul 27, 2020, 1:43:16 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
3a1cf0d
Parents:
a86b1b85
Message:

Fixed example with O_DIRECT to use proper alignment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/io_uring.c

    ra86b1b85 rf3ed2af  
     1#ifndef _GNU_SOURCE
    12#define _GNU_SOURCE
     3#endif
    24
    35#include <fcntl.h>
     
    810
    911struct io_uring ring;
     12
     13__attribute__((aligned(1024))) char data[1024];
    1014
    1115int main(int argc,  char * argv[]) {
     
    2226
    2327      /* prep the array */
    24       char data[512];
    25       struct iovec iov = { data, 512 };
     28      struct iovec iov = { data, 1024 };
    2629
    2730      /* init liburing */
     
    3538      sqe = io_uring_get_sqe(&ring);
    3639      io_uring_prep_readv(sqe, fd, &iov, 1, 0);
     40      // io_uring_prep_read(sqe, fd, data, 1024, 0);
    3741
    38       sqe->user_data = data;
     42      sqe->user_data = (uint64_t)(uintptr_t)data;
    3943
    4044      /* tell the kernel we have an sqe ready for consumption */
     
    4650      /* read and process cqe event */
    4751      if(ret == 0) {
    48             char * out = cqe->user_data;
     52            char * out = (char *)(uintptr_t)cqe->user_data;
    4953            signed int len = cqe->res;
    5054            io_uring_cqe_seen(&ring, cqe);
     
    5458            }
    5559            else if( len < 0 ) {
    56                   fprintf(stderr, "readv returned error : %s\n", strerror(-len));
     60                  fprintf(stderr, "readv/read returned error : %s\n", strerror(-len));
    5761            }
    5862      }
Note: See TracChangeset for help on using the changeset viewer.