在Solaris Internals这本书上,作者提到一段代码用以检测系统是否支持异步I/O.
感觉很有助于理解Solaris系统异步IO的实现以及系统调用。
列在这里和大家分享.
1.源码:
/*
* Quick kaio test. Read 1k bytes from a file using async I/O.
* To compile:
* cc -o aio aio.c -laio
* To run:
* aio file_name
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/aio.h>
#define BSIZE 1024
main(int argc, char *argv[])
{
aio_result_t res;
char buf[BSIZE];
int fd;
if ((fd=open(argv[1], O_RDONLY)) == -1) {
perror("open");
exit(-1);
}
aioread(fd, buf, BSIZE, 0L, SEEK_SET, &res);
aiowait(0);
if (res.aio_return == BSIZE) {
printf("aio succeeded\
");
close(fd);
exit(0);
}
perror("aio");
}
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




