subprocess::descriptor class

Abstracts file descriptors.

Member functions of this class and its descendents wrap syscalls to commonly used file descriptor functions.

As a user, you can derive from this class to implement your own custom descriptors.

Derived classes

class file_descriptor virtual
Wraps a descriptor mapping to a file on the disc.
class idescriptor virtual
Adds read ability to descriptor.
class odescriptor virtual
Adds write ability to descriptor.

Constructors, destructors, conversion operators

descriptor() defaulted
descriptor(int fd) explicit
descriptor(const descriptor&) defaulted
descriptor(descriptor&&) defaulted noexcept
~descriptor() defaulted virtual

Public functions

auto operator=(const descriptor&) -> descriptor& defaulted
auto operator=(descriptor&&) -> descriptor& defaulted noexcept
auto fd() const -> int
Returns the encapsulated file descriptor.
auto closable() const -> bool virtual
Marks whether the subprocess should close the FD.
void open() virtual
Initialize call before the process runs.
void close() virtual
Tear down the descriptor.

Protected variables

int fd_

Function documentation

int subprocess::descriptor::fd() const

Returns the encapsulated file descriptor.

Returns int OS-level file descriptor for subprocess I/O

The return value of fd() is used by subprocess::process and sent to child processes. This is the fd() that the process will read/write from.

bool subprocess::descriptor::closable() const virtual

Marks whether the subprocess should close the FD.

Returns true The subprocess should close the FD

void subprocess::descriptor::open() virtual

Initialize call before the process runs.

open() is called by subprocess::execute() right before spawning the child process. This is the function to write for the set up of your I/O from the process.

void subprocess::descriptor::close() virtual

Tear down the descriptor.

close() is called by subprocess::execute() after the process is spawned, but before waiting. This should ideally be the place where you should tear down the constructs that were required for process I/O.