Developer Guide and Reference

Contents

Example for aio_suspend Function

The following example illustrates a wait operation execution using the
aio_suspend()
function.
int aio_ex_2(HANDLE fd) { static struct aiocb aio[2]; static struct aiocb *aio_list[2] = {&aio[0], &aio[1]}; int i, ret; /* Data initialization */ IC_AIO_DATA_INIT(aio[0], fd, "rec#1\n", strlen("rec#1\n"), 0) IC_AIO_DATA_INIT(aio[1], fd, "rec#2\n", strlen("rec#2\n"), aio[0].aio_nbytes) /* Asynch-write */ if (aio_write(&aio[0]) == -1) return errno; if (aio_write(&aio[1]) == -1) return errno; /* Do some complex computation */ printf("do_compute(1000, 1.123)=%f", do_compute(1000, 1.123)); /* do the wait operation using sleep() */ ret = aio_suspend(aio_list, 2, 0); if (ret == -1) return errno; return 0; }/* aio_ex_2 */
Result upon execution:
-bash-3.00$ ./a.out -bash-3.00$ cat dat rec#1 rec#2
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);