Next: Configuration of AIO, Previous: Synchronizing AIO Operations, Up: Asynchronous I/O
When one or more requests are asynchronously processed, it might be useful in some situations to cancel a selected operation, e.g., if it becomes obvious that the written data is no longer accurate and would have to be overwritten soon. As an example, assume an application, which writes data in files in a situation where new incoming data would have to be written in a file which will be updated by an enqueued request. The POSIX AIO implementation provides such a function, but this function is not capable of forcing the cancellation of the request. It is up to the implementation to decide whether it is possible to cancel the operation or not. Therefore using this function is merely a hint.
The
aio_cancelfunction can be used to cancel one or more outstanding requests. If the aiocbp parameter isNULL, the function tries to cancel all of the outstanding requests which would process the file descriptor fildes (i.e., whoseaio_fildesmember is fildes). If aiocbp is notNULL,aio_cancelattempts to cancel the specific request pointed to by aiocbp.For requests which were successfully canceled, the normal notification about the termination of the request should take place. I.e., depending on the
struct sigeventobject which controls this, nothing happens, a signal is sent or a thread is started. If the request cannot be canceled, it terminates the usual way after performing the operation.After a request is successfully canceled, a call to
aio_errorwith a reference to this request as the parameter will returnECANCELEDand a call toaio_returnwill return -1. If the request wasn't canceled and is still running the error status is stillEINPROGRESS.The return value of the function is
AIO_CANCELEDif there were requests which haven't terminated and which were successfully canceled. If there is one or more requests left which couldn't be canceled, the return value isAIO_NOTCANCELED. In this caseaio_errormust be used to find out which of the, perhaps multiple, requests (in aiocbp isNULL) weren't successfully canceled. If all requests already terminated at the timeaio_cancelis called the return value isAIO_ALLDONE.If an error occurred during the execution of
aio_cancelthe function returns -1 and setserrnoto one of the following values.
EBADF- The file descriptor fildes is not valid.
ENOSYSaio_cancelis not implemented.When the sources are compiled with
_FILE_OFFSET_BITS == 64, this function is in factaio_cancel64since the LFS interface transparently replaces the normal implementation.
This function is similar to
aio_cancelwith the only difference that the argument is a reference to a variable of typestruct aiocb64.When the sources are compiled with
_FILE_OFFSET_BITS == 64, this function is available under the nameaio_canceland so transparently replaces the interface for small files on 32 bit machines.