Very Simple Cross-Platform Library
Public Member Functions | Private Member Functions | Private Attributes | List of all members
hu::varadiistvan::scpl::io::BlockingStream Class Reference

#include <BlockingStream.h>

Inheritance diagram for hu::varadiistvan::scpl::io::BlockingStream:
hu::varadiistvan::scpl::io::Failable hu::varadiistvan::scpl::io::DataStream

Public Member Functions

 BlockingStream (BufferedStream &stream)
 
 operator bool () const
 
void interrupt ()
 
bool isInterrupted ()
 
bool read (void *dest, size_t length)
 
bool skip (size_t length)
 
bool write (const void *src, size_t length)
 
bool flush ()
 
- Public Member Functions inherited from hu::varadiistvan::scpl::io::Failable
 Failable ()
 
bool failed () const
 
errorCode_t getErrorCode () const
 
void repair ()
 

Private Member Functions

bool fill ()
 
bool checkInterrupted ()
 

Private Attributes

BufferedStreamstream
 
WaitableEvent event
 
bool interrupted
 
size_t readingOffset
 
bool eof
 

Additional Inherited Members

- Protected Member Functions inherited from hu::varadiistvan::scpl::io::Failable
void setErrorCode (errorCode_t ec)
 

Detailed Description

Wrapper for a buffered stream, which an event and provides blocking, but interruptible read() and write() operations.

The class is designed in a way, that it expects its constructed instances to be called only from a single thread at a time, except for the interrupt() function, which may be called from another thread anytime.

Definition at line 55 of file BlockingStream.h.

Constructor & Destructor Documentation

◆ BlockingStream()

hu::varadiistvan::scpl::io::BlockingStream::BlockingStream ( BufferedStream stream)
inline

Construct the blocking stream for the given buffered stream.

The stream must have a waiter which is used for waiting.

Definition at line 156 of file BlockingStream.h.

Member Function Documentation

◆ checkInterrupted()

bool BlockingStream::checkInterrupted ( )
inlineprivate

Check for the stream being interrupted.

Returns
if the stream is interrupted, false otherwise

Definition at line 48 of file BlockingStream.cc.

◆ fill()

bool BlockingStream::fill ( )
private

Fill the buffer with data from the stream.

Definition at line 143 of file BlockingStream.cc.

◆ flush()

bool BlockingStream::flush ( )

Flush anything written so far into the buffer, but not to the underlying stream.

Returns
whether the operation has succeeded.

Definition at line 120 of file BlockingStream.cc.

◆ interrupt()

void hu::varadiistvan::scpl::io::BlockingStream::interrupt ( )
inline

Interrupt the stream. Pending or future read and write calls will return indicating error. The isInterrupted() function can be used to check if the stream was interrupted or not.

Definition at line 174 of file BlockingStream.h.

◆ isInterrupted()

bool hu::varadiistvan::scpl::io::BlockingStream::isInterrupted ( )
inline

Indicate if the stream is interrupted or not.

Definition at line 181 of file BlockingStream.h.

◆ operator bool()

hu::varadiistvan::scpl::io::BlockingStream::operator bool ( ) const
inline

Determine if the stream has neither failed nor been interrupted.

Definition at line 167 of file BlockingStream.h.

◆ read()

bool BlockingStream::read ( void *  dest,
size_t  length 
)

Read the given number of bytes into the given buffer.

Returns
if the reading has succeeded

Definition at line 62 of file BlockingStream.cc.

◆ skip()

bool BlockingStream::skip ( size_t  length)

Skip the given number of bytes.

Definition at line 83 of file BlockingStream.cc.

◆ write()

bool BlockingStream::write ( const void *  src,
size_t  length 
)

Write the given number of bytes from the given buffer. The data may not be written to the underlying stream fully, so if you want to make sure that it is sent, call flush() afterwards.

Returns
true on success, false on error.

Definition at line 101 of file BlockingStream.cc.

Member Data Documentation

◆ eof

bool hu::varadiistvan::scpl::io::BlockingStream::eof
private

Indicate if the end-of-file has been reached while reading.

Definition at line 81 of file BlockingStream.h.

◆ event

WaitableEvent hu::varadiistvan::scpl::io::BlockingStream::event
private

The waitable event.

Definition at line 66 of file BlockingStream.h.

◆ interrupted

bool hu::varadiistvan::scpl::io::BlockingStream::interrupted
private

Indicate if we are interrupted.

Definition at line 71 of file BlockingStream.h.

◆ readingOffset

size_t hu::varadiistvan::scpl::io::BlockingStream::readingOffset
private

The offset in the buffer of the reading stream.

Definition at line 76 of file BlockingStream.h.

◆ stream

BufferedStream& hu::varadiistvan::scpl::io::BlockingStream::stream
private

The buffered stream used.

Definition at line 61 of file BlockingStream.h.


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