Aller au contenu
Bienvenue sur la nouvelle documentation de CppUtils !

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.

ParamètreDescription
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.

ParamètreDescription
bytesData bytes to transmit.

Retourne : 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.

ParamètreDescription
textCharacter string view to transmit.

Retourne : Total number of bytes written.

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

Writes a trivially copyable object directly into the channel.

ParamètreDescription
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.

ParamètreDescription
bufferWritable destination byte buffer.

Retourne : 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.

ParamètreDescription
valueDestination object reference populated from raw bytes.

Retourne : 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.

Retourne : 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.

ParamètreDescription
timeoutMaximum duration to wait.

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