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

Abstract interface for non-blocking reading from a pipe. More...

#include <AbstractPipe.h>

Inherited by UnixPipeReader, and WindowsPipeReader.

Public Member Functions

virtual ~AbstractPipeReader () noexcept
 Virtual destructor for proper cleanup of derived classes.
 
virtual size_t poll (char *buffer, size_t buffer_size)=0
 Poll for available data from the pipe without blocking.
 
virtual bool isOpen () const =0
 Check if the pipe is currently open.
 

Detailed Description

Abstract interface for non-blocking reading from a pipe.

Provides an abstraction for reading data from a pipe in a non-blocking manner. This interface is implemented by platform-specific readers:

  • Windows: WinPipeReader
  • Unix/Linux: UnixPipeReader

The poll() method reads available data without blocking. If no data is available, it returns 0. If the pipe is closed, PipeClosedException is thrown.

Important Notes:

  • poll() is non-blocking: it returns immediately with whatever data is available
  • isOpen() check does not prevent concurrent closure from throwing PipeClosedException
  • This interface is typically not used directly; use PipeScanner for line-based reading
See also
PipeScanner for line-based reading abstraction
AbstractPipeWriter for the writing counterpart

Member Function Documentation

◆ isOpen()

virtual bool UCILoader::AbstractPipeReader::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 poll() call. Use exception handling for true race-safe closure detection.

◆ poll()

virtual size_t UCILoader::AbstractPipeReader::poll ( char *  buffer,
size_t  buffer_size 
)
pure virtual

Poll for available data from the pipe without blocking.

Parameters
bufferPointer to memory where data will be written
buffer_sizeMaximum number of bytes to read
Returns
Number of bytes actually read (0 to buffer_size)
Exceptions
PipeClosedExceptionif the pipe is closed or broken

This method is non-blocking:

  • Returns immediately with whatever data is available (0 or more bytes)
  • Returns 0 if no data is currently available, not if pipe is closed
  • The returned data is copied into the provided buffer

Exception Safety: If PipeClosedException is thrown, the pipe is corrupted or closed and should not be used further. Pre-checking isOpen() does not guarantee safety against concurrent closure.

Typical Usage Pattern: Use PipeScanner which wraps this method to provide blocking line-based reading.


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