UCILoader 1.1.2
Small C++ library that allows user to connect to a chess engines via UCI protocol.
Loading...
Searching...
No Matches
UCILoader::AbstractPipeWriter Class Referenceabstract

Abstract interface for writing to a pipe. More...

#include <AbstractPipe.h>

Inherited by UnixPipeWriter, and WindowsPipeWriter.

Public Member Functions

virtual ~AbstractPipeWriter () noexcept
 Virtual destructor for proper cleanup of derived classes.
 
virtual void write (const char *buffer, size_t buffer_size)=0
 Write data to the pipe, blocking until complete.
 
virtual bool isOpen () const =0
 Check if the pipe is currently open.
 

Detailed Description

Abstract interface for writing to a pipe.

Provides an abstraction for writing data to a pipe. This interface is implemented by platform-specific writers:

  • Windows: WinPipeWriter
  • Unix/Linux: UnixPipeWriter

The write() method is designed to write all requested bytes or throw an exception. It differs from poll() in that it always writes the complete buffer or fails.

Important Notes:

  • write() is blocking: it will not return until all data is written
  • All bytes are guaranteed to be written, or PipeClosedException is thrown
  • isOpen() check does not prevent concurrent closure from throwing PipeClosedException
  • Useful for sending complete messages to processes
See also
AbstractPipeReader for the reading counterpart

Member Function Documentation

◆ isOpen()

virtual bool UCILoader::AbstractPipeWriter::isOpen ( ) const
pure virtual

Check if the pipe is currently open.

Returns
True if the pipe appears to be open, false if it's closed
Warning
This check is not race-condition safe. The pipe may be closed after this check returns true but before the next write() call. Use exception handling for true race-safe closure detection.

◆ write()

virtual void UCILoader::AbstractPipeWriter::write ( const char *  buffer,
size_t  buffer_size 
)
pure virtual

Write data to the pipe, blocking until complete.

Parameters
bufferPointer to the data to write
buffer_sizeNumber of bytes to write
Exceptions
PipeClosedExceptionif the pipe is closed or broken

This method guarantees that either:

  1. All buffer_size bytes are written to the pipe, or
  2. PipeClosedException is thrown

The method blocks until the complete buffer is written. It's suitable for sending UCI commands and other structured messages that must be transmitted completely.

Exception Safety: If PipeClosedException is thrown, the pipe is broken and should not be used further. Some or all of the data may have been written before the exception.

Typical Usage:

std::string command = "uci\n";
try {
writer->write(command.c_str(), command.size());
} catch (const PipeClosedException&) {
std::cerr << "Engine pipe closed" << std::endl;
}
Exception thrown when a pipe operation fails due to pipe closure.
Definition: AbstractPipe.h:21

The documentation for this class was generated from the following file: