现在的位置: 首页 > 综合 > 正文

asynchronous io for linux

2013年04月03日 ⁄ 综合 ⁄ 共 4990字 ⁄ 字号 评论关闭

int aio_read(struct aiocb *aiocbp);

Description

The aio_read() function requests an asynchronous "n = read(fd, buf, count)" with fd, buf, count given by aiocbp->aio_fildes, aiocbp->aio_buf, aiocbp->aio_nbytes, respectively. The return status n can be retrieved upon completion using aio_return(3).

The data is read starting at the absolute file offset aiocbp->aio_offset, regardless of the current file position. After this request, the value of the current file position is unspecified.

The "asynchronous" means that this call returns as soon as the request has been enqueued; the read may or may not have completed when the call returns. One tests for completion using aio_error(3).

 

If _POSIX_PRIORITIZED_IO is defined, and this file supports it, then the asynchronous operation is submitted at a priority equal to that of the calling process minus aiocbp->aio_reqprio.

 

The field aiocbp->aio_lio_opcode is ignored.

No data is read from a regular file beyond its maximum offset.

Return Value

On success, 0 is returned. On error the request is not enqueued, -1 is returned, and errno is set appropriately. If an error is first detected later, it will be reported via aio_return(3) (returns status -1) and aio_error(3) (error status whatever one would have gotten in errno, such as EBADF).

 

int aio_write(struct aiocb *aiocbp);

Description

The aio_write() function requests an asynchronous "n = write(fd, buf, count)" with fd, buf, count given by aiocbp->aio_fildes, aiocbp->aio_buf, aiocbp->aio_nbytes, respectively. The return status n can be retrieved upon completion using aio_return(3).

If O_APPEND is not set, the data is written starting at the absolute file offset aiocbp->aio_offset, regardless of the current file position. If O_APPEND is set, the data is written at the end of the file. After this request, the value of the current file position is unspecified.

The "asynchronous" means that this call returns as soon as the request has been enqueued; the write may or may not have completed when the call returns. One tests for completion using aio_error(3).

 

If _POSIX_PRIORITIZED_IO is defined, and this file supports it, then the asynchronous operation is submitted at a priority equal to that of the calling process minus aiocbp->aio_reqprio.

 

The field aiocbp->aio_lio_opcode is ignored.

No data is written to a regular file beyond its maximum offset.

Return Value

On success, 0 is returned. On error the request is not enqueued, -1 is returned, and errno is set appropriately. If an error is first detected later, it will be reported via aio_return(3) (returns status -1) and aio_error(3) (error status whatever one would have gotten in errno, such as EBADF).

 

int aio_cancel(int fd, struct aiocb *aiocbp);

Description

The aio_cancel() function attempts to cancel outstanding asynchronous I/O requests for the file descriptor fd. If aiocbp is NULL, all such requests are cancelled. Otherwise, only the request described by the control block pointed to by aiocbp is cancelled.

Normal asynchronous notification occurs for cancelled requests. The request return status is set to -1, and the request error status is set to ECANCELED. The control block of requests that cannot be cancelled is not changed.

If aiocbp is not NULL, and fd differs from the file descriptor with which the asynchronous operation was initiated, unspecified results occur.

Which operations are cancelable is implementation-defined.

Return Value

This function returns AIO_CANCELED if all requests were successfully cancelled. It returns AIO_NOTCANCELED when at least one of the requests specified was not cancelled because it was in progress. In this case one may check the status of individual requests using aio_error(3). This function returns AIO_ALLDONE when all requests had been completed already before this call. When some error occurs, -1 is returned, and errno is set appropriately.

 

ssize_t aio_return(struct aiocb *aiocbp);

Description

The aio_return() function returns the final return status for the asynchronous I/O request with control block pointed to by aiocbp.

This function should be called only once for any given request, after aio_error(3) returns something other than EINPROGRESS.

Return Value

If the asynchronous I/O operation has completed, this function returns the value that would have been returned in case of a synchronous read, write, or fsync request. Otherwise the return value is undefined. On error, the error value is returned.

 

int aio_error(const struct aiocb *aiocbp);

Description

The aio_error() function returns the error status for the asynchronous I/O request with control block pointed to by aiocbp.

Return Value

This function returns EINPROGRESS if the request has not been completed yet. It returns ECANCELED if the request was cancelled. It returns 0 if the request completed successfully. Otherwise an error value is returned, the same value that would have been stored in the errno variable in case of a synchronous read, write, fsync, or fdatasync request. On error, the error value is returned.

int aio_fsync(int op, struct aiocb *aiocbp);

Description

The aio_fsync() function does a sync on all outstanding asynchronous I/O operations associated with aiocbp->aio_fildes.

More precisely, if op is O_SYNC, then all currently queued I/O operations shall be completed as if by a call of fsync(2), and if op is O_DSYNC, this call is the asynchronous analog of fdatasync(2). Note that this is a request only -- this call does not wait for I/O completion.

Apart from aio_fildes the only field in the structure pointed to by aiocbp that is used by this call is the aio_sigevent field (a struct sigevent) that indicates the desired type of asynchronous notification at completion. All other fields are ignored.

Return Value

On success (the sync request was successfully queued) this function returns 0. On error -1 is returned, and errno is set appropriately.

抱歉!评论已关闭.