Skip to main content

dispatch_read

Function dispatch_read 

Source
pub unsafe extern "C" fn dispatch_read(
    fd: dispatch_fd_t,
    length: usize,
    queue: &DispatchQueue,
    handler: &DynBlock<dyn Fn(NonNull<DispatchData>, c_int)>,
)
Expand description

Schedule a read operation for asynchronous execution on the specified file descriptor. The specified handler is enqueued with the data read from the file descriptor when the operation has completed or an error occurs.

The data object passed to the handler will be automatically released by the system when the handler returns. It is the responsibility of the application to retain, concatenate or copy the data object if it is needed after the handler returns.

The data object passed to the handler will only contain as much data as is currently available from the file descriptor (up to the specified length).

If an unrecoverable error occurs on the file descriptor, the handler will be enqueued with the appropriate error code along with a data object of any data that could be read successfully.

An invocation of the handler with an error code of zero and an empty data object indicates that EOF was reached.

The system takes control of the file descriptor until the handler is enqueued, and during this time file descriptor flags such as O_NONBLOCK will be modified by the system on behalf of the application. It is an error for the application to modify a file descriptor directly while it is under the control of the system, but it may create additional dispatch I/O convenience operations or dispatch I/O channels associated with that file descriptor.

Parameter fd: The file descriptor from which to read the data.

Parameter length: The length of data to read from the file descriptor, or SIZE_MAX to indicate that all of the data currently available from the file descriptor should be read.

Parameter queue: The dispatch queue to which the handler should be submitted.

Parameter handler: The handler to enqueue when data is ready to be delivered. param data The data read from the file descriptor. param error An errno condition for the read operation or zero if the read was successful.