Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7094295
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类: LINUX

2014-04-14 07:42:47

官网:,正如标题所说,非常简单了,不用多解释,请直接看头文件,其中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 */




阅读(480) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~