enum Event { DATA = 1, ERROR_CHECK_ERRNO = 2, END_OF_FILE = 3 } | Event |
typedef XorpCallback4<void, BufferedAsyncReader*, Event, uint8_t*, size_t>::RefPtr Callback | Callback |
BufferedAsyncReader (EventLoop& e,
int fd,
size_t reserve_bytes,
const Callback& cb)
| BufferedAsyncReader |
Constructor.
Parameters:
e | the eventloop. |
fd | the file descriptor. |
reserve_bytes | the number of bytes to reserve in the data buffer. |
cb | the callback to invoke. |
~BufferedAsyncReader ()
| ~BufferedAsyncReader |
bool set_trigger_bytes (size_t bytes)
| set_trigger_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:
bytes | the number of threshold bytes. |
Returns: true on success, false if bytes is larger than reserve.
size_t trigger_bytes ()
| trigger_bytes |
[const]
Get the current threshold for event notification.
bool dispose (size_t bytes)
| dispose |
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:
bytes | the number of bytes to dispose. |
Returns: true on success, false if bytes is larger than the number of available bytes.
bool set_reserve_bytes (size_t bytes)
| set_reserve_bytes |
Set reserve for maximum amount of data to receive.
Parameters:
bytes | the number of bytes to reserve. |
Returns: true on success, false if error.
size_t reserve_bytes ()
| reserve_bytes |
[const]
Get reserve for maximum amount of data to receive.
size_t available_bytes ()
| available_bytes |
[const]
Get the number of currently available bytes.
void start ()
| start |
Start.
void stop ()
| stop |
Stop.
Stop asynchrous reading.