|
Squid Web Cache v8/master
|
#include <MemBuf.h>
Public Member Functions | |
| CBDATA_DECL_ (MemBuf, noexcept) | |
| MemBuf () | |
| ~MemBuf () override | |
| char * | content () |
| start of the added data | |
| const char * | content () const |
| start of the added data | |
| mb_size_t | contentSize () const |
| available data size | |
| bool | hasContent () const |
| char * | space () |
| returns buffer after data; does not check space existence | |
| 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 | |
| void | consumeWhitespacePrefix () |
| removes all prefix whitespace, moving content left | |
| void | appended (mb_size_t sz) |
| updates content size after external append | |
| 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 |
| FREE * | freeFunc () |
| 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. | |
| 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 &) | |
| MemBuf & | operator= (const MemBuf &) |
| void | grow (mb_size_t min_cap) |
Auto-growing memory-resident buffer with Packable interface
|
inlineoverride |
|
inlineprivate |
|
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(), 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(), 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().
| 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(), storeRebuildLoadEntry(), and storeRebuildLoadEntry().
|
inlineinherited |
Definition at line 61 of file Packable.h.
References Packable::vappendf().
Referenced by Ftp::Server::acceptDataConnection(), Format::Format::assemble(), HttpStateData::buildRequestPrefix(), clientPackRangeHdr(), clientPackTermBound(), ErrorState::compileLegacyCode(), EventScheduler::dump(), dump_cachemgrpasswd(), 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(), 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(), Adaptation::Icap::ModXact::openChunk(), Http::Stream::packChunk(), HttpRequest::packFirstLineInto(), Http::StatusLine::packInto(), HttpHdrCc::packInto(), HttpHdrScTarget::packInto(), HttpHdrRangeSpec::packInto(), Helper::Client::packStatsInto(), Ftp::PrintReply(), Ftp::Client::sendEprt(), Ftp::Client::sendPassive(), ACLExternal::startLookup(), 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().
|
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.
| MemBuf::CBDATA_DECL_ | ( | MemBuf | , |
| noexcept | |||
| ) |
| void MemBuf::clean | ( | ) |
cleans mb; last function to call if you do not give .buf away
cleans the mb; last function to call if you do not give .buf away with memBufFreeFunc
Definition at line 110 of file MemBuf.cc.
References assert, buf, capacity, isNull(), max_capacity, memFreeBuf(), size, and stolen.
Referenced by BodyPipe::~BodyPipe(), ~MemBuf(), debugObj(), helperDispatchWriteDone(), htcpClear(), htcpQuery(), htcpTstReply(), httpHeaderPutStrvf(), idnsReadVC(), ACLExternal::makeExternalAclKey(), Adaptation::Icap::ModXact::makeRequestHeaders(), ClientHttpRequest::mRangeCLen(), Http::Message::parseCharBuf(), prepareLogWithRequestDetails(), Adaptation::Icap::ModXact::prepEchoing(), HttpHeader::putCc(), HttpHeader::putContRange(), HttpHeader::putRange(), HttpHeader::putSc(), ACLExternal::startLookup(), statObjects(), and Adaptation::Icap::ModXact::writeSomeBody().
| void MemBuf::consume | ( | mb_size_t | sz | ) |
Definition at line 168 of file MemBuf.cc.
References assert, buf, contentSize(), size, stolen, and terminate().
Referenced by Client::adaptVirginReplyBody(), BodyPipe::consume(), consumeWhitespacePrefix(), BodyPipe::getMoreData(), Client::handleMoreAdaptedBodyAvailable(), and ClientHttpRequest::noteMoreBodyDataAvailable().
| void MemBuf::consumeWhitespacePrefix | ( | ) |
|
inline |
Definition at line 41 of file MemBuf.h.
References buf.
Referenced by Client::adaptVirginReplyBody(), Format::Format::assemble(), ErrorState::compileLegacyCode(), ErrorState::compileLogformatCode(), constructHelperQuery(), Auth::SchemeConfig::CreateAuthUser(), HttpStateData::decodeAndWriteReplyBody(), ErrorState::Dump(), 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(), 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().
|
inline |
|
inline |
Definition at line 47 of file MemBuf.h.
References size.
Referenced by Client::adaptVirginReplyBody(), Format::Format::assemble(), BodyPipe::checkIn(), ErrorState::compileLegacyCode(), ErrorState::compileLogformatCode(), consume(), consumeWhitespacePrefix(), HttpStateData::decodeAndWriteReplyBody(), Adaptation::Icap::ModXact::encapsulateHead(), BodyPipe::getMoreData(), HttpStateData::getMoreRequestBody(), Client::handleMoreAdaptedBodyAvailable(), helperDispatch(), htcpTstReply(), idnsDoSendQueryVC(), idnsReadVC(), idnsSendQueryVC(), Adaptation::Ecap::HeaderRep::image(), Adaptation::Icap::OptXact::makeRequest(), Adaptation::Icap::ModXact::makeRequestHeaders(), BodySink::noteMoreBodyDataAvailable(), ClientHttpRequest::noteMoreBodyDataAvailable(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), HttpReply::packHeadersUsingSlowPacker(), Ftp::Gateway::parseListing(), Adaptation::Icap::ModXact::prepEchoing(), HttpStateData::readReply(), redirectHandleReply(), Http::Stream::sendBody(), Client::sendMoreRequestBody(), Http::Stream::sendStartOfMessage(), ConnStateData::sslCrtdHandleReply(), BodyPipe::status(), TestEvent::testDump(), TestHttpReply::testSanityCheckFirstLine(), TestHttpRequest::testSanityCheckStartLine(), clientReplyContext::traceReply(), truncate(), BodyPipe::undoCheckOut(), Store::UnpackIndexSwapMeta(), Adaptation::Ecap::XactionRep::vbContent(), Adaptation::Ecap::XactionRep::vbContentShift(), Adaptation::Icap::ModXact::virginConsume(), Adaptation::Icap::ModXact::writeSomeBody(), and ZeroedSlot().
|
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.
| FREE * MemBuf::freeFunc | ( | ) |
freezes the object! and returns function to clear it up.
| 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)
| free() | function to be used. |
Definition at line 303 of file MemBuf.cc.
References assert, buf, capacity, memFreeBufFunc(), and stolen.
Referenced by Fs::Ufs::UFSSwapDir::openTmpSwapLog(), and Comm::Write().
|
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().
|
inline |
Whether the buffer contains any data.
| true | if data exists in the buffer |
| false | if data exists in the buffer |
Definition at line 54 of file MemBuf.h.
References size.
Referenced by constructHelperQuery(), Auth::SchemeConfig::CreateAuthUser(), BodyPipe::getMoreData(), ConnStateData::handleChunkedRequestBody(), Helper::operator<<(), redirectHandleReply(), BodyPipe::setConsumerIfNotLate(), ConnStateData::sslCrtdHandleReply(), BodyPipe::startAutoConsumptionIfNeeded(), and Adaptation::Icap::ModXact::writeSomeBody().
|
inline |
Definition at line 75 of file MemBuf.h.
References potentialSpaceSize().
Referenced by HttpStateData::readReply().
|
inline |
Whether the buffer contains any data space available.
| true | if data can be added to the buffer |
| false | if the buffer is full |
Definition at line 72 of file MemBuf.h.
References capacity, and size.
Referenced by storeRebuildLoadEntry(), and storeRebuildLoadEntry().
| void MemBuf::init | ( | ) |
init with defaults
Definition at line 86 of file MemBuf.cc.
References init(), MEM_BUF_INIT_SIZE, and MEM_BUF_MAX_SIZE.
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(), Client::adaptVirginReplyBody(), Format::Format::assemble(), debugObj(), HttpStateData::decodeAndWriteReplyBody(), ErrorState::Dump(), 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(), idnsSendQueryVC(), Adaptation::Ecap::HeaderRep::image(), Ftp::Client::initReadBuf(), ACLExternal::makeExternalAclKey(), Adaptation::Icap::ModXact::makeRequestHeaders(), ClientHttpRequest::mRangeCLen(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), HttpReply::pack(), HttpReply::packHeadersUsingSlowPacker(), Http::Message::parseCharBuf(), Ftp::Gateway::parseListing(), prepareLogWithRequestDetails(), Adaptation::Icap::ModXact::prepEchoing(), HttpHeader::putCc(), HttpHeader::putContRange(), HttpHeader::putRange(), HttpHeader::putSc(), Fs::Ufs::RebuildState::rebuildFromDirectory(), redirectHandleReply(), Http::Stream::sendBody(), HttpStateData::sendRequest(), Log::Format::SquidNative(), ACLExternal::startLookup(), Adaptation::Icap::ModXact::startShoveling(), Adaptation::Icap::OptXact::startShoveling(), statObjects(), TestEvent::testDump(), TestHttpReply::testSanityCheckFirstLine(), TestHttpRequest::testSanityCheckStartLine(), clientReplyContext::traceReply(), Ftp::Server::writeCustomReply(), Ftp::Server::writeEarlyReply(), Ftp::Server::writeErrorReply(), Ftp::Server::writeForwardedReplyAndCall(), Http::Tunneler::writeRequest(), and Adaptation::Icap::ModXact::writeSomeBody().
| 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(), idnsSendQueryVC(), Helper::Reply::other(), and reset().
| mb_size_t MemBuf::potentialSpaceSize | ( | ) | const |
Definition at line 161 of file MemBuf.cc.
References max_capacity, and size.
Referenced by Client::calcBufferSpaceToReserve(), BodyPipe::getMoreData(), hasPotentialSpace(), idnsSendQueryVC(), BodyPipe::putMoreData(), and Adaptation::Icap::ModXact::virginConsume().
| void MemBuf::reset | ( | ) |
resets mb preserving (or initializing if needed) memory buffer
Cleans the buffer without changing its capacity if called with a Null buffer, calls memBufDefInit()
Definition at line 129 of file MemBuf.cc.
References assert, buf, capacity, init(), isNull(), size, and stolen.
Referenced by ErrorState::compileLegacyCode(), ErrorState::compileLogformatCode(), constructHelperQuery(), Auth::SchemeConfig::CreateAuthUser(), errorInitialize(), Note::Value::format(), Auth::UserRequest::helperRequestKeyExtras(), htcpTstReply(), internalRemoteUri(), ACLExternal::makeExternalAclKey(), ClientHttpRequest::mRangeCLen(), prepareLogWithRequestDetails(), Ftp::Client::sendEprt(), Ftp::Client::sendPassive(), snmpDebugOid(), Log::Format::SquidCustom(), 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(), TestHttpReply::testSanityCheckFirstLine(), TestHttpRequest::testSanityCheckStartLine(), and Ftp::UnescapeDoubleQuoted().
|
inline |
space to add data
Definition at line 57 of file MemBuf.h.
Referenced by append(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), storeRebuildLoadEntry(), storeRebuildLoadEntry(), and terminate().
|
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.
| mb_size_t MemBuf::spaceSize | ( | ) | const |
Definition at line 155 of file MemBuf.cc.
References capacity, and size.
Referenced by BodyPipe::status(), storeRebuildLoadEntry(), and storeRebuildLoadEntry().
| 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)
Definition at line 241 of file MemBuf.cc.
References assert, capacity, size, and space().
Referenced by appended(), consume(), init(), Adaptation::Icap::OptXact::makeRequest(), 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().
| void MemBuf::truncate | ( | mb_size_t | sz | ) |
|
overridevirtual |
| char* MemBuf::buf |
TODO: hide these members completely and remove 0-termination so that consume() does not need to memmove all the time
Definition at line 134 of file MemBuf.h.
Referenced by ~MemBuf(), append(), clean(), ErrorState::compileLegacyCode(), consume(), consumeWhitespacePrefix(), content(), content(), debugObj(), freeFunc(), grow(), Ftp::Server::handleEpsvReply(), Ftp::Server::handlePasvReply(), Ftp::Server::handleRequest(), htcpClear(), htcpQuery(), htcpTstReply(), httpHeaderPutStrvf(), idnsReadVC(), idnsReadVCHeader(), init(), internalRemoteUri(), isNull(), ACLExternal::makeExternalAclKey(), Http::Message::parseCharBuf(), prepareLogWithRequestDetails(), HttpHeader::putCc(), HttpHeader::putContRange(), HttpHeader::putRange(), HttpHeader::putSc(), reset(), HttpStateData::sendRequest(), Http::Stream::sendStartOfMessage(), space(), space(), Log::Format::SquidCustom(), ACLExternal::startLookup(), statObjects(), clientReplyContext::traceReply(), vappendf(), Comm::Write(), Http::One::Server::writeControlMsgAndCall(), Ftp::Server::writeForwardedReplyAndCall(), Ftp::Server::writeReply(), and Http::Tunneler::writeRequest().
| mb_size_t MemBuf::capacity |
allocated space
Definition at line 149 of file MemBuf.h.
Referenced by append(), appended(), clean(), freeFunc(), grow(), hasSpace(), init(), isNull(), reset(), space(), spaceSize(), terminate(), and vappendf().
| mb_size_t MemBuf::max_capacity |
when grows: assert(new_capacity <= max_capacity)
Definition at line 142 of file MemBuf.h.
Referenced by clean(), Adaptation::Icap::ModXact::estimateVirginBody(), HttpStateData::getMoreRequestBody(), grow(), init(), isNull(), potentialSpaceSize(), and vappendf().
| mb_size_t MemBuf::size |
Definition at line 135 of file MemBuf.h.
Referenced by append(), appended(), HttpStateData::buildRequestPrefix(), clean(), clientPackTermBound(), consume(), contentSize(), Ftp::Server::handleEpsvReply(), Ftp::Server::handlePasvReply(), hasContent(), hasSpace(), idnsReadVC(), init(), isNull(), ACLExternal::makeExternalAclKey(), ClientHttpRequest::mRangeCLen(), Http::Message::parseCharBuf(), potentialSpaceSize(), reset(), space(), space(), spaceSize(), statObjects(), terminate(), clientReplyContext::traceReply(), truncate(), vappendf(), and Comm::Write().
| unsigned MemBuf::stolen |
Definition at line 151 of file MemBuf.h.
Referenced by ~MemBuf(), append(), Format::Format::assemble(), clean(), consume(), freeFunc(), grow(), init(), reset(), truncate(), vappendf(), and wasStolen().