#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 34 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 50 of file StreamBuffer.cc.
References ASSERT, fullbytes(), moveup(), and realloc().
Referenced by dtn::ConnectionConvergenceLayer::reconfigure_link().
char* oasys::StreamBuffer::data | ( | ) | [inline] |
Definition at line 50 of file StreamBuffer.h.
References buf_.
char * oasys::StreamBuffer::start | ( | ) |
Definition at line 59 of file StreamBuffer.cc.
Referenced by oasys::BufferedInput::find_nl(), oasys::BufferedOutput::flush(), oasys::BufferedInput::get_char(), 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_shutdown(), 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(), and dtn::StreamConvergenceLayer::Connection::send_data().
char * oasys::StreamBuffer::end | ( | ) |
Definition at line 65 of file StreamBuffer.cc.
Referenced by dtn::StreamConvergenceLayer::Connection::break_contact(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), oasys::BufferedInput::read_some_bytes(), dtn::StreamConvergenceLayer::Connection::send_data_todo(), dtn::StreamConvergenceLayer::Connection::send_keepalive(), dtn::StreamConvergenceLayer::Connection::send_next_segment(), dtn::StreamConvergenceLayer::Connection::send_pending_acks(), oasys::BufferedOutput::vformat_buf(), and oasys::BufferedOutput::write().
void oasys::StreamBuffer::reserve | ( | size_t | amount | ) |
Reserve amount bytes in the buffer.
Definition at line 71 of file StreamBuffer.cc.
References ASSERT, fullbytes(), moveup(), realloc(), size_, start_, and tailbytes().
Referenced by dtn::CLConnection::CLConnection(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), dtn::StreamConvergenceLayer::Connection::process_data(), 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 92 of file StreamBuffer.cc.
References ASSERT, end_, and tailbytes().
Referenced by dtn::StreamConvergenceLayer::Connection::break_contact(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), dtn::StreamConvergenceLayer::Connection::send_data_todo(), dtn::StreamConvergenceLayer::Connection::send_keepalive(), dtn::StreamConvergenceLayer::Connection::send_next_segment(), dtn::StreamConvergenceLayer::Connection::send_pending_acks(), 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 100 of file StreamBuffer.cc.
References ASSERT, end_, fullbytes(), and start_.
Referenced by oasys::BufferedOutput::flush(), oasys::BufferedInput::get_char(), 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_keepalive(), dtn::StreamConvergenceLayer::Connection::handle_shutdown(), oasys::BufferedInput::read_bytes(), oasys::BufferedInput::read_line(), oasys::BufferedInput::read_some_bytes(), and dtn::StreamConvergenceLayer::Connection::send_data().
void oasys::StreamBuffer::clear | ( | ) |
Clear all data from the buffer.
Definition at line 112 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 71 of file StreamBuffer.h.
References size_.
Referenced by dtn::StreamConvergenceLayer::Connection::process_data(), and dtn::ConnectionConvergenceLayer::reconfigure_link().
size_t oasys::StreamBuffer::fullbytes | ( | ) |
Amount of bytes stored in the stream buffer.
Definition at line 118 of file StreamBuffer.cc.
Referenced by dtn::StreamConvergenceLayer::Connection::break_contact(), consume(), oasys::BufferedInput::eof(), oasys::BufferedInput::find_nl(), oasys::BufferedOutput::flush(), oasys::BufferedInput::get_char(), 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::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(), reserve(), dtn::StreamConvergenceLayer::Connection::send_data(), 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 124 of file StreamBuffer.cc.
Referenced by fill(), oasys::BufferedInput::get_char(), dtn::StreamConvergenceLayer::Connection::handle_shutdown(), dtn::StreamConvergenceLayer::Connection::initiate_contact(), oasys::BufferedInput::internal_read(), dtn::StreamConvergenceLayer::Connection::process_data(), oasys::BufferedInput::read_some_bytes(), 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(), and oasys::BufferedOutput::vformat_buf().
void oasys::StreamBuffer::realloc | ( | size_t | size | ) | [private] |
Resize buffer to size.
Definition at line 130 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 143 of file StreamBuffer.cc.
References buf_, end_, and start_.
Referenced by reserve(), and set_size().
size_t oasys::StreamBuffer::start_ [private] |
Definition at line 88 of file StreamBuffer.h.
Referenced by clear(), consume(), fullbytes(), moveup(), reserve(), and start().
size_t oasys::StreamBuffer::end_ [private] |
Definition at line 89 of file StreamBuffer.h.
Referenced by clear(), consume(), end(), fill(), fullbytes(), moveup(), and tailbytes().
size_t oasys::StreamBuffer::size_ [private] |
Definition at line 90 of file StreamBuffer.h.
Referenced by realloc(), reserve(), size(), StreamBuffer(), and tailbytes().
char* oasys::StreamBuffer::buf_ [private] |
Definition at line 92 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 94 of file StreamBuffer.h.