Spawns a child process and exposes its stdin/stdout/stderr as async handles. More...
#include <pipe.hpp>
Public Member Functions | |
| template<typename TPoller > | |
| TPipe (TPoller &poller, const std::string &exe, const std::vector< std::string > &args, bool stderrToStdout=false) | |
Spawns exe with args and wires up async I/O handles. | |
| int | Pid () const |
| Returns the child's process ID. | |
| void | CloseRead () |
| Closes the read end of the child's stdout pipe. | |
| void | CloseWrite () |
| Closes the write end of the child's stdin pipe, sending EOF to the child. | |
| void | CloseErr () |
| Closes the read end of the child's stderr pipe. | |
| int | Wait () |
| Waits for the child process to exit and returns its exit status. | |
| TFuture< ssize_t > | ReadSome (void *buffer, size_t size) |
Reads up to size bytes from the child's stdout. | |
| TFuture< ssize_t > | ReadSomeErr (void *buffer, size_t size) |
Reads up to size bytes from the child's stderr. | |
| TFuture< ssize_t > | WriteSome (const void *buffer, size_t size) |
Writes up to size bytes to the child's stdin. | |
Spawns a child process and exposes its stdin/stdout/stderr as async handles.
Linux/macOS only (#ifndef _WIN32). The constructor forks immediately; the child runs exe with args. The parent side owns three async file handles:
WriteSome → child's stdinReadSome → child's stdoutReadSomeErr → child's stderr (unless stderrToStdout = true)Call CloseWrite() to send EOF to the child, then Wait() to reap it.
|
inline |
Spawns exe with args and wires up async I/O handles.
| poller | Event-loop poller used for async I/O on the pipe fds. |
| exe | Absolute path to the executable. |
| args | Arguments passed to the executable (argv[1..]). |
| stderrToStdout | If true, child stderr is redirected into stdout (ReadSomeErr becomes unavailable). |
| TFuture< ssize_t > NNet::TPipe::ReadSome | ( | void * | buffer, |
| size_t | size | ||
| ) |
Reads up to size bytes from the child's stdout.
Returns bytes read (>0), 0 on EOF (child closed stdout), or a negative retry hint on transient errors.
| TFuture< ssize_t > NNet::TPipe::ReadSomeErr | ( | void * | buffer, |
| size_t | size | ||
| ) |
Reads up to size bytes from the child's stderr.
Only valid when stderrToStdout = false. Returns bytes read (>0), 0 on EOF, or a negative retry hint.
| int NNet::TPipe::Wait | ( | ) |
Waits for the child process to exit and returns its exit status.
Blocks the calling thread (via waitpid). Call after the child has finished or after sending it a signal.
waitpid (use WEXITSTATUS to extract the code). | TFuture< ssize_t > NNet::TPipe::WriteSome | ( | const void * | buffer, |
| size_t | size | ||
| ) |
Writes up to size bytes to the child's stdin.
Returns bytes written (>0), 0 if the child closed stdin, or a negative retry hint on transient errors.