Skip to content

Commit 36ec10a

Browse files
committed
Add API-level documentation for the piped_processt class.
1 parent 881af34 commit 36ec10a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

doc/API/util/piped_process.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `src/util/piped_process.{cpp, h}`
2+
3+
To utilise the `piped_process` API for interprocess communication with any binary:
4+
5+
* You need to initialise it by calling the construct `piped_processt("binary with args", message_handler)`.
6+
* A `message_handlert` should usually be present down from the call stack at
7+
the place you want to call `piped_process` from.
8+
* If IPC fails during child process creation, you will get a `system_exceptiont`.
9+
* If the `binary command` does not correspond to a binary in the `$PATH` or is
10+
not a path to a binary itself, you'll read a string `Launching <xyz> failed with error: <error>`
11+
when you attempt to `receive()` output from it.
12+
* To close the underlying child process, you need a call to the destructor - `~piped_processt()`.
13+
* This will occur automatically when the `piped_processt` goes out of scope if
14+
it's locally scoped.
15+
* Use `send()` to send a string message to the child process' input.
16+
* This returns a `send_responset`, an enum that shows whether the
17+
sending of the message through the pipe succeeded or failed.
18+
* Use `receive()` to read a string message from the child process' output.
19+
* It's always a good idea to guard a call to `receive` with `can_receive()`,
20+
so that receiving is blocked until there's something to receive.
21+
* `can_receive` with no arguments will default to infinite wait time for piped
22+
process readiness.
23+
* Alternatively, you can guard the call to `receive` with `wait_receivable`.
24+
`wait_receivable` takes an integer value representing `microseconds` of waiting
25+
time between checks for pipe readiness.

0 commit comments

Comments
 (0)