Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Visible to Intel only — GUID: GUID-C153D487-1DB8-47F1-8F34-6797FD6D639D

Document Table of Contents

Example for aio_error and aio_return Functions

The following example illustrates how the aio_error() and aio_return() functions can be used.

int aio_ex_3(HANDLE fd) { static struct aiocb aio; static struct aiocb *aio_list[] = {&aio}; int ret; char *dat = "Hello from Ex-3\n"; /* Data initialization and asynchronously writing */ IC_AIO_DATA_INIT(aio, fd, dat, strlen(dat), 0); if (aio_write(& aio) == -1) return errno; ret = aio_error(&aio); if ( ret == EINPROGRESS ) { fprintf(stderr, "ERRNO=%d STR=%s\n", ret, strerror(ret)); ret = aio_suspend(aio_list, 1, NULL); if (ret == -1) return errno;} else if (ret) return ret; ret = aio_error(&aio); if (ret) return ret; ret = aio_return(&aio); printf("ret=%d\n", ret); return 0; }/* aio_ex_3 */

Result upon execution:

-bash-3.00$ ./a.out ERRNO=115 STR=Operation now in progress ret=16 -bash-3.00$ cat dat Hello from Ex-3

Remarks:

  1. In the example, the IC_AIO_DATA_INIT is defined as follows:
    #define IC_AIO_DATA_INIT(_aio, _fd, _dat, _len, _off)\ {memset(&_aio, 0, sizeof(_aio)); \ _aio.aio_fildes = _fd; \ _aio.aio_buf = _dat; \ _aio.aio_nbytes = _len; \ _aio.aio_offset = _off;}
  2. The file descriptor fd is obtained as:
    HANDLE fd = CreateFile("dat", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL/*|FILE_FLAG_OVERLAPPED*/, NULL);