An immutable buffer that could be used as a source.
More...
#include <read_buffer.hpp>
List of all members.
Detailed Description
An immutable buffer that could be used as a source.
The read_buffer class provides a source implementation that reads from a const_buffer.
Constructor & Destructor Documentation
hamcast::util::read_buffer::read_buffer |
( |
const_buffer & |
cb |
) |
|
Swaps cb
with the internal buffer.
- Parameters:
-
hamcast::util::read_buffer::read_buffer |
( |
size_type |
buf_size, |
|
|
const void * |
buf | |
|
) |
| | |
hamcast::util::read_buffer::read_buffer |
( |
size_type |
buf_size, |
|
|
void * |
buf, |
|
|
bool |
ownership | |
|
) |
| | |
Constructs the internal const_buffer with buf_size
, buf
and ownership
.
- Parameters:
-
| buf_size | The size of buf . |
| buf | The C-buffer. |
| ownership | Denotes if this object should take ownership of buf . |
- See also:
- const_buffer::const_buffer(size_type, void*, bool)
- Warning:
buf
must stay valid for the whole lifetime of this object if ownership
== false
.
hamcast::util::read_buffer::read_buffer |
( |
std::pair< size_type, void * > |
buf, |
|
|
bool |
ownership | |
|
) |
| | |
Constructs the internal const_buffer with buf
and ownership
.
- Parameters:
-
| buf | The C-buffer and its size as std::pair. |
| ownership | Denotes if this object should take ownership of buf . |
- See also:
- const_buffer::const_buffer(size_type, void*, bool)
- Parameters:
-
| ownership | Denotes if this object should take ownership of buf . |
Member Function Documentation
size_t hamcast::util::read_buffer::available |
( |
|
) |
const |
Get the number of available (unread) bytes.
- Returns:
- The number of bytes that could be read before
std::ios_base::failure
is thrown.
void hamcast::util::read_buffer::close |
( |
|
) |
[virtual] |
bool hamcast::util::read_buffer::closed |
( |
|
) |
const [virtual] |
Check if the data channel is closed.
- Returns:
true
if this
is closed for read/write operations; otherwise false
.
Implements hamcast::util::closeable.
void hamcast::util::read_buffer::read |
( |
size_t |
buf_size, |
|
|
void * |
buf | |
|
) |
| | [virtual] |
Read buf_size
bytes from the data source. This function blocks until enough bytes are available and throws and exception if the source becomes unreadable before buf_size
bytes are read.
- Parameters:
-
| buf_size | The size of buf . |
| buf | The target buffer. |
- Precondition:
- lock_read() was called
- Exceptions:
-
| std::ios_base::failure | on errors during read (e.g. if the source is closed) |
Implements hamcast::util::source.
size_t hamcast::util::read_buffer::read_some |
( |
size_t |
buf_size, |
|
|
void * |
buf | |
|
) |
| | [virtual] |
Read up to buf_size
bytes from the data source and store the bytes in buf
. A closed source always returns 0.
- Parameters:
-
| buf_size | The size of buf . |
| buf | The target buffer. |
- Returns:
- The number of readed bytes (might be <
buf_size
).
- Precondition:
- lock_read() was called
- Exceptions:
-
| std::ios_base::failure | on errors during read. |
Implements hamcast::util::source.
bool hamcast::util::read_buffer::wait_for_data |
( |
long |
seconds, |
|
|
long |
microseconds | |
|
) |
| | [virtual] |
Wait until this source becomes "ready" or until a timeout occurs.
- Parameters:
-
| seconds | The seconds part of the maximum block time. |
| microseconds | The microseconds part of the maximum block time. |
- Returns:
true
if there is data to read; otherwise false
- Precondition:
- lock_read() was called
- Exceptions:
-
| std::ios_base::failure | if the source becomes closed |
Implements hamcast::util::source.
The documentation for this class was generated from the following files:
- hamcast/util/read_buffer.hpp
- src/read_buffer.cpp