Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 14.5 Asynchronous I/O 513


#include <aio.h>
int aio_fsync(intop,struct aiocb *aiocb);
Returns: 0 if OK,−1 on error
Theaio_fildesfield in the AIO control block indicates the file whose asynchronous
writes aresynched. If theopargument is set toO_DSYNC,then the operation behaves
like a call tofdatasync.Otherwise, ifopis set toO_SYNC,the operation behaves like a
call tofsync.
Like theaio_readandaio_writefunctions, theaio_fsyncoperation returns
when the synch is scheduled. The data won’t be persistent until the asynchronous
synch completes. The AIO control block controls how we arenotified, just as with the
aio_readandaio_writefunctions.
To determine the completion status of an asynchronous read, write, or synch
operation, we need to call theaio_errorfunction.
#include <aio.h>
int aio_error(const struct aiocb *aiocb);
Returns: (see following)
The return value tells us one of four things.
0 The asynchronous operation completed successfully.Weneed to
call theaio_returnfunction to obtain the return value from the
operation.
−1The call toaio_errorfailed. In this case,errnotells us why.
EINPROGRESS The asynchronous read, write, or synch is still pending.
anything else Any other return value gives us the error code corresponding to
the failed asynchronous operation.
If the asynchronous operation succeeded, we can call theaio_returnfunction to
get the asynchronous operation’s return value.
#include <aio.h>
ssize_t aio_return(const struct aiocb *aiocb);
Returns: (see following)
Until the asynchronous operation completes, we need to be careful to avoid calling the
aio_returnfunction. Theresults areundefined until the operation completes. We
also need to be careful to callaio_returnonly one time per asynchronous I/O
operation. Once we call this function, the operating system is free to deallocate the
recordcontaining the I/O operation’s return value.
Theaio_returnfunction will return−1and seterrnoifaio_returnitself fails.
Otherwise, it will return the results of the asynchronous operation. In this case, it will
return whateverread,write,orfsyncwould have returned on success if one of those
functions had been called.
Free download pdf