#include <StreamBuffer.h>
StreamBuffer is a resizable buffer which is designed to efficiently support growing at the end of the buffer and consumption of the buffer from the front.
XXX/demmer rework to use ExpandableBuffer
Definition at line 55 of file StreamBuffer.h.
Public Member Functions | |
StreamBuffer (size_t size=DEFAULT_BUFSIZE) | |
Create a new StreamBuffer with initial size. | |
~StreamBuffer () | |
void | set_size (size_t size) |
Set the size of the buffer. | |
char * | data () |
| |
char * | start () |
| |
char * | end () |
| |
void | reserve (size_t amount) |
Reserve amount bytes in the buffer. | |
void | fill (size_t amount) |
Fill amount bytes, e.g. | |
void | consume (size_t amount) |
Consume amount bytes from the front of the buffer. | |
void | clear () |
Clear all data from the buffer. | |
size_t | size () |
Total size of the buffer, including full and empty bytes. | |
size_t | fullbytes () |
Amount of bytes stored in the stream buffer. | |
size_t | tailbytes () |
Amount of free bytes available at the end of the buffer. | |
Private Member Functions | |
void | realloc (size_t size) |
Resize buffer to size. | |
void | moveup () |
Compact buffer, moving all data up to the start of the dynamically allocated buffer, eliminating the empty space at the front. | |
Private Attributes | |
size_t | start_ |
size_t | end_ |
size_t | size_ |
char * | buf_ |
Static Private Attributes | |
static const size_t | DEFAULT_BUFSIZE = 512 |
oasys::StreamBuffer::StreamBuffer | ( | size_t | size = DEFAULT_BUFSIZE |
) |
oasys::StreamBuffer::~StreamBuffer | ( | ) |
void oasys::StreamBuffer::set_size | ( | size_t | size | ) |
Set the size of the buffer.
New size should not be smaller than size of data in the StreamBuffer.
Definition at line 71 of file StreamBuffer.cc.
References ASSERT, fullbytes(), moveup(), and realloc().
Referenced by dtn::ConnectionConvergenceLayer::reconfigure_link().
char* oasys::StreamBuffer::data | ( | ) | [inline] |
Definition at line 71 of file StreamBuffer.h.
References buf_.
Referenced by dtn::BluetoothConvergenceLayer::Connection::recv_announce(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), and dtn::BluetoothConvergenceLayer::Connection::recv_loop().
char * oasys::StreamBuffer::start | ( | ) |
Definition at line 80 of file StreamBuffer.cc.
Referenced by oasys::BufferedInput::find_nl(), oasys::BufferedOutput::flush(), oasys::BufferedInput::get_char(), dtn::BluetoothConvergenceLayer::Connection::handle_ack(), dtn::StreamConvergenceLayer::Connection::handle_ack_segment(), dtn::StreamConvergenceLayer::Connection::handle_contact_initiation(), dtn::StreamConvergenceLayer::Connection::handle_data_segment(), dtn::StreamConvergenceLayer::Connection::handle_data_todo(), dtn::BluetoothConvergenceLayer::Connection::handle_reply(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), dtn::StreamConvergenceLayer::Connection::process_data(), oasys::BufferedInput::read_bytes(), oasys::BufferedInput::read_line(), oasys::BufferedInput::read_some_bytes(), dtn::BluetoothConvergenceLayer::Connection::recv_announce(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), and dtn::BluetoothConvergenceLayer::Connection::recv_loop().
char * oasys::StreamBuffer::end | ( | ) |
Definition at line 86 of file StreamBuffer.cc.
Referenced by dtn::StreamConvergenceLayer::Connection::finish_bundle(), dtn::BluetoothConvergenceLayer::Connection::handle_reply(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), oasys::BufferedInput::read_some_bytes(), dtn::BluetoothConvergenceLayer::Connection::recv_announce(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), dtn::BluetoothConvergenceLayer::Connection::recv_loop(), dtn::StreamConvergenceLayer::Connection::send_data_todo(), dtn::StreamConvergenceLayer::Connection::send_keepalive(), dtn::StreamConvergenceLayer::Connection::send_next_segment(), dtn::StreamConvergenceLayer::Connection::send_pending_acks(), dtn::StreamConvergenceLayer::Connection::start_next_bundle(), oasys::BufferedOutput::vformat_buf(), and oasys::BufferedOutput::write().
void oasys::StreamBuffer::reserve | ( | size_t | amount | ) |
Reserve amount bytes in the buffer.
Definition at line 92 of file StreamBuffer.cc.
References fullbytes(), moveup(), realloc(), size_, start_, and tailbytes().
Referenced by dtn::CLConnection::CLConnection(), dtn::StreamConvergenceLayer::Connection::finish_bundle(), dtn::BluetoothConvergenceLayer::Connection::handle_reply(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), dtn::StreamConvergenceLayer::Connection::process_data(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), dtn::BluetoothConvergenceLayer::Connection::recv_loop(), dtn::BluetoothConvergenceLayer::Connection::send_announce(), dtn::BluetoothConvergenceLayer::Connection::send_loop(), dtn::StreamConvergenceLayer::Connection::start_next_bundle(), oasys::BufferedOutput::vformat_buf(), and oasys::BufferedOutput::write().
void oasys::StreamBuffer::fill | ( | size_t | amount | ) |
Fill amount bytes, e.g.
move the end ptr up by that amount
Definition at line 111 of file StreamBuffer.cc.
References ASSERT, end_, and tailbytes().
Referenced by dtn::StreamConvergenceLayer::Connection::finish_bundle(), dtn::BluetoothConvergenceLayer::Connection::handle_reply(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), dtn::BluetoothConvergenceLayer::Connection::recv_announce(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), dtn::BluetoothConvergenceLayer::Connection::recv_loop(), dtn::StreamConvergenceLayer::Connection::send_data_todo(), dtn::StreamConvergenceLayer::Connection::send_keepalive(), dtn::StreamConvergenceLayer::Connection::send_next_segment(), dtn::StreamConvergenceLayer::Connection::send_pending_acks(), dtn::StreamConvergenceLayer::Connection::start_next_bundle(), oasys::BufferedOutput::vformat_buf(), and oasys::BufferedOutput::write().
void oasys::StreamBuffer::consume | ( | size_t | amount | ) |
Consume amount bytes from the front of the buffer.
Definition at line 119 of file StreamBuffer.cc.
References ASSERT, end_, fullbytes(), and start_.
Referenced by oasys::BufferedOutput::flush(), oasys::BufferedInput::get_char(), dtn::BluetoothConvergenceLayer::Connection::handle_ack(), dtn::StreamConvergenceLayer::Connection::handle_ack_segment(), dtn::StreamConvergenceLayer::Connection::handle_contact_initiation(), dtn::StreamConvergenceLayer::Connection::handle_data_segment(), dtn::StreamConvergenceLayer::Connection::handle_data_todo(), dtn::StreamConvergenceLayer::Connection::handle_end_bundle(), dtn::StreamConvergenceLayer::Connection::handle_keepalive(), dtn::BluetoothConvergenceLayer::Connection::handle_reply(), dtn::StreamConvergenceLayer::Connection::handle_shutdown(), dtn::StreamConvergenceLayer::Connection::handle_start_bundle(), oasys::BufferedInput::read_bytes(), oasys::BufferedInput::read_line(), oasys::BufferedInput::read_some_bytes(), dtn::BluetoothConvergenceLayer::Connection::recv_announce(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), and dtn::BluetoothConvergenceLayer::Connection::recv_loop().
void oasys::StreamBuffer::clear | ( | ) |
Clear all data from the buffer.
Definition at line 131 of file StreamBuffer.cc.
Referenced by oasys::BufferedOutput::clear_buf().
size_t oasys::StreamBuffer::size | ( | ) | [inline] |
Total size of the buffer, including full and empty bytes.
Definition at line 92 of file StreamBuffer.h.
References size_.
Referenced by dtn::StreamConvergenceLayer::Connection::process_data(), dtn::ConnectionConvergenceLayer::reconfigure_link(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), and dtn::StreamConvergenceLayer::Connection::start_next_bundle().
size_t oasys::StreamBuffer::fullbytes | ( | ) |
Amount of bytes stored in the stream buffer.
Definition at line 137 of file StreamBuffer.cc.
Referenced by consume(), oasys::BufferedInput::eof(), oasys::BufferedInput::find_nl(), oasys::BufferedOutput::flush(), oasys::BufferedInput::get_char(), dtn::BluetoothConvergenceLayer::Connection::handle_ack(), dtn::StreamConvergenceLayer::Connection::handle_ack_segment(), dtn::StreamConvergenceLayer::Connection::handle_contact_initiation(), dtn::StreamConvergenceLayer::Connection::handle_data_segment(), dtn::StreamConvergenceLayer::Connection::handle_data_todo(), dtn::BluetoothConvergenceLayer::Connection::handle_reply(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), dtn::StreamConvergenceLayer::Connection::process_data(), oasys::BufferedInput::read_bytes(), oasys::BufferedInput::read_line(), oasys::BufferedInput::read_some_bytes(), dtn::ConnectionConvergenceLayer::reconfigure_link(), dtn::BluetoothConvergenceLayer::Connection::recv_announce(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), dtn::BluetoothConvergenceLayer::Connection::recv_loop(), reserve(), dtn::StreamConvergenceLayer::Connection::send_keepalive(), set_size(), oasys::BufferedOutput::vformat_buf(), and oasys::BufferedOutput::write().
size_t oasys::StreamBuffer::tailbytes | ( | ) |
Amount of free bytes available at the end of the buffer.
Definition at line 143 of file StreamBuffer.cc.
Referenced by fill(), dtn::StreamConvergenceLayer::Connection::finish_bundle(), oasys::BufferedInput::get_char(), dtn::BluetoothConvergenceLayer::Connection::handle_reply(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), dtn::StreamConvergenceLayer::Connection::process_data(), oasys::BufferedInput::read_some_bytes(), dtn::BluetoothConvergenceLayer::Connection::recv_announce(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), dtn::BluetoothConvergenceLayer::Connection::recv_loop(), reserve(), dtn::StreamConvergenceLayer::Connection::send_data_todo(), dtn::StreamConvergenceLayer::Connection::send_keepalive(), dtn::StreamConvergenceLayer::Connection::send_next_segment(), dtn::StreamConvergenceLayer::Connection::send_pending_acks(), dtn::StreamConvergenceLayer::Connection::send_pending_data(), dtn::StreamConvergenceLayer::Connection::start_next_bundle(), and oasys::BufferedOutput::vformat_buf().
void oasys::StreamBuffer::realloc | ( | size_t | size | ) | [private] |
Resize buffer to size.
Definition at line 149 of file StreamBuffer.cc.
References ASSERT, buf_, oasys::LOG_CRIT, oasys::logf(), and size_.
Referenced by reserve(), and set_size().
void oasys::StreamBuffer::moveup | ( | ) | [private] |
Compact buffer, moving all data up to the start of the dynamically allocated buffer, eliminating the empty space at the front.
Definition at line 162 of file StreamBuffer.cc.
References buf_, end_, and start_.
Referenced by reserve(), and set_size().
size_t oasys::StreamBuffer::start_ [private] |
Definition at line 109 of file StreamBuffer.h.
Referenced by clear(), consume(), fullbytes(), moveup(), reserve(), and start().
size_t oasys::StreamBuffer::end_ [private] |
Definition at line 110 of file StreamBuffer.h.
Referenced by clear(), consume(), end(), fill(), fullbytes(), moveup(), and tailbytes().
size_t oasys::StreamBuffer::size_ [private] |
Definition at line 111 of file StreamBuffer.h.
Referenced by realloc(), reserve(), size(), StreamBuffer(), and tailbytes().
char* oasys::StreamBuffer::buf_ [private] |
Definition at line 113 of file StreamBuffer.h.
Referenced by data(), end(), moveup(), realloc(), start(), StreamBuffer(), and ~StreamBuffer().
const size_t oasys::StreamBuffer::DEFAULT_BUFSIZE = 512 [static, private] |
Definition at line 115 of file StreamBuffer.h.