oasys::StreamBuffer Class Reference

#include <StreamBuffer.h>

List of all members.


Detailed Description

Stream oriented resizable buffer.

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 ()
 
Returns:
Pointer to the beginning of the total buffer (including potentially consumed parts

char * start ()
 
Returns:
Pointer to the beginning of the data.

char * end ()
 
Returns:
Pointer to the end of the data.

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


Constructor & Destructor Documentation

oasys::StreamBuffer::StreamBuffer ( size_t  size = DEFAULT_BUFSIZE  ) 

Create a new StreamBuffer with initial size.

Definition at line 30 of file StreamBuffer.cc.

References ASSERT, buf_, and size_.

oasys::StreamBuffer::~StreamBuffer (  ) 

Definition at line 40 of file StreamBuffer.cc.

References buf_.


Member Function Documentation

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]

Returns:
Pointer to the beginning of the total buffer (including potentially consumed parts

Definition at line 50 of file StreamBuffer.h.

References buf_.

char * oasys::StreamBuffer::start (  ) 

Returns:
Pointer to the beginning of the data.

Definition at line 59 of file StreamBuffer.cc.

References buf_, and start_.

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(), and oasys::BufferedInput::read_some_bytes().

char * oasys::StreamBuffer::end (  ) 

Returns:
Pointer to the end of the data.

Definition at line 65 of file StreamBuffer.cc.

References buf_, and end_.

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(), and oasys::BufferedInput::read_some_bytes().

void oasys::StreamBuffer::clear (  ) 

Clear all data from the buffer.

Definition at line 112 of file StreamBuffer.cc.

References end_, and start_.

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.

References end_, and start_.

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_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.

References end_, and size_.

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().


Member Data Documentation

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.


The documentation for this class was generated from the following files:
Generated on Thu Jun 7 16:57:03 2007 for DTN Reference Implementation by  doxygen 1.5.1