1 .\" Copyright (c) 2010 Apple Inc. All rights reserved.
8 .Nd asynchronously read from and write to file descriptors
10 .Fd #include <dispatch/dispatch.h>
15 .Fa "dispatch_queue_t queue"
16 .Fa "void (^handler)(dispatch_data_t data, int error)"
21 .Fa "dispatch_data_t data"
22 .Fa "dispatch_queue_t queue"
23 .Fa "void (^handler)(dispatch_data_t data, int error))"
30 functions asynchronously read from and write to POSIX file descriptors. They
31 can be thought of as asynchronous, callback-based versions of the
35 functions provided by the standard C library. They are convenience functions
37 .Xr dispatch_io_read 3
39 .Xr dispatch_io_write 3
40 functions, intended for simple one-shot read or write requests. Multiple
41 request on the same file desciptor are better handled with the full underlying
42 dispatch I/O channel functions.
46 function schedules an asynchronous read operation on the file descriptor
48 Once the file descriptor is readable, the system will read as much data as is
49 currently available, up to the specified
51 starting at the current file pointer position. The given
53 block will be submitted to
55 when the operation completes or an error occurs. The block will be passed a
58 object with the result of the read operation. If an error occurred while
59 reading from the file descriptor, the
61 parameter to the block will be set to the appropriate POSIX error code and
63 will contain any data that could be read successfully. If the file pointer
64 position is at end-of-file, emtpy
68 will be passed to the handler block.
72 function schedules an asynchronous write operation on the file descriptor
74 The system will attempt to write the entire contents of the provided
78 at the current file pointer position. The given
80 block will be submitted to
82 when the operation completes or an error occurs. If the write operation
83 completed successfully, the
85 parameter to the block will be set to zero, otherwise it will be set to the
86 appropriate POSIX error code and the
88 parameter will contain any data that could not be written.
94 block is released by the system when the block returns. If
96 is needed outside of the handler block, it must concatenate, copy, or retain
99 Once an asynchronous read or write operation has been submitted on a file
102 the system takes control of that file descriptor until the
104 block is executed. During this time the application must not manipulate
106 directly, in particular it is only safe to close
108 from the handler block (or after it has returned).
110 If multiple asynchronous read or write operations are submitted to the same
111 file descriptor, they will be performed in order, but their handlers will only
112 be submitted once all operations have completed and control over the file
113 descriptor has been relinquished. For details on this and on the interaction
114 with dispatch I/O channels created from the same file descriptor, see
115 .Sx FILEDESCRIPTOR OWNERSHIP
117 .Xr dispatch_io_create 3 .
120 .Xr dispatch_data_create 3 ,
121 .Xr dispatch_io_create 3 ,
122 .Xr dispatch_io_read 3 ,