struct Pipe {
long long read_fd;
long long write_fd;
}Fields
Methods
Creates a new pipe in place (fills read_fd/write_fd). Returns 0 on success, -1 on failure.
Reads up to 'count' bytes from the pipe's read end into 'buf'. Returns the number of bytes read (0 means the write end was closed and the pipe is drained — EOF), or -1 on error.
Writes up to 'count' bytes from 'buf' to the pipe's write end. Returns the number of bytes written, or -1 on error.
Puts the read end into non-blocking mode (pairs with std::Reactor — await_fd(p.read_fd, SCHED_READ) once this returns 0). Returns 0 on success, -1 on failure.
Puts the write end into non-blocking mode. Returns 0 on success, -1 on failure.
Closes the read end. Safe to call once; closing twice is undefined the same way double-close(2) is on any platform.
Closes the write end. A reader blocked in read() (or awaiting SCHED_READ on read_fd) sees EOF (read() returns 0) once this runs and the pipe is drained.