xorp

BufferedAsyncReader Class Reference

Inheritance diagram for BufferedAsyncReader:
NONCOPYABLE

List of all members.

Classes

struct  Config

Public Types

enum  Event { DATA = 1, OS_ERROR = 2, END_OF_FILE = 3 }
typedef XorpCallback4< void,
BufferedAsyncReader *, Event,
uint8_t *, size_t >::RefPtr 
Callback

Public Member Functions

 BufferedAsyncReader (EventLoop &e, XorpFd fd, size_t reserve_bytes, const Callback &cb, int priority=XorpTask::PRIORITY_DEFAULT)
 Constructor.
bool set_trigger_bytes (size_t bytes)
 Set threshold for event notification.
size_t trigger_bytes () const
 Get the current threshold for event notification.
bool dispose (size_t bytes)
 Acknowledge data at the start of the buffer is finished with.
bool set_reserve_bytes (size_t bytes)
 Set reserve for maximum amount of data to receive.
size_t reserve_bytes () const
 Get reserve for maximum amount of data to receive.
size_t available_bytes () const
 Get the number of currently available bytes.
int error () const
void start ()
 Start.
void stop ()
 Stop.
virtual string toString () const

Private Member Functions

void io_event (XorpFd fd, IoEventType type)
void announce_event (Event e)
void provision_trigger_bytes ()

Private Attributes

Config _config
EventLoop_eventloop
XorpFd _fd
Callback _cb
vector< uint8_t > _buffer
XorpTimer _ready_timer
int _last_error
int _priority

Constructor & Destructor Documentation

BufferedAsyncReader::BufferedAsyncReader ( EventLoop e,
XorpFd  fd,
size_t  reserve_bytes,
const Callback &  cb,
int  priority = XorpTask::PRIORITY_DEFAULT 
)

Constructor.

Parameters:
ethe eventloop.
fdthe file descriptor.
reserve_bytesthe number of bytes to reserve in the data buffer.
cbthe callback to invoke.
prioritythe task priority for the eventloop operations.

Member Function Documentation

bool BufferedAsyncReader::dispose ( size_t  bytes)

Acknowledge data at the start of the buffer is finished with.

Typically, a consumer would call this from within their callback to say this number of bytes has been processed and can be discarded.

Parameters:
bytesthe number of bytes to dispose.
Returns:
true on success, false if bytes is larger than the number of available bytes.
bool BufferedAsyncReader::set_reserve_bytes ( size_t  bytes)

Set reserve for maximum amount of data to receive.

Parameters:
bytesthe number of bytes to reserve.
Returns:
true on success, false if error.
bool BufferedAsyncReader::set_trigger_bytes ( size_t  bytes)

Set threshold for event notification.

Only when this threshold is reached the consumers callback invoked. If more data is already available, then the event notification will be triggered through a 0 second timer. This provides an opportunity for other tasks to run.

Calling this method may cause the internal buffer state to change. If it is called from within a consumer callback, then the buffer pointer may become invalid and dereferencing the pointer should be avoided.

Parameters:
bytesthe number of threshold bytes.
Returns:
true on success, false if bytes is larger than reserve.
void BufferedAsyncReader::start ( )

Start.

Start asynchrous reads.

void BufferedAsyncReader::stop ( )

Stop.

Stop asynchrous reading.


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations