@@ -64,8 +64,8 @@ The functions above do the following:
64
64
`start_async`::
65
65
66
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
69
70
70
`finish_async`::
71
71
@@ -135,7 +135,7 @@ stderr as follows:
135
135
136
136
.in: The FD must be readable; it becomes child's stdin.
137
137
.out: The FD must be writable; it becomes child's stdout.
138
- .err > 0 is not supported .
138
+ .err: The FD must be writable; it becomes child's stderr .
139
139
140
140
The specified FD is closed by start_command(), even if it fails to
141
141
run the sub-process!
@@ -180,17 +180,47 @@ The caller:
180
180
struct async variable;
181
181
2. initializes .proc and .data;
182
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
185
6. calls finish_async().
186
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
+
187
215
The function pointer in .proc has the following signature:
188
216
189
- int proc(int fd , void *data);
217
+ int proc(int in, int out , void *data);
190
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.
194
224
195
225
. data is the value that the caller has specified in the .data member
196
226
of struct async.
@@ -205,8 +235,8 @@ because this facility is implemented by a pipe to a forked process on
205
235
UNIX, but by a thread in the same address space on Windows:
206
236
207
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.
210
240
211
241
. It must not change the program's state that the caller of the
212
242
facility also uses.
0 commit comments