Advertisement
3axap_010

dll.c

May 12th, 2020
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <aio.h>
  2. #include <fcntl.h>
  3. #include <string.h>
  4.  
  5. int async_read(int file, char* buffer, size_t size, off_t offset)
  6. {
  7.     struct aiocb cb;
  8.     memset(&cb, 0, sizeof(struct aiocb));
  9.     cb.aio_fildes = file;
  10.     cb.aio_offset = offset;
  11.     cb.aio_nbytes = size;
  12.     cb.aio_lio_opcode = LIO_READ;
  13.     cb.aio_buf = buffer;
  14.     struct sigevent se;
  15.     se.sigev_notify = SIGEV_NONE;
  16.     cb.aio_sigevent = se;
  17.  
  18.     aio_read(&cb);
  19.  
  20.     while (aio_error(&cb) != 0)
  21.         ;
  22.  
  23.     return aio_return(&cb);
  24. }
  25.  
  26. int async_write(int file, char* buffer, size_t size, off_t offset)
  27. {
  28.     struct aiocb cb;
  29.     memset(&cb, 0, sizeof(struct aiocb));
  30.     cb.aio_fildes = file;
  31.     cb.aio_offset = offset;
  32.     cb.aio_nbytes = size;
  33.     cb.aio_lio_opcode = LIO_WRITE;
  34.     cb.aio_buf = buffer;
  35.     struct sigevent se;
  36.     se.sigev_notify = SIGEV_NONE;
  37.     cb.aio_sigevent = se;
  38.  
  39.     aio_write(&cb);
  40.  
  41.     while (aio_error(&cb) != 0)
  42.         ;
  43.  
  44.     return aio_return(&cb);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement