libcommonc++
0.7
|
An unbuffered I/O stream. More...
#include <Stream.h++>
Public Member Functions | |
virtual | ~Stream () |
Destructor. More... | |
virtual size_t | read (ByteBuffer &buffer) |
Read data from the stream into a ByteBuffer. More... | |
virtual size_t | read (CharBuffer &buffer) |
Read data from the stream into a CharBuffer. More... | |
template<typename T > | |
size_t | read (Buffer< T > &buffer, size_t &partial) |
Read data from the stream into a Buffer of arbitrary type. More... | |
virtual size_t | read (byte_t *buffer, size_t buflen) |
Read data from the stream into a raw buffer. More... | |
size_t | read (byte_t *buffer, size_t buflen, int64_t offset, AsyncIOTask &task) |
Read data asynchronously from the stream into a raw buffer. More... | |
size_t | read (ByteBuffer &buffer, int64_t offset, AsyncIOTask &task) |
Read data asynchronously from the stream into a Buffer. More... | |
size_t | write (const byte_t *buffer, size_t buflen, int64_t offset, AsyncIOTask &task) |
Write data asynchronously to the stream from a raw buffer. More... | |
size_t | write (ByteBuffer &buffer, int64_t offset, AsyncIOTask &task) |
Write data asynchronously to the stream from a Buffer. More... | |
virtual size_t | readFully (ByteBuffer &buffer, size_t count=0) |
Read data from the stream into a ByteBuffer, until either the buffer is full or an error or timeout occurs. More... | |
virtual size_t | readFully (CharBuffer &buffer, size_t count=0) |
Read data from the stream into a CharBuffer, until either the buffer is full or an error or timeout occurs. More... | |
template<typename T > | |
size_t | readFully (Buffer< T > &buffer, size_t &partial) |
Read data from the stream into a Buffer of arbitrary type, until either the buffer is full or an error or timeout occurs. More... | |
virtual size_t | readFully (byte_t *buffer, size_t buflen) |
Read data from the stream into a raw buffer, until either the buffer is full or an error or timeout occurs. More... | |
virtual size_t | read (MemoryBlock *vec, uint_t count) |
Read data from the stream into a series of I/O buffers. More... | |
virtual size_t | write (ByteBuffer &buffer) |
Write data to the stream from a ByteBuffer. More... | |
virtual size_t | write (CharBuffer &buffer) |
Write data to the stream from a CharBuffer. More... | |
template<typename T > | |
size_t | write (Buffer< T > &buffer, size_t &partial) |
Write data to the stream from a Buffer of arbitrary type. More... | |
virtual size_t | write (const byte_t *buffer, size_t buflen) |
Write data to the stream from a raw buffer, until either the entire buffer is written or an error or timeout occurs. More... | |
virtual size_t | writeFully (ByteBuffer &buffer) |
Write data to the stream from a ByteBuffer, until either the entire buffer is written or an error or timeout occurs. More... | |
virtual size_t | writeFully (CharBuffer &buffer) |
Write data to the stream from a CharBuffer, until either the entire buffer is written or an error or timeout occurs. More... | |
template<typename T > | |
size_t | writeFully (Buffer< T > &buffer, size_t &partial) |
Write data to the stream from a Buffer of arbitrary type, until either the entire buffer is written or an error or timeout occurs. More... | |
virtual size_t | writeFully (const byte_t *buffer, size_t buflen) |
Write data to the stream from a raw buffer. More... | |
virtual size_t | write (const MemoryBlock *vec, uint_t count) |
Write data to the stream from a series of I/O buffers. More... | |
virtual int64_t | seek (int64_t offset, SeekMode mode=SeekAbsolute) |
Reposition the seek pointer in the stream. More... | |
virtual int64_t | tell () |
Get the current (absolute) offset of the seek pointer. More... | |
bool | isOpen () const |
Test if the stream is open. More... | |
bool | isSeekable () const |
Test if the stream supports seeking. More... | |
bool | isReadable () const |
Test if the stream can be read from. More... | |
bool | isWritable () const |
Test if the stream can be written to. More... | |
bool | isFullDuplex () const |
Test if the stream is full-duplex (i.e., supports both reading and writing). More... | |
bool | isHalfDuplex () const |
Test if the stream is half-duplex (i.e., supports either reading or writing, but not both). More... | |
virtual void | close (IOMode mode=IOReadWrite) |
Close the stream for reading, writing, or both. More... | |
virtual void | setTimeout (timespan_ms_t timeout) |
Set the stream I/O timeout, in milliseconds. More... | |
timespan_ms_t | getTimeout () const |
Get the stream I/O timeout, in milliseconds. More... | |
Static Public Attributes | |
static const uint_t | MAX_IOBLOCK_COUNT = 16 |
The maximum number of I/O buffers that can be passed to the vector I/O methods. More... | |
Protected Member Functions | |
Stream () | |
Construct a new, uninitialized Stream. More... | |
Stream (FileHandle handle, bool seekable=true, bool readable=true, bool writable=true) | |
Construct a new stream. More... | |
void | _init (FileHandle handle, bool seekable, bool readable, bool writable) |
Initialize the stream for use with an open file. More... | |
Friends | |
class | Process |
An unbuffered I/O stream.
|
protected |
Construct a new stream.
handle | The handle to an open file. |
seekable | A flag indicating whether the stream is seekable. |
readable | A flag indicating whether the stream is readable. |
writable | A flag indicating whether the stream is writable. |
|
virtual |
Destructor.
|
protected |
Initialize the stream for use with an open file.
handle | The handle to an open file. |
seekable | A flag indicating whether the stream is seekable. |
readable | A flag indicating whether the stream is readable. |
writable | A flag indicating whether the stream is writable. |
|
virtual |
Close the stream for reading, writing, or both.
mode | The close mode. |
Reimplemented in StreamSocket, and StreamPipe.
|
inline |
Get the stream I/O timeout, in milliseconds.
|
inline |
Test if the stream is full-duplex (i.e., supports both reading and writing).
|
inline |
Test if the stream is half-duplex (i.e., supports either reading or writing, but not both).
|
inline |
Test if the stream is open.
|
inline |
Test if the stream can be read from.
|
inline |
Test if the stream supports seeking.
|
inline |
Test if the stream can be written to.
|
virtual |
Read data from the stream into a ByteBuffer.
buffer | The buffer to read into. |
IOException | If the end-of-file was reached or some other I/O error occurred. |
Reimplemented in StreamSocket.
|
virtual |
Read data from the stream into a CharBuffer.
buffer | The buffer to read into. |
IOException | If the end-of-file was reached or some other I/O error occurred. |
Reimplemented in StreamSocket.
|
inline |
Read data from the stream into a Buffer of arbitrary type.
If sizeof(T) is greater than 1 byte, then there can be no guarantee that the number of bytes read before a timeout or error occurs will be evenly divisible by sizeof(T). If the final element was partially read, the number of bytes of the element that were read will be stored in partial; this value should be passed unmodified to the next invocation of this method to continue reading from the appropriate offset within the partially-read element.
buffer | The buffer to read into. |
partial | The number of bytes remaining to read for a partially-read element; on return, the number of bytes read of a partially-read element, or 0 if the last element was read completely. Should be set to 0 prior to the first call to this method for a fresh buffer. |
IOException | If the end-of-file was reached or some other I/O error occurred. |
|
virtual |
Read data from the stream into a raw buffer.
buffer | The buffer to read into. |
buflen | The number of bytes to read. |
IOException | If the end-of-file was reached or some other I/O error occurred. |
Reimplemented in StreamSocket.
size_t read | ( | byte_t * | buffer, |
size_t | buflen, | ||
int64_t | offset, | ||
AsyncIOTask & | task | ||
) |
Read data asynchronously from the stream into a raw buffer.
buffer | The buffer to read into. |
buflen | The number of bytes to read. |
offset | The file offset to read from. |
task | The async I/O control block for monitoring the operation. |
IOException | If an I/O error occurred. |
size_t read | ( | ByteBuffer & | buffer, |
int64_t | offset, | ||
AsyncIOTask & | task | ||
) |
Read data asynchronously from the stream into a Buffer.
buffer | The Buffer to read into. This object must not be destroyed before the asynchronous I/O operation is completed or cancelled. |
offset | The file offset to read from. |
task | The async I/O control block for monitoring the operation. |
IOException | If an I/O error occurred. |
|
virtual |
Read data from the stream into a series of I/O buffers.
This operation is known as "vector read" or "scatter read." The buffers are read into in order. On systems that support it, the operation is performed with a single system call.
vec | An array of buffers to read into. |
count | The number of buffers in the array. |
IOException | If the end-of-file was reached or some other I/O error occurred. |
Reimplemented in StreamSocket.
|
virtual |
Read data from the stream into a ByteBuffer, until either the buffer is full or an error or timeout occurs.
buffer | The buffer to read into. |
count | The number of bytes to read. If 0 or greater than the number of bytes between the position and the limit, reads up to the limit. |
IOException | If the end-of-file was reached or some other I/O error occurred. |
|
virtual |
Read data from the stream into a CharBuffer, until either the buffer is full or an error or timeout occurs.
buffer | The buffer to read into. |
count | The number of characters to read. If 0 or greater than the number of bytes between the position and the limit, reads up to the limit. |
IOException | If the end-of-file was reached or some other I/O error occurred. |
|
inline |
Read data from the stream into a Buffer of arbitrary type, until either the buffer is full or an error or timeout occurs.
If sizeof(T) is greater than 1 byte, then there can be no guarantee that the number of bytes read before a timeout or error occurs will be evenly divisible by sizeof(T). If the final element was partially read, the number of bytes of the element that were read will be stored in partial; this value should be passed unmodified to the next invocation of this method to continue reading from the appropriate offset within the partially-read element.
buffer | The buffer to read into. |
partial | The number of bytes remaining to read for a partially-read element; on return, the number of bytes read of a partially-read element, or 0 if the last element was read completely. Should be set to 0 prior to the first call to this method for a fresh buffer. |
IOException | If the end-of-file was reached or some other I/O error occurred. |
|
virtual |
Read data from the stream into a raw buffer, until either the buffer is full or an error or timeout occurs.
buffer | The buffer to read into. |
buflen | The number of bytes to read. |
IOException | If the end-of-file was reached or some other I/O error occurred. |
|
virtual |
Reposition the seek pointer in the stream.
offset | The new offset. |
mode | The seek mode. |
IOException | If the stream does not support seeking, or if some other I/O error occurred. |
|
virtual |
Set the stream I/O timeout, in milliseconds.
A timeout of 0 indicates no timeout, and a timeout of -1 indicates infinite timeout (blocking I/O).
Reimplemented in StreamSocket, and SerialPort.
|
virtual |
Get the current (absolute) offset of the seek pointer.
IOException | If the stream does not support seeking, or if some other I/O error occurred. |
size_t write | ( | const byte_t * | buffer, |
size_t | buflen, | ||
int64_t | offset, | ||
AsyncIOTask & | task | ||
) |
Write data asynchronously to the stream from a raw buffer.
buffer | The buffer to write. |
buflen | The number of bytes to write. |
offset | The file offset to write to. |
task | The async I/O control block for monitoring the operation. |
IOException | If an I/O error occurred. |
size_t write | ( | ByteBuffer & | buffer, |
int64_t | offset, | ||
AsyncIOTask & | task | ||
) |
Write data asynchronously to the stream from a Buffer.
buffer | The Buffer to write. This object must not be destroyed before the asynchronous I/O operation is completed or cancelled. |
offset | The file offset to write to. |
task | The async I/O control block for monitoring the operation. |
IOException | If an I/O error occurred. |
|
virtual |
Write data to the stream from a ByteBuffer.
buffer | The buffer to write. |
IOException | If an I/O error occurred. |
Reimplemented in StreamSocket.
|
virtual |
Write data to the stream from a CharBuffer.
buffer | The buffer to write. |
IOException | If an I/O error occurred. |
Reimplemented in StreamSocket.
|
inline |
Write data to the stream from a Buffer of arbitrary type.
If sizeof(T) is greater than 1 byte, then there can be no guarantee that the number of bytes written before a timeout or error occurs will be evenly divisible by sizeof(T). If the final element was partially written, the number of bytes of the element that were written will be stored in partial; this value should be passed unmodified to the next invocation of this method to continue writing from the appropriate offset within the partially-written element.
buffer | The buffer to write. |
partial | The number of bytes remaining to write for a partially-written element; on return, the number of bytes written of a partially-written element, or 0 if the last element was written completely. Should be set to 0 prior to the first call to this method for a fresh buffer. |
IOException | If an I/O error occurred. |
|
virtual |
Write data to the stream from a raw buffer, until either the entire buffer is written or an error or timeout occurs.
buffer | A pointer to the buffer. |
buflen | The number of bytes to write. |
IOException | If an I/O error occurred. |
Reimplemented in StreamSocket.
|
virtual |
Write data to the stream from a series of I/O buffers.
This operation is known as "vector write" or "gather write." The buffers are written in order. On systems that support it, the operation is performed with a single system call.
vec | An array of buffers to write. |
count | The number of buffers in the array. |
IOException | If an I/O error occurred. |
Reimplemented in StreamSocket.
|
virtual |
Write data to the stream from a ByteBuffer, until either the entire buffer is written or an error or timeout occurs.
buffer | The buffer to write. |
IOException | If and I/O error occurred. |
|
virtual |
Write data to the stream from a CharBuffer, until either the entire buffer is written or an error or timeout occurs.
buffer | The buffer to write. |
IOException | If an I/O error occurred. |
|
inline |
Write data to the stream from a Buffer of arbitrary type, until either the entire buffer is written or an error or timeout occurs.
If sizeof(T) is greater than 1 byte, then there can be no guarantee that the number of bytes written before a timeout or error occurs will be evenly divisible by sizeof(T). If the final element was partially written, the number of bytes of the element that were written will be stored in partial; this value should be passed unmodified to the next invocation of this method to continue writing from the appropriate offset within the partially-written element.
buffer | The buffer to write. |
partial | The number of bytes remaining to write for a partially-written element; on return, the number of bytes written of a partially-written element, or 0 if the last element was written completely. Should be set to 0 prior to the first call to this method for a fresh buffer. |
IOException | If an I/O error occurred. |
|
virtual |
Write data to the stream from a raw buffer.
buffer | A pointer to the buffer. |
buflen | The number of bytes to write. |
IOException | If an I/O error occurred. |
|
friend |
|
static |
The maximum number of I/O buffers that can be passed to the vector I/O methods.