Public Member Functions | Data Fields

IOBufferReader Class Reference

An independent reader from an MIOBuffer. More...

#include <I_IOBuffer.h>

Collaboration diagram for IOBufferReader:
Collaboration graph
[legend]

Public Member Functions

char * start ()
 Start of unconsumed data.
char * end ()
 End of inuse area of the first block with unconsumed data.
int64_t read_avail ()
 Amount of data available across all of the IOBufferBlocks.
bool is_read_avail_more_than (int64_t size)
 Check if there is more than size bytes available to read.
int block_count ()
 Number of IOBufferBlocks with data in the block list.
int64_t block_read_avail ()
 Amount of data available in the first buffer with data for this reader.
void skip_empty_blocks ()
void clear ()
 Clears all fields in this IOBuffeReader, rendering it unusable.
void reset ()
 Instruct the reader to reset the IOBufferBlock list.
void consume (int64_t n)
 Consume a number of bytes from this reader's IOBufferBlock list.
IOBufferReaderclone ()
 Create another reader with access to the same data as this IOBufferReader.
void dealloc ()
 Deallocate this reader.
IOBufferBlockget_current_block ()
 Get a pointer to the first block with data.
bool current_low_water ()
 Consult this reader's MIOBuffer writable space.
bool low_water ()
 Queries the underlying MIOBuffer about.
bool high_water ()
 To see if the amount of data available to the reader is greater than the MIOBuffer's water mark.
inkcoreapi int64_t memchr (char c, int64_t len=INT64_MAX, int64_t offset=0)
 Perform a memchr() across the list of IOBufferBlocks.
inkcoreapi int64_t read (void *buf, int64_t len)
 Copies and consumes data.
inkcoreapi char * memcpy (const void *buf, int64_t len=INT64_MAX, int64_t offset=0)
 Copy data but do not consume it.
char & operator[] (int64_t i)
 Subscript operator.
MIOBufferwriter () const
MIOBufferallocated () const
 IOBufferReader ()

Data Fields

MIOBufferAccessoraccessor
MIOBuffermbuf
 Back pointer to this object's MIOBuffer.
Ptr< IOBufferBlockblock
int64_t start_offset
 Offset beyond the shared start().
int64_t size_limit

Detailed Description

An independent reader from an MIOBuffer.

A reader for a set of IOBufferBlocks. The IOBufferReader represents the place where a given consumer of buffer data is reading from. It provides a uniform interface for easily accessing the data contained in a list of IOBufferBlocks associated with the IOBufferReader.

IOBufferReaders are the abstraction that determine when data blocks can be removed from the buffer.

Definition at line 540 of file I_IOBuffer.h.


Constructor & Destructor Documentation

IOBufferReader::IOBufferReader (  )  [inline]

Definition at line 787 of file I_IOBuffer.h.


Member Function Documentation

MIOBuffer* IOBufferReader::allocated (  )  const [inline]

Definition at line 766 of file I_IOBuffer.h.

References mbuf.

TS_INLINE int IOBufferReader::block_count (  ) 

Number of IOBufferBlocks with data in the block list.

Returns the number of IOBufferBlocks on the block list with data remaining for this reader.

Returns:
number of blocks with data for this reader.

Definition at line 609 of file P_IOBuffer.h.

References block, and IOBufferBlock::next.

Referenced by MIOBuffer::max_block_count().

TS_INLINE int64_t IOBufferReader::block_read_avail (  ) 

Amount of data available in the first buffer with data for this reader.

Returns the number of unconsumed bytes of data available on the first IOBufferBlock with data for this reader.

Returns:
number of unconsumed bytes of data available in the first buffer.

Definition at line 600 of file P_IOBuffer.h.

References block, skip_empty_blocks(), and start_offset.

Referenced by NetVCTest::consume_and_check_bytes(), SocksProxy::mainEvent(), HTTPHdr::parse_req(), HTTPHdr::parse_resp(), read(), and HttpSM::state_read_push_response_header().

TS_INLINE void IOBufferReader::clear (  ) 

Clears all fields in this IOBuffeReader, rendering it unusable.

Drops the reference to the IOBufferBlock list, the accesor, MIOBuffer and resets this reader's state. You have to set those fields in order to use this object again.

Definition at line 697 of file P_IOBuffer.h.

References accessor, block, mbuf, size_limit, and start_offset.

Referenced by MIOBuffer::dealloc_reader().

TS_INLINE IOBufferReader * IOBufferReader::clone (  ) 

Create another reader with access to the same data as this IOBufferReader.

Allocates a new reader with the same state as this IOBufferReader. This means that the new reader will point to the same list of IOBufferBlocks and to the same buffer position as this reader.

Returns:
new reader with the same state as this.

Definition at line 1141 of file P_IOBuffer.h.

References MIOBuffer::clone_reader(), and mbuf.

Referenced by HttpSM::attach_client_session(), and TSIOBufferReaderClone().

TS_INLINE void IOBufferReader::consume ( int64_t  n  ) 
TS_INLINE bool IOBufferReader::current_low_water (  ) 

Consult this reader's MIOBuffer writable space.

Queries the MIOBuffer associated with this reader about the amount of writable space available without adding any blocks on the buffer and returns true if it is less than the water mark.

Returns:
true if the MIOBuffer associated with this IOBufferReader returns true in MIOBuffer::current_low_water().

Definition at line 570 of file P_IOBuffer.h.

References MIOBuffer::current_low_water(), and mbuf.

TS_INLINE void IOBufferReader::dealloc (  ) 

Deallocate this reader.

Removes and deallocates this reader from the underlying MIOBuffer. This IOBufferReader object must not be used after this call.

Definition at line 1147 of file P_IOBuffer.h.

References MIOBuffer::dealloc_reader(), and mbuf.

Referenced by HttpSM::setup_blind_tunnel(), and HttpSM::state_read_client_request_header().

TS_INLINE char * IOBufferReader::end (  ) 

End of inuse area of the first block with unconsumed data.

Returns a pointer to the end of the first block with unconsumed data for this reader. A NULL pointer indicates there are no blocks with unconsumed data for this reader.

Returns:
pointer to the end of the first block with unconsumed data.

Definition at line 591 of file P_IOBuffer.h.

References block, and skip_empty_blocks().

TS_INLINE IOBufferBlock * IOBufferReader::get_current_block (  ) 

Get a pointer to the first block with data.

Returns a pointer to the first IOBufferBlock in the block chain with data available for this reader

Returns:
pointer to the first IOBufferBlock in the list with data available for this reader.

Definition at line 576 of file P_IOBuffer.h.

References block.

Referenced by HTTPHdr::parse_req(), HTTPHdr::parse_resp(), HttpSM::state_read_client_request_header(), TSIOBufferReaderStart(), and CacheContinuation::VCdataRead().

TS_INLINE bool IOBufferReader::high_water (  ) 

To see if the amount of data available to the reader is greater than the MIOBuffer's water mark.

Indicates whether the amount of data available to this reader exceeds the water mark for this reader's MIOBuffer.

Returns:
true if the amount of data exceeds the MIOBuffer's water mark.

Definition at line 564 of file P_IOBuffer.h.

References mbuf, read_avail(), and MIOBuffer::water_mark.

bool IOBufferReader::is_read_avail_more_than ( int64_t  size  )  [inline]

Check if there is more than size bytes available to read.

Returns:
true if more than size byte are available.

Definition at line 638 of file P_IOBuffer.h.

References block, IOBufferBlock::next, IOBufferBlock::read_avail(), and start_offset.

Referenced by ProtocolProbeTrampoline::ioCompletionEvent(), and ChunkedHandler::process_chunked_content().

TS_INLINE bool IOBufferReader::low_water (  ) 

Queries the underlying MIOBuffer about.

Returns true if the amount of writable space after adding a block on the underlying MIOBuffer is less than its water mark. This function call may add blocks to the MIOBuffer (see MIOBuffer::low_water()).

Returns:
result of MIOBuffer::low_water() on the MIOBuffer for this reader.

Definition at line 558 of file P_IOBuffer.h.

References MIOBuffer::low_water(), and mbuf.

int64_t IOBufferReader::memchr ( char  c,
int64_t  len = INT64_MAX,
int64_t  offset = 0 
)

Perform a memchr() across the list of IOBufferBlocks.

Returns the offset from the current start point of the reader to the first occurence of character 'c' in the buffer.

Parameters:
c character to look for.
len number of characters to check. If len exceeds the number of bytes available on the buffer or INT64_MAX is passed in, the number of bytes available to the reader is used. It is independent of the offset value.
offset number of the bytes to skip over before beginning the operation.
Returns:
-1 if c is not found, otherwise position of the first ocurrence.

Definition at line 209 of file IOBuffer.cc.

References block, IOBufferBlock::next, IOBufferBlock::read_avail(), IOBufferBlock::start(), and start_offset.

char * IOBufferReader::memcpy ( const void *  buf,
int64_t  len = INT64_MAX,
int64_t  offset = 0 
)

Copy data but do not consume it.

Copies 'len' bytes of data from the current buffer into the supplied buffer. The copy skips the number of bytes specified by 'offset' beyond the current point of the reader. It also takes into account the current start_offset value.

Parameters:
buf in which to place the data. The pointer is modified after the call and points one position after the end of the data copied.
len bytes to copy. If len exceeds the bytes available to the reader or INT64_MAX is passed in, the number of bytes available is used instead. No data is consumed from the reader in this operation.
offset bytes to skip from the current position. The parameter is modified after the call.
Returns:
pointer to one position after the end of the data copied. The parameter buf is set to this value also.

Definition at line 242 of file IOBuffer.cc.

References block, IOBufferBlock::next, IOBufferBlock::read_avail(), IOBufferBlock::start(), and start_offset.

Referenced by copy_from_buffer_reader(), proto_is_http2(), rcv_settings_frame(), read(), and TSIOBufferReaderCopy().

TS_INLINE char & IOBufferReader::operator[] ( int64_t  i  ) 

Subscript operator.

Returns a reference to the character at the specified position. You must ensure that it is within an appropriate range.

Parameters:
i positions beyond the current point of the reader. It must be less than the number of the bytes available to the reader.
Returns:
reference to the character in that position.

Definition at line 673 of file P_IOBuffer.h.

References block, ink_assert, IOBufferBlock::next, IOBufferBlock::read_avail(), IOBufferBlock::start(), start_offset, and unlikely.

int64_t IOBufferReader::read ( void *  buf,
int64_t  len 
)

Copies and consumes data.

Copies len bytes of data from the buffer into the supplied buffer, which must be allocated prior to the call and it must be at large enough for the requested bytes. Once the data is copied, it consumed from the reader.

Parameters:
buf in which to place the data.
len bytes to copy and consume. If 'len' exceeds the bytes available to the reader, the number of bytes available is used instead.
Returns:
number of bytes copied and consumed.

Definition at line 188 of file IOBuffer.cc.

References block_read_avail(), consume(), memcpy(), read_avail(), and start().

Referenced by PrefetchBlaster::blastObject(), CacheTestSM::check_buffer(), NetTesterSM::handle_read(), and HtmlParser::ScanHtmlForURL().

TS_INLINE int64_t IOBufferReader::read_avail (  ) 

Amount of data available across all of the IOBufferBlocks.

Returns the number of unconsumed bytes of data available to this reader across all remaining IOBufferBlocks. It subtracts the current start_offset value from the total.

Returns:
bytes of data available across all the buffers.

Definition at line 622 of file P_IOBuffer.h.

References block, INT64_MAX, IOBufferBlock::next, IOBufferBlock::read_avail(), size_limit, and start_offset.

Referenced by HttpTunnel::add_producer(), KeepAliveConn::append(), HttpClientSession::attach_server_session(), TransformVConnection::backlog(), HttpTunnelProducer::backlog(), PrefetchBlaster::blastObject(), CacheTestSM::check_buffer(), consume(), NetVCTest::consume_and_check_bytes(), HttpTunnel::copy_partial_post_data(), HttpClientSession::do_io_close(), INKVConnInternal::do_io_write(), HttpSM::do_setup_post_tunnel(), ClusterState::doIO(), VIO::done(), CacheTestSM::event_handler(), CacheTestSM::fill_buffer(), ChunkedHandler::generate_chunked_content(), FetchSM::get_info_from_buffer(), NullTransform::handle_event(), TransformTerminus::handle_event(), PrefetchTransform::handle_event(), HttpSM::handle_post_failure(), NetTesterSM::handle_read(), ShowCache::handleCacheEvent(), KeepAliveConn::handleEvent(), high_water(), KeepAliveConn::init(), SocksProxy::mainEvent(), MIOBuffer::max_read_avail(), ObjectReloadCont::ObjectReloadEvent(), CacheVC::openWriteMain(), FetchSM::process_fetch_read(), FetchSM::process_fetch_write(), HttpTunnel::producer_handler(), read(), RecursiveHttpGet::RecursiveHttpGetEvent(), ClusterVConnectionBase::reenable(), CacheVC::reenable(), HttpClientSession::release(), HttpSM::server_transfer_init(), HttpSM::setup_client_read_request_header(), HttpSM::setup_push_read_response_header(), HttpSM::setup_push_transfer_to_cache(), HttpSM::setup_server_read_response_header(), OneWayTunnel::startEvent(), OneWayMultiTunnel::startEvent(), HttpSM::state_read_push_response_header(), transfer_data(), RangeTransform::transform_to_range(), TSIOBufferReaderAvail(), PrefetchUrlBlaster::udpUrlBlaster(), ClusterHandler::valid_for_data_write(), and write_to_net_io().

TS_INLINE void IOBufferReader::reset (  ) 

Instruct the reader to reset the IOBufferBlock list.

Resets the reader to the point to the start of the block where new data will be written. After this call, the start_offset field is set to zero and the list of IOBufferBlocks is set using the associated MIOBuffer.

Definition at line 707 of file P_IOBuffer.h.

References MIOBuffer::_writer, block, mbuf, size_limit, and start_offset.

Referenced by MIOBuffer::alloc_accessor(), MIOBuffer::alloc_reader(), and MIOBuffer::reset().

TS_INLINE void IOBufferReader::skip_empty_blocks (  ) 

Definition at line 549 of file P_IOBuffer.h.

References block, and start_offset.

Referenced by block_read_avail(), end(), FetchSM::get_info_from_buffer(), start(), and TSIOBufferReaderStart().

TS_INLINE char * IOBufferReader::start (  ) 

Start of unconsumed data.

Returns a pointer to first unconsumed data on the buffer for this reader. A null pointer indicates no data is available. It uses the current start_offset value.

Returns:
pointer to the start of the unconsumed data.

Definition at line 582 of file P_IOBuffer.h.

References block, skip_empty_blocks(), and start_offset.

Referenced by PrefetchBlaster::blastObject(), NetVCTest::consume_and_check_bytes(), SocksProxy::mainEvent(), HTTPHdr::parse_req(), HTTPHdr::parse_resp(), read(), HttpSM::state_read_push_response_header(), transfer_data(), and PrefetchUrlBlaster::udpUrlBlaster().

MIOBuffer* IOBufferReader::writer (  )  const [inline]

Definition at line 765 of file I_IOBuffer.h.

References mbuf.


Field Documentation

Definition at line 785 of file I_IOBuffer.h.

Referenced by clear(), MIOBuffer::clone_reader(), consume(), read_avail(), and reset().


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