多线程编程指南

异步 I/O 操作

#include <sys/asynch.h>



int aioread(int fildes, char *bufp, int bufs, off_t offset,

    int whence, aio_result_t *resultp);



int aiowrite(int filedes, const char *bufp, int bufs,

    off_t offset, int whence, aio_result_t *resultp);



aio_result_t *aiowait(const struct timeval *timeout);



int aiocancel(aio_result_t *resultp);

aioread(3AIO)aiowrite(3AIO) 在格式上类似于 pread(2)pwrite(2),但是添加了最后一个参数。对 aioread()aiowrite() 的调用导致启动 I/O 操作或将该操作排入队列。

调用将顺利返回,而不被阻塞,而且调用的状态将在 resultp 所指向的结构中返回。resultpaio_result_t 类型的项,其中包含以下值:

int aio_return;

int aio_errno;

当调用立即失败时,可以在 aio_errno 中找到失败代码。否则,此字段将包含 AIO_INPROGRESS,意味着已成功地将操作排入队列。