Public Member Functions | Data Fields

MIOBuffer Class Reference

A multiple reader, single writer memory buffer. More...

#include <I_IOBuffer.h>

Collaboration diagram for MIOBuffer:
Collaboration graph
[legend]

Public Member Functions

void fill (int64_t len)
 Increase writer's inuse area.
void append_block (IOBufferBlock *b)
 Adds a block to the end of the block list.
void append_block (int64_t asize_index)
 Adds a new block to the end of the block list.
void add_block ()
 Adds new block to the end of block list using the block size for the buffer specified when the buffer was allocated.
void append_xmalloced (void *b, int64_t len)
 Adds by reference len bytes of data pointed to by b to the end of the buffer.
void append_fast_allocated (void *b, int64_t len, int64_t fast_size_index)
 Adds by reference len bytes of data pointed to by b to the end of the buffer.
inkcoreapi int64_t write (const void *rbuf, int64_t nbytes)
 Adds the nbytes worth of data pointed by rbuf to the buffer.
inkcoreapi int64_t write (IOBufferReader *r, int64_t len=INT64_MAX, int64_t offset=0)
 Add by data from IOBufferReader r to the this buffer by reference.
int64_t remove_append (IOBufferReader *)
IOBufferBlockfirst_write_block ()
 Returns a pointer to the first writable block on the block chain.
char * buf ()
char * buf_end ()
char * start ()
char * end ()
int64_t block_write_avail ()
 Returns the amount of space of available for writing on the first writable block on the block chain (the one that would be reutrned by first_write_block()).
int64_t current_write_avail ()
 Returns the amount of space of available for writing on all writable blocks currently on the block chain.
int64_t write_avail ()
 Adds blocks for writing if the watermark criteria are met.
int64_t block_size ()
 Returns the default data block size for this buffer.
int64_t total_size ()
 Returns the default data block size for this buffer.
bool high_water ()
 Returns true if amount of the data outstanding on the buffer exceeds the watermark.
bool low_water ()
 Returns true if the amount of writable space after adding a block on the buffer is less than the water mark.
bool current_low_water ()
 Returns true if amount the amount writable space without adding and blocks on the buffer is less than the water mark.
void set_size_index (int64_t size)
IOBufferReaderalloc_accessor (MIOBufferAccessor *anAccessor)
 Allocates a new IOBuffer reader and sets it's its 'accessor' field to point to 'anAccessor'.
IOBufferReaderalloc_reader ()
 Allocates an IOBufferReader for this buffer.
IOBufferReaderclone_reader (IOBufferReader *r)
 Allocates a new reader on this buffer and places it's starting point at the same place as reader r.
void dealloc_reader (IOBufferReader *e)
 Deallocates reader e from this buffer.
void dealloc_all_readers ()
 Deallocates all outstanding readers on the buffer.
void set (void *b, int64_t len)
void set_xmalloced (void *b, int64_t len)
void alloc (int64_t i=default_large_iobuffer_size)
void alloc_xmalloc (int64_t buf_size)
void append_block_internal (IOBufferBlock *b)
int64_t puts (char *buf, int64_t len)
bool empty ()
int64_t max_read_avail ()
int max_block_count ()
void check_add_block ()
IOBufferBlockget_current_block ()
void reset ()
void init_readers ()
void dealloc ()
void clear ()
void realloc (int64_t i)
void realloc (void *b, int64_t buf_size)
void realloc_xmalloc (void *b, int64_t buf_size)
void realloc_xmalloc (int64_t buf_size)
 MIOBuffer (void *b, int64_t bufsize, int64_t aWater_mark)
 MIOBuffer (int64_t default_size_index)
 MIOBuffer ()
 ~MIOBuffer ()

Data Fields

int64_t size_index
int64_t water_mark
 Determines when to stop writing or reading.
Ptr< IOBufferBlock_writer
IOBufferReader readers [MAX_MIOBUFFER_READERS]
const char * _location

Detailed Description

A multiple reader, single writer memory buffer.

MIOBuffers are at the center of all IOCore data transfer. MIOBuffers are the data buffers used to transfer data to and from VConnections. A MIOBuffer points to a list of IOBufferBlocks which in turn point to IOBufferData structures that in turn point to the actual data. MIOBuffer allows one producer and multiple consumers. The buffer fills up according the amount of data outstanding for the slowest consumer. Thus, MIOBuffer implements automatic flow control between readers of different speeds. Data on IOBuffer is immutable. Once written it cannot be modified, only deallocated once all consumers have finished with it. Immutability is necessary since data can be shared between buffers, which means that multiple IOBufferBlock objects may reference the same data but only one will have ownership for writing.

Definition at line 808 of file I_IOBuffer.h.


Constructor & Destructor Documentation

TS_INLINE MIOBuffer::MIOBuffer ( void *  b,
int64_t  bufsize,
int64_t  aWater_mark 
)

Definition at line 735 of file P_IOBuffer.h.

References _location, size_index, and water_mark.

TS_INLINE MIOBuffer::MIOBuffer ( int64_t  default_size_index  ) 

Definition at line 747 of file P_IOBuffer.h.

References _location, clear(), and size_index.

TS_INLINE MIOBuffer::MIOBuffer (  ) 

Definition at line 758 of file P_IOBuffer.h.

References _location, and clear().

TS_INLINE MIOBuffer::~MIOBuffer (  ) 

Definition at line 769 of file P_IOBuffer.h.

References _writer, and dealloc_all_readers().


Member Function Documentation

TS_INLINE void MIOBuffer::add_block (  ) 

Adds new block to the end of block list using the block size for the buffer specified when the buffer was allocated.

Definition at line 957 of file P_IOBuffer.h.

References append_block(), and size_index.

Referenced by check_add_block(), copy_header(), TSHttpHdrPrint(), TSIOBufferStart(), TSMimeHdrPrint(), TSUrlPrint(), write(), and HttpSM::write_header_into_buffer().

TS_INLINE void MIOBuffer::alloc ( int64_t  i = default_large_iobuffer_size  ) 

Definition at line 1110 of file P_IOBuffer.h.

References _location, _writer, init_readers(), new_IOBufferBlock_internal(), and size_index.

Referenced by new_MIOBuffer_internal().

TS_INLINE IOBufferReader * MIOBuffer::alloc_accessor ( MIOBufferAccessor anAccessor  ) 

Allocates a new IOBuffer reader and sets it's its 'accessor' field to point to 'anAccessor'.

Definition at line 818 of file P_IOBuffer.h.

References IOBufferReader::accessor, ink_release_assert, IOBufferReader::mbuf, readers, and IOBufferReader::reset().

Referenced by MIOBufferAccessor::reader_for().

TS_INLINE IOBufferReader * MIOBuffer::alloc_reader (  ) 

Allocates an IOBufferReader for this buffer.

IOBufferReaders hold data on the buffer for different consumers. IOBufferReaders are REQUIRED when using buffer. alloc_reader() MUST ONLY be a called on newly allocated buffers. Calling on a buffer with data already placed on it will result in the reader starting at an indeterminate place on the buffer.

Definition at line 837 of file P_IOBuffer.h.

References IOBufferReader::accessor, ink_release_assert, IOBufferReader::mbuf, readers, and IOBufferReader::reset().

Referenced by HttpTunnel::allocate_redirect_postdata_buffers(), HttpTunnel::allocate_redirect_postdata_producer_buffer(), CheckConnect::CheckConnect(), HttpSM::do_setup_post_tunnel(), ClusterState::doIO(), CacheTestSM::event_handler(), RangeTransform::handle_event(), NullTransform::handle_event(), TransformControl::handle_event(), PrefetchTransform::handle_event(), ShowCache::handleCacheEvent(), SocksProxy::init(), SocksEntry::init(), PrefetchBlaster::init(), PluginVCCore::init(), OneWayTunnel::init(), FetchSM::init_comm(), NetTesterSM::NetTesterSM(), HttpServerSession::new_connection(), HttpClientSession::new_connection(), Http2ClientSession::new_connection(), ObjectReloadCont::ObjectReloadEvent(), ProtocolProbeTrampoline::ProtocolProbeTrampoline(), HttpServerSession::reset_read_buffer(), HttpSM::setup_100_continue_transfer(), HttpSM::setup_blind_tunnel(), HttpSM::setup_cache_read_transfer(), HttpSM::setup_cache_transfer_to_transform(), setup_client_request(), HttpSM::setup_internal_transfer(), HttpSM::setup_push_transfer_to_cache(), HttpSM::setup_server_send_request(), HttpSM::setup_server_transfer(), HttpSM::setup_server_transfer_to_cache_only(), HttpSM::setup_server_transfer_to_transform(), HttpSM::setup_transfer_from_transform(), HttpSM::setup_transfer_from_transform_to_cache_only(), HttpSM::setup_transform_to_server_transfer(), CacheContinuation::setupVCdataRead(), NetVCTest::start_test(), HttpSM::state_send_server_request_header(), TSIOBufferReaderAlloc(), PrefetchUrlBlaster::udpUrlBlaster(), and vc_do_io_write().

TS_INLINE void MIOBuffer::alloc_xmalloc ( int64_t  buf_size  ) 

Definition at line 1123 of file P_IOBuffer.h.

References ats_malloc(), and set_xmalloced().

TS_INLINE void MIOBuffer::append_block ( IOBufferBlock b  ) 
TS_INLINE void MIOBuffer::append_block ( int64_t  asize_index  ) 

Adds a new block to the end of the block list.

The size is determined by asize_index. See the remarks section for a mapping of indexes to buffer block sizes.

Definition at line 943 of file P_IOBuffer.h.

References _location, IOBufferBlock::alloc(), append_block_internal(), BUFFER_SIZE_ALLOCATED, ink_assert, and new_IOBufferBlock_internal().

TS_INLINE void MIOBuffer::append_block_internal ( IOBufferBlock b  ) 
TS_INLINE void MIOBuffer::append_fast_allocated ( void *  b,
int64_t  len,
int64_t  fast_size_index 
)

Adds by reference len bytes of data pointed to by b to the end of the buffer.

b MUST be a pointer to the beginning of block allocated from ioBufAllocator of the corresponding index for fast_size_index. The data will be deallocated by the buffer once all readers on the buffer have consumed it.

Definition at line 1098 of file P_IOBuffer.h.

References _location, append_block_internal(), new_IOBufferBlock_internal(), and IOBufferBlock::set_internal().

Referenced by HttpSM::setup_internal_transfer().

TS_INLINE void MIOBuffer::append_xmalloced ( void *  b,
int64_t  len 
)

Adds by reference len bytes of data pointed to by b to the end of the buffer.

b MUST be a pointer to the beginning of block allocated from the ats_xmalloc() routine. The data will be deallocated by the buffer once all readers on the buffer have consumed it.

Definition at line 1086 of file P_IOBuffer.h.

References _location, append_block_internal(), BUFFER_SIZE_INDEX_FOR_XMALLOC_SIZE, new_IOBufferBlock_internal(), and IOBufferBlock::set_internal().

Referenced by HttpSM::setup_internal_transfer().

TS_INLINE int64_t MIOBuffer::block_size (  ) 

Returns the default data block size for this buffer.

Definition at line 856 of file P_IOBuffer.h.

References index_to_buffer_size(), and size_index.

Referenced by MIOBufferAccessor::block_size(), and total_size().

TS_INLINE int64_t MIOBuffer::block_write_avail (  ) 

Returns the amount of space of available for writing on the first writable block on the block chain (the one that would be reutrned by first_write_block()).

Definition at line 883 of file P_IOBuffer.h.

References first_write_block(), and IOBufferBlock::write_avail().

Referenced by copy_header().

char* MIOBuffer::buf (  )  [inline]

Definition at line 930 of file I_IOBuffer.h.

References IOBufferBlock::buf(), and first_write_block().

Referenced by write().

char* MIOBuffer::buf_end (  )  [inline]

Definition at line 935 of file I_IOBuffer.h.

References IOBufferBlock::buf_end(), and first_write_block().

Referenced by TransformControl::handle_event(), and puts().

TS_INLINE void MIOBuffer::check_add_block (  ) 

Definition at line 963 of file P_IOBuffer.h.

References add_block(), current_low_water(), and high_water().

Referenced by write_avail().

void MIOBuffer::clear (  )  [inline]
TS_INLINE IOBufferReader * MIOBuffer::clone_reader ( IOBufferReader r  ) 

Allocates a new reader on this buffer and places it's starting point at the same place as reader r.

r MUST be a pointer to a reader previous allocated from this buffer.

Definition at line 861 of file P_IOBuffer.h.

References IOBufferReader::accessor, IOBufferReader::block, ink_assert, ink_release_assert, IOBufferReader::mbuf, readers, IOBufferReader::size_limit, and IOBufferReader::start_offset.

Referenced by IOBufferReader::clone(), and ChunkedHandler::init_by_action().

bool MIOBuffer::current_low_water (  )  [inline]

Returns true if amount the amount writable space without adding and blocks on the buffer is less than the water mark.

Definition at line 1013 of file I_IOBuffer.h.

References current_write_avail(), and water_mark.

Referenced by check_add_block(), and IOBufferReader::current_low_water().

TS_INLINE int64_t MIOBuffer::current_write_avail (  ) 

Returns the amount of space of available for writing on all writable blocks currently on the block chain.

Will NOT add blocks to the block chain.

Definition at line 986 of file P_IOBuffer.h.

References _writer, IOBufferBlock::next, and IOBufferBlock::write_avail().

Referenced by current_low_water(), ClusterState::doIO(), and write_avail().

void MIOBuffer::dealloc (  )  [inline]

Definition at line 1099 of file I_IOBuffer.h.

References _writer, and dealloc_all_readers().

Referenced by clear().

TS_INLINE void MIOBuffer::dealloc_all_readers (  ) 

Deallocates all outstanding readers on the buffer.

Definition at line 1153 of file P_IOBuffer.h.

References dealloc_reader(), and readers.

Referenced by dealloc(), free_MIOBuffer(), HttpServerSession::reset_read_buffer(), CheckConnect::~CheckConnect(), ~MIOBuffer(), and NetTesterSM::~NetTesterSM().

TS_INLINE void MIOBuffer::dealloc_reader ( IOBufferReader e  ) 

Deallocates reader e from this buffer.

e MUST be a pointer to a reader previous allocated from this buffer. Reader need to allocated when a particularly consumer is being removed from the buffer but the buffer is still in use. Deallocation is not necessary when the buffer is being freed as all outstanding readers are automatically deallocated.

Definition at line 1130 of file P_IOBuffer.h.

References IOBufferReader::accessor, IOBufferReader::clear(), MIOBufferAccessor::clear(), ink_assert, MIOBufferAccessor::reader(), and MIOBufferAccessor::writer().

Referenced by HttpTunnel::consumer_handler(), IOBufferReader::dealloc(), dealloc_all_readers(), CacheTestSM::event_handler(), ShowCache::handleCacheEvent(), TSIOBufferReaderFree(), and CacheTestSM::~CacheTestSM().

bool MIOBuffer::empty (  )  [inline]

Definition at line 1070 of file I_IOBuffer.h.

References _writer.

char* MIOBuffer::end (  )  [inline]
TS_INLINE void MIOBuffer::fill ( int64_t  len  ) 

Increase writer's inuse area.

Instructs the writer associated with this MIOBuffer to increase the inuse area of the block by as much as 'len' bytes.

Parameters:
len number of bytes to add to the inuse area of the block.

Definition at line 1014 of file P_IOBuffer.h.

References _writer.

Referenced by PrefetchBlaster::bufferObject(), TestProxy::cacheSendGetEvent(), TestProxy::connectEvent(), copy_header(), CacheTestSM::fill_buffer(), TransformControl::handle_event(), ObjectReloadCont::Init(), SocksProxy::mainEvent(), SocksEntry::mainEvent(), puts(), read_from_net(), SocksProxy::sendResp(), ssl_read_from_net(), transfer_data(), TSHttpHdrPrint(), TSIOBufferProduce(), TSMimeHdrPrint(), TSUrlPrint(), PrefetchUrlBlaster::udpUrlBlaster(), and HttpSM::write_header_into_buffer().

IOBufferBlock* MIOBuffer::first_write_block (  )  [inline]

Returns a pointer to the first writable block on the block chain.

Returns NULL if there are not currently any writable blocks on the block list.

Definition at line 918 of file I_IOBuffer.h.

References _writer, and ink_assert.

Referenced by block_write_avail(), buf(), buf_end(), end(), get_current_block(), read_from_net(), ssl_read_from_net(), and start().

TS_INLINE IOBufferBlock * MIOBuffer::get_current_block (  ) 
bool MIOBuffer::high_water (  )  [inline]

Returns true if amount of the data outstanding on the buffer exceeds the watermark.

Definition at line 992 of file I_IOBuffer.h.

References max_read_avail(), and water_mark.

Referenced by PrefetchBlaster::bufferObject(), check_add_block(), and CacheVC::openReadMain().

void MIOBuffer::init_readers (  )  [inline]

Definition at line 1092 of file I_IOBuffer.h.

References _writer, IOBufferReader::block, and readers.

Referenced by alloc(), append_block_internal(), set(), and set_xmalloced().

bool MIOBuffer::low_water (  )  [inline]

Returns true if the amount of writable space after adding a block on the buffer is less than the water mark.

Since this function relies on write_avail() it may add blocks.

Definition at line 1003 of file I_IOBuffer.h.

References water_mark, and write_avail().

Referenced by IOBufferReader::low_water().

TS_INLINE int MIOBuffer::max_block_count (  ) 

Definition at line 1028 of file P_IOBuffer.h.

References IOBufferReader::block_count(), and readers.

Referenced by NetVCTest::~NetVCTest().

TS_INLINE int64_t MIOBuffer::max_read_avail (  ) 
int64_t MIOBuffer::puts ( char *  buf,
int64_t  len 
)

Definition at line 167 of file IOBuffer.cc.

References buf_end(), end(), fill(), and memcpy.

void MIOBuffer::realloc ( int64_t  i  )  [inline]

Definition at line 1112 of file I_IOBuffer.h.

References _writer.

void MIOBuffer::realloc ( void *  b,
int64_t  buf_size 
) [inline]

Definition at line 1116 of file I_IOBuffer.h.

References _writer.

void MIOBuffer::realloc_xmalloc ( void *  b,
int64_t  buf_size 
) [inline]

Definition at line 1120 of file I_IOBuffer.h.

References _writer.

void MIOBuffer::realloc_xmalloc ( int64_t  buf_size  )  [inline]

Definition at line 1124 of file I_IOBuffer.h.

References _writer.

int64_t MIOBuffer::remove_append ( IOBufferReader r  ) 
void MIOBuffer::reset (  )  [inline]
TS_INLINE void MIOBuffer::set ( void *  b,
int64_t  len 
)
TS_INLINE void MIOBuffer::set_size_index ( int64_t  size  ) 

Definition at line 1161 of file P_IOBuffer.h.

References iobuffer_size_to_index(), and size_index.

TS_INLINE void MIOBuffer::set_xmalloced ( void *  b,
int64_t  len 
)
char* MIOBuffer::start (  )  [inline]
int64_t MIOBuffer::total_size (  )  [inline]

Returns the default data block size for this buffer.

Definition at line 982 of file I_IOBuffer.h.

References block_size().

int64_t MIOBuffer::write ( IOBufferReader r,
int64_t  len = INT64_MAX,
int64_t  offset = 0 
)

Add by data from IOBufferReader r to the this buffer by reference.

If len is INT64_MAX, all available data on the reader is added. If len is less than INT64_MAX, the smaller of len or the amount of data on the buffer is added. If offset is greater than zero, than the offset bytes of data at the front of the reader are skipped. Bytes skipped by offset reduce the number of bytes available on the reader used in the amount of data to add computation. write() does not respect watermarks or buffer size limits. Users of write must implement their own flow control. Returns the number of bytes added. Each write() call creates a new IOBufferBlock, even if it is for one byte. As such, it's necessary to exercise caution in any code that repeatedly transfers data from one buffer to another, especially if the data is being read over the network as it may be coming in very small chunks. Because deallocation of outstanding buffer blocks is recursive, it's possible to overrun the stack if too many blocks have been added to the buffer chain. It's imperative that users both implement their own flow control to prevent too many bytes from becoming outstanding on a buffer that the write() call is being used and that care be taken to ensure the transfers are of a minimum size. Should it be necessary to make a large number of small transfers, it's preferable to use a interface that copies the data rather than sharing blocks to prevent a build of blocks on the buffer.

Definition at line 136 of file IOBuffer.cc.

References IOBufferBlock::_buf_end, IOBufferBlock::_end, IOBufferBlock::_start, append_block(), IOBufferReader::block, IOBufferBlock::clone(), IOBufferBlock::next, IOBufferBlock::read_avail(), and IOBufferReader::start_offset.

int64_t MIOBuffer::write ( const void *  rbuf,
int64_t  nbytes 
)
TS_INLINE int64_t MIOBuffer::write_avail (  ) 

Adds blocks for writing if the watermark criteria are met.

Returns the amount of space of available for writing on all writable blocks on the block chain after a block due to the watermark criteria.

Definition at line 1007 of file P_IOBuffer.h.

References check_add_block(), and current_write_avail().

Referenced by HttpTunnel::consumer_handler(), HttpTunnel::consumer_reenable(), CacheTestSM::fill_buffer(), low_water(), SSLNetVConnection::net_read_io(), read_from_net(), ClusterVConnectionBase::reenable(), transfer_data(), ClusterHandler::valid_for_data_write(), and write_to_net_io().


Field Documentation

const char* MIOBuffer::_location
IOBufferReader MIOBuffer::readers[MAX_MIOBUFFER_READERS]

Determines when to stop writing or reading.

The watermark is the level to which the producer (filler) is required to fill the buffer before it can expect the reader to consume any data. A watermark of zero means that the reader will consume any amount of data, no matter how small.

Definition at line 1139 of file I_IOBuffer.h.

Referenced by PrefetchBlaster::bufferObject(), clear(), current_low_water(), IOBufferReader::high_water(), high_water(), OneWayTunnel::init(), OneWayMultiTunnel::init(), FetchSM::init(), ChunkedHandler::init_by_action(), low_water(), MIOBuffer(), CacheVC::openReadMain(), CacheVC::reenable(), HttpSM::setup_cache_read_transfer(), HttpSM::setup_server_transfer(), HttpSM::setup_transfer_from_transform(), TSIOBufferWaterMarkGet(), and TSIOBufferWaterMarkSet().


The documentation for this class was generated from the following files: