Developer Guide and Reference

Contents

Handling Errors Caused by Asynchronous I/O Functions

This topic only applies to Windows* OS.
The
errno
macro is used to obtain the errors that occur during asynchronous request functions such as
aio_read()
,
aio_write()
,
aio_fsync()
, and
lio_listio()
or asynchronous control functions, such as
aio_cancel()
,
aio_error()
,
aio_return()
, and
aio_suspend()
.
The following example illustrates how
errno
can be used.
#include <stdio.h> #include <stdlib.h> #include <aio.h>   struct aiocb my_aio; struct aiocb *my_aio_list[1] = {&my_aio};   int main() {   int res;   double arr[123456];  timespec_t my_t = {1, 0};   /* Data initialization */  my_aio.aio_fildes = CreateFile("dat",    GENERIC_READ | GENERIC_WRITE,    FILE_SHARE_READ,    NULL,    OPEN_ALWAYS,    FILE_ATTRIBUTE_NORMAL,    NULL);  my_aio.aio_buf = (volatile char *)arr;  my_aio.aio_nbytes = sizeof(arr);   /* Do asynchronous writing with computation overlapping */  aio_write(&my_aio);  do_compute(arr, 123456);   /* Suspend the asynchronous writing for 1 sec */  res = aio_suspend(my_aio_list, 1, &my_t);  if ( res ) {   /* The call was ended by timeout, before the indicated operations had completed. */   if ( errno == EAGAIN ) {   res = aio_suspend(my_aio_list, 1, 0);   if ( res ) {   printf("aio_suspend returned non-0\n"); return errno;}   }   else   if ( res ) {   printf("aio_suspend returned neither 0 nor EAGAIN\n");   return errno;   }  }    CloseHandle(my_aio.aio_fildes);  printf("\nPass\n");    return 0; }
In the example, the program executes an asynchronous write operation, using
aio_write(),
overlapping with some computation, the
do_compute()
function execution. The pending write operation is suspended for one second using
aio_suspend()
.
On successful execution of the asynchronous write operation, zero is returned.
EAGAIN
or any other error value is returned when the call is ended by timeout before the indicated operation has completed.
You can check
EAGAIN
using the
errno
macro.

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804