hamcast  Version 0.7
Public Member Functions | List of all members
hamcast::util::read_buffer Class Reference

#include <read_buffer.hpp>

Inheritance diagram for hamcast::util::read_buffer:
hamcast::util::source hamcast::util::closeable hamcast::ref_counted

Public Member Functions

 read_buffer (const_buffer &cb)
 
 read_buffer (size_type buf_size, const void *buf)
 
 read_buffer (size_type buf_size, void *buf, bool ownership)
 
 read_buffer (std::pair< size_type, void * > buf, bool ownership)
 
bool wait_for_data (long seconds, long microseconds)
 
size_t read_some (size_t buf_size, void *buf)
 
size_t available () const
 
virtual void read (size_t buf_size, void *buf)
 
virtual void close ()
 
virtual bool closed () const
 
- Public Member Functions inherited from hamcast::ref_counted
long ref_count ()
 

Additional Inherited Members

- Static Public Member Functions inherited from hamcast::ref_counted
static void add_ref (ref_counted *rc)
 
static void release (ref_counted *rc)
 
- Protected Member Functions inherited from hamcast::ref_counted
 ref_counted ()
 
void ref ()
 
bool deref ()
 

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
cbWill be swapped with the internal const_buffer.
hamcast::util::read_buffer::read_buffer ( size_type  buf_size,
const void *  buf 
)

Constructs the internal const_buffer with buf_size and buf.

Parameters
buf_sizeThe size of buf.
bufThe const C-buffer.
See Also
const_buffer::const_buffer(size_type, const void*)
Warning
buf must stay valid for the whole lifetime of this object.
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_sizeThe size of buf.
bufThe C-buffer.
ownershipDenotes 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
bufThe C-buffer and its size as std::pair.
ownershipDenotes if this object should take ownership of buf.
See Also
const_buffer::const_buffer(size_type, void*, bool)
Parameters
ownershipDenotes 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

Close the data channel.

Implements hamcast::util::closeable.

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_sizeThe size of buf.
bufThe target buffer.
Precondition
lock_read() was called
Exceptions
std::ios_base::failureon 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_sizeThe size of buf.
bufThe target buffer.
Returns
The number of readed bytes (might be < buf_size).
Precondition
lock_read() was called
Exceptions
std::ios_base::failureon 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
secondsThe seconds part of the maximum block time.
microsecondsThe 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::failureif the source becomes closed

Implements hamcast::util::source.


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