#include <llbuffer.h>
Collaboration diagram for LLBufferArray:
LLChannelDescriptors | nextChannel () |
Generate the next channel descriptor for this buffer array. | |
static LLChannelDescriptors | makeChannelConsumer (const LLChannelDescriptors &channels) |
Generate the a channel descriptor which consumes the output for the channel passed in. | |
Public Types | |
typedef std::vector< LLBuffer * > | buffer_list_t |
typedef buffer_list_t::iterator | buffer_iterator_t |
typedef buffer_list_t::const_iterator | const_buffer_iterator_t |
typedef std::list< LLSegment > | segment_list_t |
typedef segment_list_t::const_iterator | const_segment_iterator_t |
typedef segment_list_t::iterator | segment_iterator_t |
npos = 0xffffffff | |
enum | { npos = 0xffffffff } |
Public Member Functions | |
LLBufferArray () | |
~LLBufferArray () | |
S32 | capacity () const |
Return the sum of all allocated bytes. | |
bool | append (S32 channel, const U8 *src, S32 len) |
Put data on a channel at the end of this buffer array. | |
bool | prepend (S32 channel, const U8 *src, S32 len) |
Put data on a channel at the front of this buffer array. | |
bool | insertAfter (segment_iterator_t segment, S32 channel, const U8 *src, S32 len) |
Insert data into a buffer array after a particular segment. | |
S32 | countAfter (S32 channel, U8 *start) const |
Count bytes in the buffer array on the specified channel. | |
U8 * | readAfter (S32 channel, U8 *start, U8 *dest, S32 &len) const |
Read bytes in the buffer array on the specified channel. | |
U8 * | seek (S32 channel, U8 *start, S32 delta) const |
Find an address in a buffer array. | |
bool | takeContents (LLBufferArray &source) |
Take the contents of another buffer array. | |
segment_iterator_t | splitAfter (U8 *address) |
Split a segments so that address is the last address of one segment, and the rest of the original segment becomes another segment on the same channel. | |
segment_iterator_t | beginSegment () |
Get the first segment in the buffer array. | |
segment_iterator_t | endSegment () |
Get the one-past-the-end segment in the buffer array. | |
const_segment_iterator_t | getSegment (U8 *address) const |
Get the segment which holds the given address. | |
segment_iterator_t | getSegment (U8 *address) |
Get the segment which holds the given address. | |
segment_iterator_t | constructSegmentAfter (U8 *address, LLSegment &segment) |
Get a segment iterator after address, and a constructed segment to represent the next linear block of memory. | |
segment_iterator_t | makeSegment (S32 channel, S32 length) |
Make a new segment at the end of buffer array. | |
bool | eraseSegment (const segment_iterator_t &iter) |
Erase the segment if it is in the buffer array. | |
Protected Member Functions | |
bool | copyIntoBuffers (S32 channel, const U8 *src, S32 len, std::vector< LLSegment > &segments) |
Optimally put data in buffers, and reutrn segments. | |
Protected Attributes | |
S32 | mNextBaseChannel |
buffer_list_t | mBuffers |
segment_list_t | mSegments |
*NOTE: This class needs to have an iovec interface
Definition at line 304 of file llbuffer.h.
typedef buffer_list_t::iterator LLBufferArray::buffer_iterator_t |
Definition at line 308 of file llbuffer.h.
typedef std::vector<LLBuffer*> LLBufferArray::buffer_list_t |
Definition at line 307 of file llbuffer.h.
typedef buffer_list_t::const_iterator LLBufferArray::const_buffer_iterator_t |
Definition at line 309 of file llbuffer.h.
typedef segment_list_t::const_iterator LLBufferArray::const_segment_iterator_t |
Definition at line 311 of file llbuffer.h.
typedef segment_list_t::iterator LLBufferArray::segment_iterator_t |
Definition at line 312 of file llbuffer.h.
Definition at line 310 of file llbuffer.h.
anonymous enum |
LLBufferArray::LLBufferArray | ( | ) |
LLBufferArray::~LLBufferArray | ( | ) |
Put data on a channel at the end of this buffer array.
The data is copied from src into the buffer array. At least one new segment is created and put on the end of the array. This object will internally allocate new buffers if necessary.
channel | The channel for this data | |
src | The start of memory for the data to be copied | |
len | The number of bytes of data to copy |
Definition at line 269 of file llbuffer.cpp.
References copyIntoBuffers(), mSegments, and LLMemType::MTYPE_IO_BUFFER.
Referenced by LLURLRequest::downCallback().
LLBufferArray::segment_iterator_t LLBufferArray::beginSegment | ( | ) |
Get the first segment in the buffer array.
Definition at line 343 of file llbuffer.cpp.
References mSegments.
S32 LLBufferArray::capacity | ( | ) | const |
LLBufferArray::segment_iterator_t LLBufferArray::constructSegmentAfter | ( | U8 * | address, | |
LLSegment & | segment | |||
) |
Get a segment iterator after address, and a constructed segment to represent the next linear block of memory.
This method is a helper by giving you the largest segment possible in the out-value param after the address provided. The iterator will be useful for iteration, while the segment can be used for direct access to memory after address if the return values isnot end. Passing in NULL will return beginSegment() which may be endSegment(). The segment returned will only be zero length if the return value equals end. This is really just a helper method, since all the information returned could be constructed through other methods.
address | An address in the middle of the sought segment. | |
segment[out] | segment to be used for reading or writing |
Definition at line 353 of file llbuffer.cpp.
References end, mSegments, and LLMemType::MTYPE_IO_BUFFER.
Referenced by LLBufferStreamBuf::underflow().
bool LLBufferArray::copyIntoBuffers | ( | S32 | channel, | |
const U8 * | src, | |||
S32 | len, | |||
std::vector< LLSegment > & | segments | |||
) | [protected] |
Optimally put data in buffers, and reutrn segments.
This is an internal function used to create buffers as necessary, and sequence the segments appropriately for the various ways to copy data from src into this. If this method fails, it may actually leak some space inside buffers, but I am not too worried about the slim possibility that we may have some 'dead' space which will be recovered when the buffer (which we will not lose) is deleted. Addressing this weakness will make the buffers almost as complex as a general memory management system.
channel | The channel for this data | |
src | The start of memory for the data to be copied | |
len | The number of bytes of data to copy | |
segments | Out-value for the segments created. |
Definition at line 801 of file llbuffer.cpp.
References LLBuffer::createSegment(), LLSegment::data(), end, llmin(), mBuffers, LLMemType::MTYPE_IO_BUFFER, S32, and LLSegment::size().
Referenced by append(), insertAfter(), and prepend().
Count bytes in the buffer array on the specified channel.
channel | The channel to count. | |
start | The start address in the array for counting. You can specify NULL to start at the beginning. |
Definition at line 469 of file llbuffer.cpp.
References count, end, getSegment(), mSegments, and S32.
Referenced by LLURLRequest::configure(), and LLURLRequest::upCallback().
LLBufferArray::segment_iterator_t LLBufferArray::endSegment | ( | ) |
Get the one-past-the-end segment in the buffer array.
Definition at line 348 of file llbuffer.cpp.
References mSegments.
Referenced by LLBufferStreamBuf::overflow(), LLBufferStreamBuf::sync(), and LLBufferStreamBuf::underflow().
bool LLBufferArray::eraseSegment | ( | const segment_iterator_t & | iter | ) |
Erase the segment if it is in the buffer array.
iter | An iterator referring to the segment to erase. |
Definition at line 773 of file llbuffer.cpp.
References end, mBuffers, mSegments, LLMemType::MTYPE_IO_BUFFER, and void.
Referenced by LLBufferStreamBuf::sync(), and LLBufferStreamBuf::underflow().
LLBufferArray::segment_iterator_t LLBufferArray::getSegment | ( | U8 * | address | ) |
Get the segment which holds the given address.
As opposed to some methods, passing a NULL will result in returning the end segment.
address | An address in the middle of the sought segment. |
Definition at line 403 of file llbuffer.cpp.
LLBufferArray::const_segment_iterator_t LLBufferArray::getSegment | ( | U8 * | address | ) | const |
Get the segment which holds the given address.
As opposed to some methods, passing a NULL will result in returning the end segment.
address | An address in the middle of the sought segment. |
Definition at line 422 of file llbuffer.cpp.
References end, and mSegments.
Referenced by countAfter(), readAfter(), seek(), and splitAfter().
bool LLBufferArray::insertAfter | ( | segment_iterator_t | segment, | |
S32 | channel, | |||
const U8 * | src, | |||
S32 | len | |||
) |
Insert data into a buffer array after a particular segment.
The data is copied from src into the buffer array. At least one new segment is created and put in the array. This object will internally allocate new buffers if necessary.
segment | The segment in front of the new segments location | |
channel | The channel for this data | |
src | The start of memory for the data to be copied | |
len | The number of bytes of data to copy |
Definition at line 293 of file llbuffer.cpp.
References copyIntoBuffers(), mSegments, and LLMemType::MTYPE_IO_BUFFER.
LLChannelDescriptors LLBufferArray::makeChannelConsumer | ( | const LLChannelDescriptors & | channels | ) | [static] |
Generate the a channel descriptor which consumes the output for the channel passed in.
Definition at line 244 of file llbuffer.cpp.
References LLChannelDescriptors::out().
Referenced by LLURLRequest::process_impl(), and LLHTTPResponder::process_impl().
LLBufferArray::segment_iterator_t LLBufferArray::makeSegment | ( | S32 | channel, | |
S32 | length | |||
) |
Make a new segment at the end of buffer array.
This method will attempt to create a new and empty segment of the specified length. The segment created may be shorter than requested.
channel[in] | The channel for the newly created segment. | |
length[in] | The requested length of the segment. |
Definition at line 734 of file llbuffer.cpp.
References LLBuffer::createSegment(), end, mBuffers, mSegments, and LLMemType::MTYPE_IO_BUFFER.
Referenced by LLBufferStreamBuf::overflow().
LLChannelDescriptors LLBufferArray::nextChannel | ( | ) |
Generate the next channel descriptor for this buffer array.
The channel descriptor interface is how the buffer array clients can know where to read and write data. Use this interface to get the 'next' channel set for usage. This is a bit of a simple hack until it's utility indicates it should be extended.
Definition at line 251 of file llbuffer.cpp.
References mNextBaseChannel.
Put data on a channel at the front of this buffer array.
The data is copied from src into the buffer array. At least one new segment is created and put in the front of the array. This object will internally allocate new buffers if necessary.
channel | The channel for this data | |
src | The start of memory for the data to be copied | |
len | The number of bytes of data to copy |
Definition at line 281 of file llbuffer.cpp.
References copyIntoBuffers(), mSegments, and LLMemType::MTYPE_IO_BUFFER.
Read bytes in the buffer array on the specified channel.
You should prefer iterating over segments is possible since this method requires you to allocate large buffers - precisely what this class is trying to prevent. This method will skip any segments which are not on the given channel, so this method would usually be used to read a channel and copy that to a log or a socket buffer or something.
channel | The channel to read. | |
start | The start address in the array for reading. You can specify NULL to start at the beginning. | |
dest | The destination of the data read. This must be at least len bytes long. | |
len[in,out] | in How many bytes to read. out How many bytes were read. |
Definition at line 509 of file llbuffer.cpp.
References end, getSegment(), llmin(), mSegments, LLMemType::MTYPE_IO_BUFFER, and S32.
Referenced by LLURLRequest::upCallback().
Find an address in a buffer array.
channel | The channel to seek in. | |
start | The start address in the array for the seek operation. You can specify NULL to start the seek at the beginning, or pass in npos to start at the end. | |
delta | How many bytes to seek through the array. |
Definition at line 571 of file llbuffer.cpp.
References end, getSegment(), llabs(), llmin(), mSegments, LLMemType::MTYPE_IO_BUFFER, npos, NULL, and S32.
Referenced by LLBufferStreamBuf::sync().
LLBufferArray::segment_iterator_t LLBufferArray::splitAfter | ( | U8 * | address | ) |
Split a segments so that address is the last address of one segment, and the rest of the original segment becomes another segment on the same channel.
After this method call, getLastSegmentAddress(*getSegment(address)) == address
should be true. This call will only create a new segment if the statement above is false before the call. Since you usually call splitAfter() to change a segment property, use getSegment() to perform those operations.
address | The address which will become the last address of the segment it is in. |
address
which is endSegment()
on failure. Definition at line 313 of file llbuffer.cpp.
References base, end, getSegment(), mSegments, LLMemType::MTYPE_IO_BUFFER, S32, and size.
Referenced by LLBufferStreamBuf::sync(), and LLBufferStreamBuf::underflow().
bool LLBufferArray::takeContents | ( | LLBufferArray & | source | ) |
Take the contents of another buffer array.
This method simply strips the contents out of the source buffery array - segments, buffers, etc, and appends them to this instance. After this operation, the source is empty and ready for reuse.
source | The source buffer |
Definition at line 717 of file llbuffer.cpp.
References mBuffers, mNextBaseChannel, mSegments, and LLMemType::MTYPE_IO_BUFFER.
buffer_list_t LLBufferArray::mBuffers [protected] |
Definition at line 589 of file llbuffer.h.
Referenced by capacity(), copyIntoBuffers(), eraseSegment(), makeSegment(), takeContents(), and ~LLBufferArray().
S32 LLBufferArray::mNextBaseChannel [protected] |
segment_list_t LLBufferArray::mSegments [protected] |
Definition at line 590 of file llbuffer.h.
Referenced by append(), beginSegment(), constructSegmentAfter(), countAfter(), endSegment(), eraseSegment(), getSegment(), insertAfter(), makeSegment(), prepend(), readAfter(), seek(), splitAfter(), and takeContents().