#include <MemBuf.h>

Inheritance diagram for MemBuf:
Collaboration diagram for MemBuf:

Public Member Functions

void * operator new (size_t size)
 
void operator delete (void *address)
 
void * toCbdata () noexcept
 
 MemBuf ()
 
virtual ~MemBuf ()
 
char * content ()
 start of the added data More...
 
const char * content () const
 start of the added data More...
 
mb_size_t contentSize () const
 available data size More...
 
bool hasContent () const
 
char * space ()
 returns buffer after data; does not check space existence More...
 
char * space (mb_size_t required)
 
mb_size_t spaceSize () const
 
bool hasSpace () const
 
mb_size_t potentialSpaceSize () const
 
bool hasPotentialSpace () const
 
void consume (mb_size_t sz)
 removes sz bytes and "packs" by moving content left More...
 
void consumeWhitespacePrefix ()
 removes all prefix whitespace, moving content left More...
 
void appended (mb_size_t sz)
 updates content size after external append More...
 
void truncate (mb_size_t sz)
 
void terminate ()
 
bool wasStolen () const
 
void init (mb_size_t szInit, mb_size_t szMax)
 
void init ()
 
void clean ()
 
void reset ()
 
int isNull () const
 
FREEfreeFunc ()
 
virtual void append (const char *c, int sz)
 
virtual void vappendf (const char *fmt, va_list ap)
 
void appendf (const char *fmt,...) PRINTF_FORMAT_ARG2
 Append operation with printf-style arguments. More...
 
virtual void buffer ()
 
virtual void flush ()
 

Public Attributes

char * buf
 
mb_size_t size
 
mb_size_t max_capacity
 
mb_size_t capacity
 
unsigned stolen:1
 

Private Member Functions

 MemBuf (const MemBuf &)
 
MemBufoperator= (const MemBuf &)
 
void grow (mb_size_t min_cap)
 

Static Private Attributes

static cbdata_type CBDATA_MemBuf = CBDATA_UNKNOWN
 

Detailed Description

Auto-growing memory-resident buffer with Packable interface

Deprecated:
Use SBuf instead.

Definition at line 23 of file MemBuf.h.

Constructor & Destructor Documentation

MemBuf::MemBuf ( )
inline

Definition at line 28 of file MemBuf.h.

virtual MemBuf::~MemBuf ( )
inlinevirtual

Definition at line 35 of file MemBuf.h.

References buf, clean(), and stolen.

MemBuf::MemBuf ( const MemBuf )
inlineprivate

private copy constructor and assignment operator generates compiler errors if someone tries to copy/assign a MemBuf

Definition at line 120 of file MemBuf.h.

References assert.

Member Function Documentation

void MemBuf::append ( const char *  newContent,
int  sz 
)
virtual

calls memcpy, appends exactly size bytes, extends buffer or creates buffer if needed.

Implements Packable.

Definition at line 225 of file MemBuf.cc.

References appended(), assert, buf, capacity, grow(), PROF_start, PROF_stop, size, space(), and stolen.

Referenced by Client::adaptVirginReplyBody(), Format::Format::assemble(), HttpStateData::buildRequestPrefix(), clientPackRangeHdr(), Adaptation::Icap::ModXact::closeChunk(), ErrorState::Convert(), ErrorState::ConvertText(), MemStore::copyFromShmSlice(), ErrorState::DenyInfoLocation(), ErrorState::Dump(), store_client::dumpStats(), Adaptation::Icap::Xaction::fillDoneStatus(), Adaptation::Icap::ModXact::fillDoneStatus(), Adaptation::Icap::Xaction::fillPendingStatus(), Adaptation::Icap::ModXact::fillPendingStatus(), BodyPipe::getMoreData(), HttpStateData::getMoreRequestBody(), gopherSendRequest(), Ftp::Server::handleDataReply(), helperDispatch(), idnsSendQueryVC(), internalRemoteUri(), Adaptation::Icap::OptXact::makeRequest(), Adaptation::Icap::ModXact::makeRequestHeaders(), munge_menu_line(), munge_other_line(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), Http::Stream::packChunk(), Http::Stream::packRange(), ErrorPageFile::parse(), Http::Message::parseCharBuf(), BodyPipe::putMoreData(), redirectHandleReply(), Http::Stream::sendStartOfMessage(), snmpDebugOid(), statStoreEntry(), Adaptation::Ecap::ServiceRep::status(), Comm::TcpAcceptor::status(), AsyncJob::status(), Adaptation::Ecap::XactionRep::status(), Security::PeerConnector::status(), Adaptation::Icap::Xaction::status(), BodyPipe::status(), Adaptation::Icap::ServiceRep::status(), strwordquote(), testHttpReply::testSanityCheckFirstLine(), testHttpRequest::testSanityCheckStartLine(), tunnelRelayConnectRequest(), Ftp::UnescapeDoubleQuoted(), and Adaptation::Icap::ModXact::writeSomeBody().

void MemBuf::appended ( mb_size_t  sz)
void Packable::appendf ( const char *  fmt,
  ... 
)
inlineinherited

Definition at line 61 of file Packable.h.

References Packable::vappendf().

Referenced by Ftp::Server::acceptDataConnection(), aclParseAccessLine(), aclParseAclList(), Format::Format::assemble(), HttpStateData::buildRequestPrefix(), clientPackRangeHdr(), clientPackTermBound(), ErrorState::Convert(), ErrorState::ConvertText(), ErrorState::DenyInfoLocation(), ErrorState::Dump(), dump_cachemgrpasswd(), Security::ServerOptions::dumpCfg(), Security::PeerOptions::dumpCfg(), store_client::dumpStats(), Adaptation::Icap::ModXact::encapsulateHead(), errorInitialize(), Adaptation::Icap::Xaction::fillDoneStatus(), Adaptation::Icap::ModXact::fillDoneStatus(), Adaptation::Icap::Xaction::fillPendingStatus(), Adaptation::Icap::ModXact::fillPendingStatus(), HttpStateData::getMoreRequestBody(), gopherSendRequest(), Ftp::Server::handleEpsvReply(), Ftp::Server::handlePasvReply(), helperDispatch(), Ftp::Gateway::htmlifyListEntry(), httpHdrContRangePackInto(), httpHdrRangeRespSpecPackInto(), internalRemoteUri(), Adaptation::Icap::ModXact::makeAllowHeader(), Adaptation::Icap::OptXact::makeRequest(), Adaptation::Icap::ModXact::makeRequestHeaders(), Adaptation::Icap::ModXact::makeUsernameHeader(), memBufReport(), munge_menu_line(), munge_other_line(), Adaptation::Icap::ModXact::openChunk(), HttpRequest::pack(), Http::Stream::packChunk(), HttpRequest::packFirstLineInto(), HttpHdrRangeSpec::packInto(), Http::StatusLine::packInto(), HttpHdrScTarget::packInto(), HttpHdrCc::packInto(), helper::packStatsInto(), Acl::AllOf::parse(), Ftp::PrintReply(), Ftp::Client::sendEprt(), Ftp::Client::sendPassive(), ExternalACLLookup::Start(), Ident::Start(), MemObject::stat(), statStoreEntry(), Ipc::Inquirer::status(), Comm::TcpAcceptor::status(), AsyncJob::status(), Adaptation::Ecap::XactionRep::status(), Security::PeerConnector::status(), Adaptation::Icap::Xaction::status(), BodyPipe::status(), Adaptation::Icap::ServiceRep::status(), tunnelRelayConnectRequest(), urnHandleReply(), wordlistCat(), Ftp::Server::writeCustomReply(), Ftp::Server::writeEarlyReply(), and Ftp::Server::writeErrorReply().

virtual void Packable::buffer ( )
inlinevirtualinherited

start buffering appends (if relevant)

Indicates that a number of small appends are about to follow so would be detrimental to trigger expensive activity on each.

Reimplemented in StoreEntry, and CapturingStoreEntry.

Definition at line 88 of file Packable.h.

Referenced by PackableStreamBuf::PackableStreamBuf().

void MemBuf::consume ( mb_size_t  sz)
Note
there is currently no stretch() method to grow without appending

Definition at line 180 of file MemBuf.cc.

References assert, buf, contentSize(), PROF_start, PROF_stop, size, stolen, and terminate().

Referenced by Client::adaptVirginReplyBody(), BodyPipe::consume(), consumeWhitespacePrefix(), BodyPipe::getMoreData(), and ClientHttpRequest::noteMoreBodyDataAvailable().

void MemBuf::consumeWhitespacePrefix ( )

removes all whitespace prefix bytes and "packs" by moving content left

Definition at line 199 of file MemBuf.cc.

References buf, consume(), contentSize(), p, PROF_start, PROF_stop, and xisspace.

char* MemBuf::content ( )
inline

Definition at line 41 of file MemBuf.h.

References buf.

Referenced by aclParseAccessLine(), aclParseAclList(), Client::adaptVirginReplyBody(), Format::Format::assemble(), ErrorState::BuildHttpReply(), constructHelperQuery(), HttpBody::content(), ErrorState::Convert(), ErrorState::ConvertText(), Auth::SchemeConfig::CreateAuthUser(), HttpStateData::decodeAndWriteReplyBody(), ErrorState::DenyInfoLocation(), Note::Value::format(), BodyPipe::getMoreData(), HttpStateData::getMoreRequestBody(), Adaptation::Icap::OptXact::handleCommConnected(), Adaptation::Icap::ModXact::handleCommConnected(), TunnelStateData::handleConnectResponse(), helperDispatch(), helperDispatchWriteDone(), Auth::UserRequest::helperRequestKeyExtras(), httpHdrAdd(), Adaptation::Ecap::HeaderRep::image(), TunnelStateData::informUserOfPeerError(), Adaptation::Icap::OptXact::makeRequest(), Adaptation::Icap::ModXact::makeRequestHeaders(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), operator<<(), HttpBody::packInto(), Acl::AllOf::parse(), Ftp::Gateway::parseListing(), Adaptation::Icap::ModXact::prepEchoing(), redirectHandleReply(), Ftp::Client::sendEprt(), Ftp::Client::sendPassive(), snmpDebugOid(), ConnStateData::sslCrtdHandleReply(), Rock::HeaderUpdater::startWriting(), Adaptation::Ecap::ServiceRep::status(), Ipc::Inquirer::status(), Comm::TcpAcceptor::status(), AsyncJob::status(), Adaptation::Ecap::XactionRep::status(), Security::PeerConnector::status(), Adaptation::Icap::Xaction::status(), BodyPipe::status(), Adaptation::Icap::ServiceRep::status(), storeRebuildParseEntry(), testHttpReply::testSanityCheckFirstLine(), testHttpRequest::testSanityCheckStartLine(), ErrorPageFile::text(), Ftp::UnescapeDoubleQuoted(), and Adaptation::Ecap::XactionRep::vbContent().

const char* MemBuf::content ( ) const
inline

Definition at line 44 of file MemBuf.h.

References buf.

mb_size_t MemBuf::contentSize ( ) const
inline

Definition at line 47 of file MemBuf.h.

References size.

Referenced by Client::adaptVirginReplyBody(), ErrorState::BuildHttpReply(), BodyPipe::checkIn(), consume(), consumeWhitespacePrefix(), HttpBody::contentSize(), ErrorState::Convert(), ErrorState::ConvertText(), HttpStateData::decodeAndWriteReplyBody(), ErrorState::DenyInfoLocation(), Adaptation::Icap::ModXact::encapsulateHead(), BodyPipe::getMoreData(), HttpStateData::getMoreRequestBody(), TunnelStateData::handleConnectResponse(), Client::handleMoreAdaptedBodyAvailable(), HttpBody::hasContent(), helperDispatch(), helperDispatchWriteDone(), htcpTstReply(), idnsDoSendQueryVC(), idnsReadVC(), Adaptation::Ecap::HeaderRep::image(), TunnelStateData::informUserOfPeerError(), Adaptation::Icap::OptXact::makeRequest(), Adaptation::Icap::ModXact::makeRequestHeaders(), BodySink::noteMoreBodyDataAvailable(), ClientHttpRequest::noteMoreBodyDataAvailable(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), HttpBody::packInto(), Ftp::Gateway::parseListing(), Adaptation::Icap::ModXact::prepEchoing(), redirectHandleReply(), Http::Stream::sendBody(), Client::sendMoreRequestBody(), Http::Stream::sendStartOfMessage(), ConnStateData::sslCrtdHandleReply(), Rock::HeaderUpdater::startWriting(), BodyPipe::status(), storeRebuildParseEntry(), testHttpReply::testSanityCheckFirstLine(), testHttpRequest::testSanityCheckStartLine(), truncate(), BodyPipe::undoCheckOut(), urnHandleReply(), Adaptation::Ecap::XactionRep::vbContent(), Adaptation::Ecap::XactionRep::vbContentShift(), Adaptation::Icap::ModXact::virginConsume(), and Adaptation::Icap::ModXact::writeSomeBody().

virtual void Packable::flush ( )
inlinevirtualinherited

perform a buffer flush (if relevant)

Used by code such as PackableStream, that assumes the Packable leads to some form of output buffer.

Reimplemented in StoreEntry, and CapturingStoreEntry.

Definition at line 95 of file Packable.h.

Referenced by PackableStreamBuf::sync().

FREE * MemBuf::freeFunc ( )

freezes the object! and returns function to clear it up.

Return values
free()function to be used.

Important: calling this function "freezes" mb, do not update mb after that in any way (you still can read-access .buf and .size)

Return values
free()function to be used.

Definition at line 328 of file MemBuf.cc.

References assert, buf, capacity, memFreeBufFunc(), and stolen.

Referenced by file_write_mbuf(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), tunnelRelayConnectRequest(), and Comm::Write().

void MemBuf::grow ( mb_size_t  min_cap)
private

Grows (doubles) internal buffer to satisfy required minimal capacity

Definition at line 343 of file MemBuf.cc.

References assert, buf, capacity, max_capacity, memReallocBuf(), PROF_start, PROF_stop, size_t, and stolen.

Referenced by append(), init(), space(), and vappendf().

bool MemBuf::hasContent ( ) const
inline
bool MemBuf::hasPotentialSpace ( ) const
inline

Definition at line 75 of file MemBuf.h.

References potentialSpaceSize().

bool MemBuf::hasSpace ( ) const
inline

Whether the buffer contains any data space available.

Return values
trueif data can be added to the buffer
falseif the buffer is full

Definition at line 72 of file MemBuf.h.

References capacity, and size.

Referenced by TunnelStateData::handleConnectResponse(), and storeRebuildLoadEntry().

void MemBuf::init ( mb_size_t  szInit,
mb_size_t  szMax 
)

init with specific sizes

Definition at line 105 of file MemBuf.cc.

References assert, buf, capacity, grow(), max_capacity, NULL, size, stolen, and terminate().

Referenced by Ftp::Server::acceptDataConnection(), aclParseAccessLine(), aclParseAclList(), Client::adaptVirginReplyBody(), Format::Format::assemble(), BodyPipe::BodyPipe(), ErrorState::BuildHttpReply(), ErrorState::ConvertText(), MemStore::copyFromShmSlice(), debugObj(), HttpStateData::decodeAndWriteReplyBody(), Helper::Reply::emptyBuf(), Ssl::ErrorDetailFile::ErrorDetailFile(), ErrorPageFile::ErrorPageFile(), Adaptation::Icap::ModXact::finalizeLogInfo(), BodyPipe::getMoreData(), HttpStateData::getMoreRequestBody(), gopherSendRequest(), Adaptation::Icap::OptXact::handleCommConnected(), Adaptation::Icap::ModXact::handleCommConnected(), Ftp::Server::handleDataReply(), Ftp::Server::handleEpsvReply(), Ftp::Server::handlePasvReply(), Ftp::Server::handleRequest(), helperDispatch(), htcpClear(), htcpQuery(), htcpTstReply(), Ftp::Gateway::htmlifyListEntry(), httpHdrAdd(), httpHeaderPutStrvf(), idnsReadVCHeader(), Adaptation::Ecap::HeaderRep::image(), makeExternalAclKey(), Adaptation::Icap::ModXact::makeRequestHeaders(), ClientHttpRequest::mRangeCLen(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), HttpReply::pack(), Acl::AllOf::parse(), Http::Message::parseCharBuf(), prepareLogWithRequestDetails(), Adaptation::Icap::ModXact::prepEchoing(), HttpHeader::putCc(), HttpHeader::putContRange(), HttpHeader::putRange(), HttpHeader::putSc(), read_reply(), Fs::Ufs::RebuildState::rebuildFromDirectory(), redirectHandleReply(), Http::Stream::sendBody(), HttpStateData::sendRequest(), snmpDebugOid(), ExternalACLLookup::Start(), Ident::Start(), statObjects(), testHttpReply::testSanityCheckFirstLine(), testHttpRequest::testSanityCheckStartLine(), tunnelRelayConnectRequest(), urnHandleReply(), Ftp::Server::writeCustomReply(), Ftp::Server::writeEarlyReply(), Ftp::Server::writeErrorReply(), Ftp::Server::writeForwardedReplyAndCall(), and Adaptation::Icap::ModXact::writeSomeBody().

void MemBuf::init ( void  )

init with defaults

Definition at line 98 of file MemBuf.cc.

References MEM_BUF_INIT_SIZE, and MEM_BUF_MAX_SIZE.

Referenced by reset().

int MemBuf::isNull ( ) const

unfirtunate hack to test if the buffer has been Init()ialized

Unfortunate hack to test if the buffer has been Init()ialized

Definition at line 157 of file MemBuf.cc.

References assert, buf, capacity, max_capacity, and size.

Referenced by clean(), Helper::Reply::emptyBuf(), BodyPipe::getMoreData(), helperDispatch(), helperDispatchWriteDone(), Helper::Reply::other(), reset(), and snmpDebugOid().

void MemBuf::operator delete ( void *  address)
inline

Definition at line 25 of file MemBuf.h.

void* MemBuf::operator new ( size_t  size)
inline

Definition at line 25 of file MemBuf.h.

MemBuf& MemBuf::operator= ( const MemBuf )
inlineprivate

Definition at line 122 of file MemBuf.h.

References assert.

mb_size_t MemBuf::potentialSpaceSize ( ) const
char* MemBuf::space ( )
inline

space to add data

Definition at line 57 of file MemBuf.h.

References buf, and size.

Referenced by append(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), TunnelStateData::readConnectResponse(), storeRebuildLoadEntry(), and terminate().

char* MemBuf::space ( mb_size_t  required)
inline

Returns buffer following data, after possibly growing the buffer to accommodate addition of the required bytes PLUS a 0-terminator char. The caller is not required to terminate the buffer, but MemBuf does terminate internally, trading termination for size calculation bugs.

Definition at line 63 of file MemBuf.h.

References buf, capacity, grow(), and size.

void* MemBuf::toCbdata ( )
inlinenoexcept

Definition at line 25 of file MemBuf.h.

void MemBuf::truncate ( mb_size_t  sz)

Definition at line 213 of file MemBuf.cc.

References assert, contentSize(), size, and stolen.

void MemBuf::vappendf ( const char *  fmt,
va_list  vargs 
)
virtual

vappendf for other printf()'s to use; calls vsnprintf, extends buf if needed

Implements Packable.

Definition at line 269 of file MemBuf.cc.

References assert, buf, capacity, grow(), max_capacity, size, and stolen.

Referenced by httpHeaderPutStrvf().

bool MemBuf::wasStolen ( ) const
inline

Definition at line 87 of file MemBuf.h.

References stolen.

Member Data Documentation

mb_size_t MemBuf::capacity

allocated space

Deprecated:
Use interface function instead TODO: make these private after converting memBuf*() functions to methods

Definition at line 149 of file MemBuf.h.

Referenced by append(), appended(), clean(), freeFunc(), grow(), hasSpace(), init(), isNull(), reset(), space(), spaceSize(), terminate(), and vappendf().

cbdata_type MemBuf::CBDATA_MemBuf = CBDATA_UNKNOWN
staticprivate

Definition at line 25 of file MemBuf.h.

mb_size_t MemBuf::max_capacity

when grows: assert(new_capacity <= max_capacity)

Deprecated:
Use interface function instead TODO: make these private after converting memBuf*() functions to methods

Definition at line 142 of file MemBuf.h.

Referenced by clean(), Adaptation::Icap::ModXact::estimateVirginBody(), HttpStateData::getMoreRequestBody(), grow(), init(), isNull(), potentialSpaceSize(), and vappendf().

unsigned MemBuf::stolen

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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors