64
`start_async`::
65
66
Run a function asynchronously. Takes a pointer to a `struct
67
- async` that specifies the details and returns a pipe FD
68
- from which the caller reads. See below for details.
67
+ async` that specifies the details and returns a set of pipe FDs
68
+ for communication with the function. See below for details.
69
70
`finish_async`::
71
180
struct async variable;
181
2. initializes .proc and .data;
182
3. calls start_async();
183
-4. processes the data by reading from the fd in .out;
184
-5. closes .out;
183
+4. processes communicates with proc through .in and .out;
184
+5. closes .in and .out;
185
6. calls finish_async().
186
187
+The members .in, .out are used to provide a set of fd's for
188
+communication between the caller and the callee as follows:
189
+
190
+. Specify 0 to have no file descriptor passed. The callee will
191
+ receive -1 in the corresponding argument.
192
+
193
+. Specify < 0 to have a pipe allocated; start_async() replaces
194
+ with the pipe FD in the following way:
195
+
196
+ .in: Returns the writable pipe end into which the caller
197
+ writes; the readable end of the pipe becomes the function's
198
+ in argument.
199
+
200
+ .out: Returns the readable pipe end from which the caller
201
+ reads; the writable end of the pipe becomes the function's
202
+ out argument.
203
+
204
+ The caller of start_async() must close the returned FDs after it
205
+ has completed reading from/writing from them.
206
+
207
+. Specify a file descriptor > 0 to be used by the function:
208
+
209
+ .in: The FD must be readable; it becomes the function's in.
210
+ .out: The FD must be writable; it becomes the function's out.
211
+
212
+ The specified FD is closed by start_async(), even if it fails to
213
+ run the function.
214
+
215
The function pointer in .proc has the following signature:
216
189
- int proc(int fd, void *data);
217
+ int proc(int in, int out, void *data);
218
191
-. fd specifies a writable file descriptor to which the function must
192
- write the data that it produces. The function *must* close this
193
- descriptor before it returns.
219
+. in, out specifies a set of file descriptors to which the function
220
+ must read/write the data that it needs/produces. The function
221
+ *must* close these descriptors before it returns. A descriptor
222
+ may be -1 if the caller did not configure a descriptor for that
223
+ direction.
224
225
. data is the value that the caller has specified in the .data member
226
of struct async.
235
UNIX, but by a thread in the same address space on Windows:
236
237
. It cannot change the program's state (global variables, environment,
208
- etc.) in a way that the caller notices; in other words, .out is the
209
- only communication channel to the caller.
238
+ etc.) in a way that the caller notices; in other words, .in and .out
239
+ are the only communication channels to the caller.
240
241
. It must not change the program's state that the caller of the
242
facility also uses.