Skip to content
Welcome to the new CppUtils documentation!

High-level RAII unidirectional anonymous IPC pipe channel with typed operations and timeout polling.

explicit PipeChannel::PipeChannel(bool nonBlocking = false);

Constructs an IPC pipe channel with close-on-exec (O_CLOEXEC) semantics.

ParameterDescription
nonBlockingWhen true, sets O_NONBLOCK on both descriptor ends.
PipeChannel::PipeChannel(const PipeChannel&) = delete;
PipeChannel& PipeChannel::operator=(const PipeChannel&) = delete;
PipeChannel::PipeChannel(PipeChannel&&) noexcept = default;
PipeChannel& PipeChannel::operator=(PipeChannel&&) noexcept = default;
PipeChannel::~PipeChannel() = default;
auto PipeChannel::closeRead() -> void;

Closes the read end of the pipe channel.

auto PipeChannel::closeWrite() -> void;

Closes the write end of the pipe channel.

[[nodiscard]] auto PipeChannel::readDescriptor() const noexcept -> int;

Returns the raw file descriptor for the read end, or -1 if closed.

[[nodiscard]] auto PipeChannel::writeDescriptor() const noexcept -> int;

Returns the raw file descriptor for the write end, or -1 if closed.

auto PipeChannel::write(std::span<const std::byte> bytes) -> std::size_t;

Writes a contiguous byte span into the channel.

ParameterDescription
bytesData bytes to transmit.

Returns: Total number of bytes written, or 0 if descriptor is closed.

auto PipeChannel::write(std::string_view text) -> std::size_t;

Writes a text string into the channel.

ParameterDescription
textCharacter string view to transmit.

Returns: Total number of bytes written.

auto PipeChannel::writeObject(const Type::TriviallyCopyable auto& value) -> void;

Writes a trivially copyable object directly into the channel.

ParameterDescription
valueObject reference to serialize as raw memory bytes.
auto PipeChannel::read(std::span<std::byte> buffer) -> std::size_t;

Reads up to buffer.size() bytes from the channel into the provided buffer.

ParameterDescription
bufferWritable destination byte buffer.

Returns: Number of bytes read(0 when the write end is closed or on end-of-stream).

auto PipeChannel::readObject(Type::TriviallyCopyable auto& value) -> bool;

Reads a complete trivially copyable object from the channel.

ParameterDescription
valueDestination object reference populated from raw bytes.

Returns: True if the complete object was read; false on premature EOF.

[[nodiscard]] auto PipeChannel::readAll() -> std::string;

Reads all remaining bytes from the channel until end-of-file.

Returns: Complete string containing all received bytes.

[[nodiscard]] auto PipeChannel::waitForData(Chrono::Duration auto timeout) const -> bool;

Waits for incoming data or pipe hangup until the specified timeout expires.

ParameterDescription
timeoutMaximum duration to wait.

Returns: True if data is available or hangup occurred; false on timeout or error.