@@ -64,8 +64,8 @@ The functions above do the following:
6464`start_async`::
6565
6666 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.
6969
7070`finish_async`::
7171
@@ -135,7 +135,7 @@ stderr as follows:
135135
136136 .in: The FD must be readable; it becomes child's stdin.
137137 .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 .
139139
140140 The specified FD is closed by start_command(), even if it fails to
141141 run the sub-process!
@@ -180,17 +180,47 @@ The caller:
180180 struct async variable;
1811812. initializes .proc and .data;
1821823. 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;
1851856. calls finish_async().
186186
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+
187215The function pointer in .proc has the following signature:
188216
189- int proc(int fd , void *data);
217+ int proc(int in, int out , void *data);
190218
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.
194224
195225. data is the value that the caller has specified in the .data member
196226 of struct async.
@@ -205,8 +235,8 @@ because this facility is implemented by a pipe to a forked process on
205235UNIX, but by a thread in the same address space on Windows:
206236
207237. 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.
210240
211241. It must not change the program's state that the caller of the
212242 facility also uses.
0 commit comments