#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 ()
 
 ~MemBuf () override
 
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 ()
 
void append (const char *c, int sz) override
 
void vappendf (const char *fmt, va_list ap) override
 
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() [1/2]

MemBuf::MemBuf ( )
inline

Definition at line 28 of file MemBuf.h.

◆ ~MemBuf()

MemBuf::~MemBuf ( )
inlineoverride

Definition at line 35 of file MemBuf.h.

References buf, clean(), and stolen.

◆ MemBuf() [2/2]

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

◆ append()

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

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

Implements Packable.

Definition at line 209 of file MemBuf.cc.

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

Referenced by Client::adaptVirginReplyBody(), Format::Format::assemble(), Format::AssembleOne(), HttpStateData::buildRequestPrefix(), clientPackRangeHdr(), Adaptation::Icap::ModXact::closeChunk(), ErrorState::compileLegacyCode(), 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(), 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(), Http::Message::parseCharBuf(), BodyPipe::putMoreData(), redirectHandleReply(), Http::Stream::sendStartOfMessage(), snmpDebugOid(), statStoreEntry(), Adaptation::Ecap::ServiceRep::status(), AsyncJob::status(), BodyPipe::status(), Adaptation::Ecap::XactionRep::status(), Adaptation::Icap::ServiceRep::status(), Adaptation::Icap::Xaction::status(), Http::Tunneler::status(), Comm::TcpAcceptor::status(), Security::PeerConnector::status(), strwordquote(), TestEvent::testDump(), TestHttpReply::testSanityCheckFirstLine(), TestHttpRequest::testSanityCheckStartLine(), Ftp::UnescapeDoubleQuoted(), Http::Tunneler::writeRequest(), and Adaptation::Icap::ModXact::writeSomeBody().

◆ appended()

void MemBuf::appended ( mb_size_t  sz)

Definition at line 226 of file MemBuf.cc.

References assert, capacity, size, and terminate().

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

◆ appendf()

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::compileLegacyCode(), ErrorState::Dump(), EventScheduler::dump(), dump_cachemgrpasswd(), store_client::dumpStats(), Adaptation::Icap::ModXact::encapsulateHead(), Adaptation::Icap::Xaction::fillDoneStatus(), Adaptation::Icap::ModXact::fillDoneStatus(), Adaptation::Icap::Xaction::fillPendingStatus(), Adaptation::Icap::ModXact::fillPendingStatus(), HttpStateData::getMoreRequestBody(), Ftp::Server::handleEpsvReply(), Ftp::Server::handlePasvReply(), helperDispatch(), 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(), Http::StatusLine::packInto(), HttpHdrCc::packInto(), HttpHdrScTarget::packInto(), HttpHdrRangeSpec::packInto(), Helper::Client::packStatsInto(), Acl::AllOf::parse(), Ftp::PrintReply(), Ftp::Client::sendEprt(), Ftp::Client::sendPassive(), ExternalACLLookup::Start(), Ident::Start(), MemObject::stat(), statStoreEntry(), AsyncJob::status(), BodyPipe::status(), Adaptation::Ecap::XactionRep::status(), Adaptation::Icap::ServiceRep::status(), Adaptation::Icap::Xaction::status(), Http::Tunneler::status(), Comm::TcpAcceptor::status(), Ipc::Inquirer::status(), Security::PeerConnector::status(), wordlistCat(), Ftp::Server::writeCustomReply(), Ftp::Server::writeEarlyReply(), Ftp::Server::writeErrorReply(), and Http::Tunneler::writeRequest().

◆ buffer()

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.

◆ clean()

◆ consume()

void MemBuf::consume ( mb_size_t  sz)

◆ consumeWhitespacePrefix()

void MemBuf::consumeWhitespacePrefix ( )

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

Definition at line 185 of file MemBuf.cc.

References buf, consume(), contentSize(), and xisspace.

◆ content() [1/2]

char * MemBuf::content ( )
inline

Definition at line 41 of file MemBuf.h.

References buf.

Referenced by aclParseAccessLine(), aclParseAclList(), Client::adaptVirginReplyBody(), Format::Format::assemble(), ErrorState::compileLegacyCode(), ErrorState::compileLogformatCode(), constructHelperQuery(), Auth::SchemeConfig::CreateAuthUser(), HttpStateData::decodeAndWriteReplyBody(), Note::Value::format(), BodyPipe::getMoreData(), HttpStateData::getMoreRequestBody(), helperDispatch(), Auth::UserRequest::helperRequestKeyExtras(), Log::Format::HttpdCombined(), Log::Format::HttpdCommon(), httpHdrAdd(), Adaptation::Ecap::HeaderRep::image(), Adaptation::Icap::OptXact::makeRequest(), Adaptation::Icap::ModXact::makeRequestHeaders(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), Helper::operator<<(), HttpReply::packHeadersUsingSlowPacker(), Acl::AllOf::parse(), Ftp::Gateway::parseListing(), Adaptation::Icap::ModXact::prepEchoing(), redirectHandleReply(), Ftp::Client::sendEprt(), Ftp::Client::sendPassive(), snmpDebugOid(), Log::Format::SquidNative(), ConnStateData::sslCrtdHandleReply(), Adaptation::Icap::ModXact::startShoveling(), Adaptation::Icap::OptXact::startShoveling(), Adaptation::Ecap::ServiceRep::status(), AsyncJob::status(), BodyPipe::status(), Adaptation::Ecap::XactionRep::status(), Adaptation::Icap::ServiceRep::status(), Adaptation::Icap::Xaction::status(), Http::Tunneler::status(), Comm::TcpAcceptor::status(), Ipc::Inquirer::status(), Security::PeerConnector::status(), TestEvent::testDump(), TestHttpReply::testSanityCheckFirstLine(), TestHttpRequest::testSanityCheckStartLine(), Ftp::UnescapeDoubleQuoted(), Store::UnpackIndexSwapMeta(), Adaptation::Ecap::XactionRep::vbContent(), and ZeroedSlot().

◆ content() [2/2]

const char * MemBuf::content ( ) const
inline

Definition at line 44 of file MemBuf.h.

References buf.

◆ contentSize()

◆ flush()

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.

◆ freeFunc()

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 303 of file MemBuf.cc.

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

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

◆ grow()

void MemBuf::grow ( mb_size_t  min_cap)
private

Grows (doubles) internal buffer to satisfy required minimal capacity

Definition at line 318 of file MemBuf.cc.

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

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

◆ hasContent()

◆ hasPotentialSpace()

bool MemBuf::hasPotentialSpace ( ) const
inline

Definition at line 75 of file MemBuf.h.

References potentialSpaceSize().

◆ hasSpace()

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

◆ init() [1/2]

void MemBuf::init ( void  )

init with defaults

Definition at line 86 of file MemBuf.cc.

References init(), MEM_BUF_INIT_SIZE, and MEM_BUF_MAX_SIZE.

Referenced by init(), and reset().

◆ init() [2/2]

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

init with specific sizes

Definition at line 93 of file MemBuf.cc.

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

Referenced by BodyPipe::BodyPipe(), Ftp::Server::acceptDataConnection(), aclParseAccessLine(), aclParseAclList(), Client::adaptVirginReplyBody(), Format::Format::assemble(), debugObj(), HttpStateData::decodeAndWriteReplyBody(), Helper::Reply::emptyBuf(), BodyPipe::getMoreData(), HttpStateData::getMoreRequestBody(), Ftp::Server::handleDataReply(), Ftp::Server::handleEpsvReply(), Ftp::Server::handlePasvReply(), Ftp::Server::handleRequest(), helperDispatch(), htcpClear(), htcpQuery(), htcpTstReply(), Log::Format::HttpdCombined(), Log::Format::HttpdCommon(), httpHdrAdd(), httpHeaderPutStrvf(), idnsReadVCHeader(), Adaptation::Ecap::HeaderRep::image(), Ftp::Client::initReadBuf(), makeExternalAclKey(), Adaptation::Icap::ModXact::makeRequestHeaders(), ClientHttpRequest::mRangeCLen(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), HttpReply::pack(), HttpReply::packHeadersUsingSlowPacker(), Acl::AllOf::parse(), Http::Message::parseCharBuf(), Ftp::Gateway::parseListing(), 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(), Log::Format::SquidNative(), ExternalACLLookup::Start(), Ident::Start(), Adaptation::Icap::ModXact::startShoveling(), Adaptation::Icap::OptXact::startShoveling(), statObjects(), TestEvent::testDump(), TestHttpReply::testSanityCheckFirstLine(), TestHttpRequest::testSanityCheckStartLine(), Ftp::Server::writeCustomReply(), Ftp::Server::writeEarlyReply(), Ftp::Server::writeErrorReply(), Ftp::Server::writeForwardedReplyAndCall(), Http::Tunneler::writeRequest(), and Adaptation::Icap::ModXact::writeSomeBody().

◆ isNull()

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 145 of file MemBuf.cc.

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

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

◆ operator delete()

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

Definition at line 25 of file MemBuf.h.

◆ operator new()

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

Definition at line 25 of file MemBuf.h.

◆ operator=()

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

Definition at line 122 of file MemBuf.h.

References assert.

◆ potentialSpaceSize()

mb_size_t MemBuf::potentialSpaceSize ( ) const

◆ reset()

◆ space() [1/2]

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(), storeRebuildLoadEntry(), and terminate().

◆ space() [2/2]

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.

◆ spaceSize()

mb_size_t MemBuf::spaceSize ( ) const

◆ terminate()

void MemBuf::terminate ( )

Null-terminate in case we are used as a string. Extra octet is not counted in the content size (or space size)

Note
XXX: but the extra octet is counted when growth decisions are made! This will cause the buffer to grow when spaceSize() == 1 on append, which will assert() if the buffer cannot grow any more.

Definition at line 241 of file MemBuf.cc.

References assert, capacity, size, and space().

Referenced by aclParseAccessLine(), aclParseAclList(), appended(), consume(), init(), Adaptation::Icap::OptXact::makeRequest(), Acl::AllOf::parse(), Http::Message::parseCharBuf(), Adaptation::Icap::ModXact::prepEchoing(), Adaptation::Icap::ModXact::startShoveling(), Adaptation::Icap::OptXact::startShoveling(), Adaptation::Ecap::ServiceRep::status(), AsyncJob::status(), BodyPipe::status(), Adaptation::Ecap::XactionRep::status(), Adaptation::Icap::ServiceRep::status(), Adaptation::Icap::Xaction::status(), Http::Tunneler::status(), Ipc::Inquirer::status(), and Security::PeerConnector::status().

◆ toCbdata()

void * MemBuf::toCbdata ( )
inlinenoexcept

Definition at line 25 of file MemBuf.h.

◆ truncate()

void MemBuf::truncate ( mb_size_t  sz)

Definition at line 197 of file MemBuf.cc.

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

◆ vappendf()

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

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

Implements Packable.

Definition at line 251 of file MemBuf.cc.

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

Referenced by httpHeaderPutStrvf().

◆ wasStolen()

bool MemBuf::wasStolen ( ) const
inline

Definition at line 87 of file MemBuf.h.

References stolen.

Member Data Documentation

◆ buf

◆ capacity

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_MemBuf

cbdata_type MemBuf::CBDATA_MemBuf = CBDATA_UNKNOWN
staticprivate

Definition at line 25 of file MemBuf.h.

◆ max_capacity

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

◆ size

◆ stolen

unsigned MemBuf::stolen

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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors