Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <aio.h>
- #include <fcntl.h>
- #include <string.h>
- int async_read(int file, char* buffer, size_t size, off_t offset)
- {
- struct aiocb cb;
- memset(&cb, 0, sizeof(struct aiocb));
- cb.aio_fildes = file;
- cb.aio_offset = offset;
- cb.aio_nbytes = size;
- cb.aio_lio_opcode = LIO_READ;
- cb.aio_buf = buffer;
- struct sigevent se;
- se.sigev_notify = SIGEV_NONE;
- cb.aio_sigevent = se;
- aio_read(&cb);
- while (aio_error(&cb) != 0)
- ;
- return aio_return(&cb);
- }
- int async_write(int file, char* buffer, size_t size, off_t offset)
- {
- struct aiocb cb;
- memset(&cb, 0, sizeof(struct aiocb));
- cb.aio_fildes = file;
- cb.aio_offset = offset;
- cb.aio_nbytes = size;
- cb.aio_lio_opcode = LIO_WRITE;
- cb.aio_buf = buffer;
- struct sigevent se;
- se.sigev_notify = SIGEV_NONE;
- cb.aio_sigevent = se;
- aio_write(&cb);
- while (aio_error(&cb) != 0)
- ;
- return aio_return(&cb);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement