aio_return 或 aio_return64 子例程

aio_returnaio_return64 子例程包含 POSIX AIO aio_return 子例程 (如 IEEE std 1003.1-2001中所定义) 和 Legacy AIO aio_return 子例程的信息。

POSIX AIO aio_return 子例程

用途

检索异步 I/O 操作的返回状态。

标准 C 库 (libc.a)

语法

#include <aio.h>

size_t aio_return (aiocbp);
struct aiocb *aiocbp;

描述

aio_return 子例程返回与 aiocb 结构相关联的返回状态。 异步 I/O 操作的返回状态是相应的 readwritefsync 子例程调用将返回的值。 如果操作的错误状态等于 EINPROGRESS,那么表示未定义操作的返回状态。 可以调用一次 aio_return 子例程以检索给定异步操作的返回状态。 之后,如果在调用 aio_returnaio_error时使用相同的 aiocb 结构,那么可能会返回错误。 当使用 aiocbp 所引用的 aiocb 结构来提交另一个异步操作时,可以成功使用 aio_return 子例程来检索该操作的返回状态。

参数

描述
aiocbp 指向与 I/O 操作关联的 aiocb 结构。

aiocb 结构

aiocb 结构在 /usr/include/aio.h 文件中定义,并包含以下成员:
int               aio_fildes
off_t             aio_offset
char             *aio_buf
size_t            aio_nbytes
int               aio_reqprio
struct sigevent   aio_sigevent
int               aio_lio_opcode

执行环境

只能从 流程环境 调用 aio_returnaio_return64 子例程。

返回值

如果异步 I/O 操作已完成,那么将返回返回状态 (如 readwritefsync 子例程所述)。 如果异步 I/O 操作尚未完成,那么未定义 aio_return 子例程的结果。

错误代码

描述
EINVAL aiocbp 参数不引用尚未检索其返回状态的异步操作。

旧 AIO aio_return 子例程

用途: 检索异步 I/O 请求的返回状态。

库 (旧 AIO aio_return 子例程)

标准 C 库 (libc.a)

语法 (旧 AIO aio_return 子例程)

#include <aio.h> 
int aio_return( handle)
aio_handle_t handle;
int aio_return64( handle)
aio_handle_t handle;

描述 (旧 AIO aio_return 子例程)

aio_return 子例程检索与 aio_handle_t 句柄关联的异步 I/O 请求的返回状态 (如果 I/O 请求已完成)。 返回的状态与相应的 readwrite 函数调用将返回的状态相同。 如果 I/O 操作尚未完成,那么返回的状态为 undefined。

aio_return64 子例程类似于 aio_return 子例程,只是它检索与 aiocb64 控制块关联的错误状态。

注: 当使用 aio.h 编译具有旧 AIO 函数定义的 aio 应用程序时,必须定义 aio.h 中使用的 _AIO_AIX_SOURCE 宏。 使用 aio.h 文件进行的缺省编译适用于具有 POSIX AIO 定义的应用程序。 在源文件中输入:
#define _AIO_AIX_SOURCE
#include <sys/aio.h>
或者,在编译时在命令行上输入:
->xlc ... -D_AIO_AIX_SOURCE ... legacy_aio_program.c 

参数 (旧 AIO aio_return 子例程)

描述
句柄 (handle) handleaio 控制块 (aiocbaiocb64) 结构的字段由先前调用 aio_readaio_read64aio_writeaio_write64lio_listioaio_listio64 子例程设置。 如果传入了随机内存位置,那么将返回随机结果。

aiocb 结构

aiocb 结构在 /usr/include/aio.h 文件中定义,并包含以下成员:
struct aiocb
{
       int                 aio_whence;
       off_t               aio_offset;
       char                *aio_buf;
       ssize_t             aio_return;
       int                 aio_errno;
       size_t              aio_nbytes;
       union {
              int          reqprio;
              struct {
                     int   version:8;
                     int   priority:8;
                     int   cache_hint:16;
              } ext;
       } aio_u1;
       int                 aio_flag;
       int                 aio_iocpfd;
       aio_handle_t        aio_handle;
}

#define aio_reqprio        aio_u1.reqprio
#define aio_version        aio_u1.ext.version
#define aio_priority       aio_u1.ext.priority
#define aio_cache_hint     aio_u1.ext.cache_hint

执行环境 (旧 AIO aio_return 子例程)

只能从 流程环境 调用 aio_returnaio_return64 子例程。

返回值 (旧 AIO aio_return 子例程)

aio_return 子例程返回与 readwrite 函数返回的异步 I/O 请求相对应的状态。 如果 aio_error 子例程调用返回的错误状态为 EINPROG,那么未定义 aio_return 子例程返回的值。

示例 (旧 AIO aio_return 子例程)

aio_error 子例程返回 0 时,要最终从磁盘设备读取 1000 字节的 aio_read 请求会导致 aio_return 子例程返回 1000。 从 500 字节文件读取 1000 字节的 aio_read 请求最终导致 aio_return 子例程返回 500。 向只读文件系统写入的aio_write请求最终会导致aio_error子程序返回EROFS,而aio_return子程序返回值为-1。