Very Simple Cross-Platform Library
|
#include <BlockingStream.h>
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 | |
BufferedStream & | stream |
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) |
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.
|
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.
|
inlineprivate |
Check for the stream being interrupted.
Definition at line 48 of file BlockingStream.cc.
|
private |
Fill the buffer with data from the stream.
Definition at line 143 of file BlockingStream.cc.
bool BlockingStream::flush | ( | ) |
Flush anything written so far into the buffer, but not to the underlying stream.
Definition at line 120 of file BlockingStream.cc.
|
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.
|
inline |
Indicate if the stream is interrupted or not.
Definition at line 181 of file BlockingStream.h.
|
inline |
Determine if the stream has neither failed nor been interrupted.
Definition at line 167 of file BlockingStream.h.
bool BlockingStream::read | ( | void * | dest, |
size_t | length | ||
) |
Read the given number of bytes into the given buffer.
Definition at line 62 of file BlockingStream.cc.
bool BlockingStream::skip | ( | size_t | length | ) |
Skip the given number of bytes.
Definition at line 83 of file BlockingStream.cc.
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.
Definition at line 101 of file BlockingStream.cc.
|
private |
Indicate if the end-of-file has been reached while reading.
Definition at line 81 of file BlockingStream.h.
|
private |
The waitable event.
Definition at line 66 of file BlockingStream.h.
|
private |
Indicate if we are interrupted.
Definition at line 71 of file BlockingStream.h.
|
private |
The offset in the buffer of the reading stream.
Definition at line 76 of file BlockingStream.h.
|
private |
The buffered stream used.
Definition at line 61 of file BlockingStream.h.