proxygen
|
#include <IOBuf.h>
Classes | |
struct | DeleterBase |
struct | HeapFullStorage |
struct | HeapPrefix |
struct | HeapStorage |
struct | InternalConstructor |
class | Iterator |
struct | SharedInfo |
struct | UniquePtrDeleter |
Public Types | |
enum | CreateOp { CREATE } |
enum | WrapBufferOp { WRAP_BUFFER } |
enum | TakeOwnershipOp { TAKE_OWNERSHIP } |
enum | CopyBufferOp { COPY_BUFFER } |
typedef ByteRange | value_type |
typedef Iterator | iterator |
typedef Iterator | const_iterator |
typedef void(* | FreeFunction) (void *buf, void *userData) |
Public Member Functions | |
IOBuf (CreateOp, std::size_t capacity) | |
IOBuf (TakeOwnershipOp op, void *buf, std::size_t capacity, FreeFunction freeFn=nullptr, void *userData=nullptr, bool freeOnError=true) | |
IOBuf (TakeOwnershipOp, void *buf, std::size_t capacity, std::size_t length, FreeFunction freeFn=nullptr, void *userData=nullptr, bool freeOnError=true) | |
IOBuf (WrapBufferOp op, const void *buf, std::size_t capacity) noexcept | |
IOBuf (WrapBufferOp op, ByteRange br) noexcept | |
IOBuf (CopyBufferOp op, const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0) | |
IOBuf (CopyBufferOp op, ByteRange br, std::size_t headroom=0, std::size_t minTailroom=0) | |
IOBuf (CopyBufferOp op, const std::string &buf, std::size_t headroom=0, std::size_t minTailroom=0) | |
~IOBuf () | |
bool | empty () const |
const uint8_t * | data () const |
uint8_t * | writableData () |
const uint8_t * | tail () const |
uint8_t * | writableTail () |
std::size_t | length () const |
std::size_t | headroom () const |
std::size_t | tailroom () const |
const uint8_t * | buffer () const |
uint8_t * | writableBuffer () |
const uint8_t * | bufferEnd () const |
std::size_t | capacity () const |
IOBuf * | next () |
const IOBuf * | next () const |
IOBuf * | prev () |
const IOBuf * | prev () const |
void | advance (std::size_t amount) |
void | retreat (std::size_t amount) |
void | prepend (std::size_t amount) |
void | append (std::size_t amount) |
void | trimStart (std::size_t amount) |
void | trimEnd (std::size_t amount) |
void | clear () |
void | reserve (std::size_t minHeadroom, std::size_t minTailroom) |
bool | isChained () const |
size_t | countChainElements () const |
std::size_t | computeChainDataLength () const |
void | prependChain (std::unique_ptr< IOBuf > &&iobuf) |
void | appendChain (std::unique_ptr< IOBuf > &&iobuf) |
std::unique_ptr< IOBuf > | unlink () |
std::unique_ptr< IOBuf > | pop () |
std::unique_ptr< IOBuf > | separateChain (IOBuf *head, IOBuf *tail) |
bool | isShared () const |
bool | isManaged () const |
bool | isManagedOne () const |
bool | isSharedOne () const |
void | unshare () |
void | unshareOne () |
void | markExternallyShared () |
void | markExternallySharedOne () |
void | makeManaged () |
void | makeManagedOne () |
ByteRange | coalesce () |
ByteRange | coalesceWithHeadroomTailroom (std::size_t newHeadroom, std::size_t newTailroom) |
void | gather (std::size_t maxLength) |
std::unique_ptr< IOBuf > | clone () const |
IOBuf | cloneAsValue () const |
std::unique_ptr< IOBuf > | cloneOne () const |
IOBuf | cloneOneAsValue () const |
std::unique_ptr< IOBuf > | cloneCoalesced () const |
std::unique_ptr< IOBuf > | cloneCoalescedWithHeadroomTailroom (std::size_t newHeadroom, std::size_t newTailroom) const |
IOBuf | cloneCoalescedAsValue () const |
IOBuf | cloneCoalescedAsValueWithHeadroomTailroom (std::size_t newHeadroom, std::size_t newTailroom) const |
void | cloneInto (IOBuf &other) const |
void | cloneOneInto (IOBuf &other) const |
folly::fbvector< struct iovec > | getIov () const |
void | appendToIov (folly::fbvector< struct iovec > *iov) const |
size_t | fillIov (struct iovec *iov, size_t len) const |
void * | operator new (size_t size) |
void * | operator new (size_t size, void *ptr) |
void | operator delete (void *ptr) |
void | operator delete (void *ptr, void *placement) |
fbstring | moveToFbString () |
Iterator | cbegin () const |
Iterator | cend () const |
Iterator | begin () const |
Iterator | end () const |
IOBuf () noexcept | |
IOBuf (IOBuf &&other) noexcept | |
IOBuf & | operator= (IOBuf &&other) noexcept |
IOBuf (const IOBuf &other) | |
IOBuf & | operator= (const IOBuf &other) |
Static Public Member Functions | |
static std::unique_ptr< IOBuf > | create (std::size_t capacity) |
static std::unique_ptr< IOBuf > | createCombined (std::size_t capacity) |
static std::unique_ptr< IOBuf > | createSeparate (std::size_t capacity) |
static std::unique_ptr< IOBuf > | createChain (size_t totalCapacity, std::size_t maxBufCapacity) |
static std::unique_ptr< IOBuf > | takeOwnership (void *buf, std::size_t capacity, FreeFunction freeFn=nullptr, void *userData=nullptr, bool freeOnError=true) |
static std::unique_ptr< IOBuf > | takeOwnership (void *buf, std::size_t capacity, std::size_t length, FreeFunction freeFn=nullptr, void *userData=nullptr, bool freeOnError=true) |
template<class UniquePtr > | |
static std::enable_if< detail::IsUniquePtrToSL< UniquePtr >::value, std::unique_ptr< IOBuf > >::type | takeOwnership (UniquePtr &&buf, size_t count=1) |
static std::unique_ptr< IOBuf > | wrapBuffer (const void *buf, std::size_t capacity) |
static std::unique_ptr< IOBuf > | wrapBuffer (ByteRange br) |
static IOBuf | wrapBufferAsValue (const void *buf, std::size_t capacity) noexcept |
static IOBuf | wrapBufferAsValue (ByteRange br) noexcept |
static std::unique_ptr< IOBuf > | copyBuffer (const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0) |
static std::unique_ptr< IOBuf > | copyBuffer (ByteRange br, std::size_t headroom=0, std::size_t minTailroom=0) |
static std::unique_ptr< IOBuf > | copyBuffer (const std::string &buf, std::size_t headroom=0, std::size_t minTailroom=0) |
static std::unique_ptr< IOBuf > | maybeCopyBuffer (const std::string &buf, std::size_t headroom=0, std::size_t minTailroom=0) |
static void | destroy (std::unique_ptr< IOBuf > &&data) |
static std::unique_ptr< IOBuf > | wrapIov (const iovec *vec, size_t count) |
static std::unique_ptr< IOBuf > | takeOwnershipIov (const iovec *vec, size_t count, FreeFunction freeFn=nullptr, void *userData=nullptr, bool freeOnError=true) |
Private Types | |
enum | FlagsEnum : uintptr_t { kFlagFreeSharedInfo = 0x1, kFlagMaybeShared = 0x2, kFlagMask = kFlagFreeSharedInfo | kFlagMaybeShared } |
Private Member Functions | |
IOBuf (InternalConstructor, uintptr_t flagsAndSharedInfo, uint8_t *buf, std::size_t capacity, uint8_t *data, std::size_t length) noexcept | |
void | unshareOneSlow () |
void | unshareChained () |
void | makeManagedChained () |
void | coalesceSlow () |
void | coalesceSlow (size_t maxLength) |
void | coalesceAndReallocate (size_t newHeadroom, size_t newLength, IOBuf *end, size_t newTailroom) |
void | coalesceAndReallocate (size_t newLength, IOBuf *end) |
void | decrementRefcount () |
void | reserveSlow (std::size_t minHeadroom, std::size_t minTailroom) |
void | freeExtBuffer () |
SharedInfo * | sharedInfo () const |
void | setSharedInfo (SharedInfo *info) |
uintptr_t | flags () const |
void | setFlags (uintptr_t flags) const |
void | clearFlags (uintptr_t flags) const |
void | setFlagsAndSharedInfo (uintptr_t flags, SharedInfo *info) |
Static Private Member Functions | |
static size_t | goodExtBufferSize (std::size_t minCapacity) |
static void | initExtBuffer (uint8_t *buf, size_t mallocSize, SharedInfo **infoReturn, std::size_t *capacityReturn) |
static void | allocExtBuffer (std::size_t minCapacity, uint8_t **bufReturn, SharedInfo **infoReturn, std::size_t *capacityReturn) |
static void | releaseStorage (HeapStorage *storage, uint16_t freeFlags) |
static void | freeInternalBuf (void *buf, void *userData) |
static uintptr_t | packFlagsAndSharedInfo (uintptr_t flags, SharedInfo *info) |
static void | freeUniquePtrBuffer (void *ptr, void *userData) |
Private Attributes | |
IOBuf * | next_ {this} |
IOBuf * | prev_ {this} |
uint8_t * | data_ {nullptr} |
uint8_t * | buf_ {nullptr} |
std::size_t | length_ {0} |
std::size_t | capacity_ {0} |
uintptr_t | flagsAndSharedInfo_ {0} |
typedef Iterator folly::IOBuf::const_iterator |
typedef void(* folly::IOBuf::FreeFunction) (void *buf, void *userData) |
typedef Iterator folly::IOBuf::iterator |
typedef ByteRange folly::IOBuf::value_type |
|
private |
Enumerator | |
---|---|
kFlagFreeSharedInfo | |
kFlagMaybeShared | |
kFlagMask |
folly::IOBuf::IOBuf | ( | CreateOp | , |
std::size_t | capacity | ||
) |
Definition at line 195 of file IOBuf.cpp.
References allocExtBuffer(), buf_, capacity_, data_, deadlock::info(), and setSharedInfo().
|
inline |
folly::IOBuf::IOBuf | ( | TakeOwnershipOp | , |
void * | buf, | ||
std::size_t | capacity, | ||
std::size_t | length, | ||
FreeFunction | freeFn = nullptr , |
||
void * | userData = nullptr , |
||
bool | freeOnError = true |
||
) |
Definition at line 289 of file IOBuf.cpp.
References setSharedInfo().
|
noexcept |
|
noexcept |
folly::IOBuf::IOBuf | ( | CopyBufferOp | op, |
const void * | buf, | ||
std::size_t | size, | ||
std::size_t | headroom = 0 , |
||
std::size_t | minTailroom = 0 |
||
) |
Definition at line 207 of file IOBuf.cpp.
References advance(), append(), and writableData().
folly::IOBuf::IOBuf | ( | CopyBufferOp | op, |
ByteRange | br, | ||
std::size_t | headroom = 0 , |
||
std::size_t | minTailroom = 0 |
||
) |
|
inline |
folly::IOBuf::~IOBuf | ( | ) |
Destroy this IOBuf.
Deleting an IOBuf will automatically destroy all IOBufs in the chain. (See the comments above regarding the ownership model of IOBuf chains. All subsequent IOBufs in the chain are considered to be owned by the head of the chain. Users should only explicitly delete the head of a chain.)
When each individual IOBuf is destroyed, it will release its reference count on the underlying buffer. If it was the last user of the buffer, the buffer will be freed.
Definition at line 415 of file IOBuf.cpp.
References decrementRefcount(), next_, and unlink().
|
noexcept |
Allocate a new null buffer.
This can be used to allocate an empty IOBuf on the stack. It will have no space allocated for it. This is generally useful only to later use move assignment to fill out the IOBuf.
Definition at line 361 of file IOBuf.cpp.
Referenced by cloneOneAsValue(), operator=(), and wrapBufferAsValue().
|
noexcept |
Move constructor and assignment operator.
In general, you should only ever move the head of an IOBuf chain. Internal nodes in an IOBuf chain are owned by the head of the chain, and should not be moved from. (Technically, nothing prevents you from moving a non-head node, but the moved-to node will replace the moved-from node in the chain. This has implications for ownership, since non-head nodes are owned by the chain head. You are then responsible for relinquishing ownership of the moved-to node, and manually deleting the moved-from node.)
With the move assignment operator, the destination of the move should be the head of an IOBuf chain or a solitary IOBuf not part of a chain. If the move destination is part of a chain, all other IOBufs in the chain will be deleted.
Definition at line 363 of file IOBuf.cpp.
folly::IOBuf::IOBuf | ( | const IOBuf & | other | ) |
Definition at line 393 of file IOBuf.cpp.
References cloneAsValue().
|
privatenoexcept |
|
inline |
Shift the data forwards in the buffer.
This shifts the data pointer forwards in the buffer to increase the headroom. This is commonly used to increase the headroom in a newly allocated buffer.
The caller is responsible for ensuring that there is sufficient tailroom in the buffer before calling advance().
If there is a non-zero data length, advance() will use memmove() to shift the data forwards in the buffer. In this case, the caller is responsible for making sure the buffer is unshared, so it will not affect other IOBufs that may be sharing the same underlying buffer.
Definition at line 632 of file IOBuf.h.
References data_, and length_.
Referenced by folly::TypedIOBuf< T >::advance(), proxygen::GzipHeaderCodec::encode(), fizz::detail::evpEncrypt(), IOBuf(), and TEST().
|
staticprivate |
Definition at line 927 of file IOBuf.cpp.
References folly::checkedMalloc(), goodExtBufferSize(), initExtBuffer(), and uint8_t.
Referenced by coalesceAndReallocate(), IOBuf(), and unshareOneSlow().
|
inline |
Adjust the tail pointer to include more valid data at the end.
This moves the tail pointer forwards to include more of the available buffer. The caller is responsible for ensuring that there is sufficient tailroom for the new data. The caller is also responsible for populating this section with valid data.
This does not modify any actual data in the buffer.
Definition at line 689 of file IOBuf.h.
References length_.
Referenced by append(), folly::TypedIOBuf< T >::append(), folly::IOBufQueue::append(), BENCHMARK(), folly::gen::detail::consumeBufferPlus(), folly::io::StreamCodec::doUncompress(), proxygen::GzipHeaderCodec::encode(), fizz::detail::evpDecrypt(), fizz::detail::evpEncrypt(), folly::AsyncPipeReader::handlerReady(), IOBuf(), main(), MoveToFbStringTest::makeBuf(), poolGetIOBuf(), proxygen::readFileToIOBuf(), CurlService::CurlClient::sendRequest(), TEST(), and TEST_F().
|
inline |
Append another IOBuf chain immediately after this IOBuf.
For example, if there are two IOBuf chains (A, B, C) and (D, E, F), and B->appendChain(D) is called, the (D, E, F) chain will be subsumed and become part of the chain starting at A, which will now look like (A, B, D, E, F, C)
The elements in the specified IOBuf chain will become part of this chain, and will be owned by the head of this chain. When this chain is destroyed, all elements in the supplied chain will also be destroyed.
For this reason, appendChain() only accepts an rvalue-reference to a unique_ptr(), to make it clear that it is taking ownership of the supplied chain. If you have a raw pointer, you can pass in a new temporary unique_ptr around the raw pointer. If you have an existing, non-temporary unique_ptr, you must call std::move(ptr) to make it clear that you are destroying the original pointer.
Definition at line 827 of file IOBuf.h.
References folly::gen::move.
Referenced by TEST(), TEST_F(), and TEST_P().
void folly::IOBuf::appendToIov | ( | folly::fbvector< struct iovec > * | iov | ) | const |
Update an existing iovec array with the IOBuf data.
New iovecs will be appended to the existing vector; anything already present in the vector will be left unchanged.
Naturally, the returned iovec data will be invalid if you modify the buffer chain.
Definition at line 1016 of file IOBuf.cpp.
References data(), length(), next(), and folly::fbvector< T, Allocator >::push_back().
Referenced by getIov().
|
inline |
Definition at line 1684 of file IOBuf.h.
References folly::padded::cbegin().
Referenced by folly::io::StreamCodec::doUncompress().
|
inline |
Get the pointer to the start of the buffer.
Note that this is the pointer to the very beginning of the usable buffer, not the start of valid data within the buffer. Use the data() method to get a pointer to the start of the data within the buffer.
Definition at line 562 of file IOBuf.h.
Referenced by folly::TypedIOBuf< T >::buffer(), and TEST().
|
inline |
Get the pointer to the end of the buffer.
Note that this is the pointer to the very end of the usable buffer, not the end of valid data within the buffer. Use the tail() method to get a pointer to the end of the data within the buffer.
Definition at line 583 of file IOBuf.h.
Referenced by folly::TypedIOBuf< T >::bufferEnd().
|
inline |
Get the total size of the buffer.
This returns the total usable length of the buffer. Use the length() method to get the length of the actual valid data in this IOBuf.
Definition at line 593 of file IOBuf.h.
Referenced by BENCHMARK(), folly::TypedIOBuf< T >::capacity(), createCombined(), createSeparate(), folly::AsyncPipeReader::handlerReady(), IOBuf(), moveToFbString(), reserveSlow(), takeOwnership(), TEST(), testAllocSize(), wrapBuffer(), and wrapBufferAsValue().
IOBuf::Iterator folly::IOBuf::cbegin | ( | ) | const |
IOBuf::Iterator folly::IOBuf::cend | ( | ) | const |
|
inline |
Clear the buffer.
Postcondition: headroom() == 0, length() == 0, tailroom() == capacity()
Definition at line 728 of file IOBuf.h.
References data_, and length_.
Referenced by folly::TypedIOBuf< T >::clear(), folly::IOBufQueue::clear(), folly::gen::detail::consumeBufferPlus(), moveToFbString(), and TEST().
|
inlineprivate |
Definition at line 1469 of file IOBuf.h.
unique_ptr< IOBuf > folly::IOBuf::clone | ( | ) | const |
Return a new IOBuf chain sharing the same data as this chain.
The new IOBuf chain will normally point to the same underlying data buffers as the original chain. (The one exception to this is if some of the IOBufs in this chain contain small internal data buffers which cannot be shared.)
Definition at line 527 of file IOBuf.cpp.
References cloneAsValue().
Referenced by BENCHMARK(), HTTP2FramerTest::dataFrameTest(), fizz::server::DualTicketCipher::decrypt(), folly::io::StreamCodec::doUncompress(), ZlibServerFilterTest::exercise_compression(), fizz::HkdfImpl< Hash >::expand(), proxygen::SPDYCodec::failSession(), proxygen::SPDYCodec::failStream(), folly::io::QueueAppender::insert(), UDPAcceptor::onDataAvailable(), proxygen::HTTP1xCodec::onIngress(), proxygen::IOBufPrinter::printChain(), TEST(), and proxygen::SecondaryAuthManager::validateAuthenticator().
IOBuf folly::IOBuf::cloneAsValue | ( | ) | const |
Similar to clone(). But returns IOBuf by value rather than heap-allocating it.
Definition at line 546 of file IOBuf.cpp.
References cloneOneAsValue(), current, and next_.
Referenced by BENCHMARK(), clone(), and IOBuf().
unique_ptr< IOBuf > folly::IOBuf::cloneCoalesced | ( | ) | const |
Return a new unchained IOBuf that may share the same data as this chain.
If the IOBuf chain is not chained then the new IOBuf will point to the same underlying data buffer as the original chain. Otherwise, it will clone and coalesce the IOBuf chain.
The new IOBuf will have at least as much headroom as the first IOBuf in the chain, and at least as much tailroom as the last IOBuf in the chain.
Throws std::bad_alloc on error.
Definition at line 535 of file IOBuf.cpp.
References cloneCoalescedAsValue().
IOBuf folly::IOBuf::cloneCoalescedAsValue | ( | ) | const |
Similar to cloneCoalesced(). But returns IOBuf by value rather than heap-allocating it.
Definition at line 570 of file IOBuf.cpp.
References cloneCoalescedAsValueWithHeadroomTailroom(), headroom(), prev(), and tailroom().
Referenced by BENCHMARK_RELATIVE(), cloneCoalesced(), folly::io::StreamCodec::doUncompress(), and folly::io::test::TEST_P().
IOBuf folly::IOBuf::cloneCoalescedAsValueWithHeadroomTailroom | ( | std::size_t | newHeadroom, |
std::size_t | newTailroom | ||
) | const |
This is similar to the cloneCoalescedAsValue() method, except this allows to set a headroom and tailroom for the new IOBuf.
Definition at line 576 of file IOBuf.cpp.
References cloneOneAsValue(), computeChainDataLength(), CREATE, current, and isChained().
Referenced by cloneCoalescedAsValue(), and cloneCoalescedWithHeadroomTailroom().
unique_ptr< IOBuf > folly::IOBuf::cloneCoalescedWithHeadroomTailroom | ( | std::size_t | newHeadroom, |
std::size_t | newTailroom | ||
) | const |
This is similar to the cloneCoalesced() method, except this allows to set a headroom and tailroom for the new IOBuf.
Definition at line 539 of file IOBuf.cpp.
References cloneCoalescedAsValueWithHeadroomTailroom().
|
inline |
Similar to Clone(). But use other as the head node. Other nodes in the chain (if any) will be allocted on heap.
Definition at line 1213 of file IOBuf.h.
Referenced by BENCHMARK().
unique_ptr< IOBuf > folly::IOBuf::cloneOne | ( | ) | const |
Return a new IOBuf with the same data as this IOBuf.
The new IOBuf returned will not be part of a chain (even if this IOBuf is part of a larger chain).
Definition at line 531 of file IOBuf.cpp.
References cloneOneAsValue().
Referenced by BENCHMARK(), ZlibServerFilterTest::exercise_compression(), proxygen::HTTP1xCodec::onBody(), proxygen::HTTP1xCodec::onParserError(), and TEST().
IOBuf folly::IOBuf::cloneOneAsValue | ( | ) | const |
Similar to cloneOne(). But returns IOBuf by value rather than heap-allocating it.
Definition at line 556 of file IOBuf.cpp.
References buf_, capacity_, data_, flagsAndSharedInfo_, deadlock::info(), IOBuf(), kFlagMaybeShared, length_, setFlags(), and sharedInfo().
Referenced by cloneAsValue(), cloneCoalescedAsValueWithHeadroomTailroom(), and cloneOne().
|
inline |
Similar to CloneOne(). But to fill an existing IOBuf instead of a new IOBuf.
Definition at line 1221 of file IOBuf.h.
References folly::test::begin(), folly::padded::cbegin(), folly::padded::cend(), count, folly::test::end(), folly::pushmi::__adl::noexcept(), ptr, and folly::size().
Referenced by BENCHMARK().
|
inline |
Coalesce this IOBuf chain into a single buffer.
This method moves all of the data in this IOBuf chain into a single contiguous buffer, if it is not already in one buffer. After coalesce() returns, this IOBuf will be a chain of length one. Other IOBufs in the chain will be automatically deleted.
After coalescing, the IOBuf will have at least as much headroom as the first IOBuf in the chain, and at least as much tailroom as the last IOBuf in the chain.
Throws std::bad_alloc on error. On error the IOBuf chain will be unmodified.
Returns ByteRange that points to the data IOBuf stores.
Definition at line 1095 of file IOBuf.h.
Referenced by BENCHMARK(), folly::io::StreamCodec::doUncompress(), fizz::EncryptedReadRecordLayer::getDecryptedBuf(), wangle::SSLSessionCacheManager::onGetSuccess(), proxygen::IOBufPrinter::printChain(), wangle::StringCodec::read(), HTTPUpstreamTest< SPDY3CodecPair >::readAndLoop(), TEST_F(), folly::AsyncUDPSocket::writeGSO(), and ConnectedWriteUDPClient::writePing().
|
private |
Definition at line 722 of file IOBuf.cpp.
References allocExtBuffer(), buf_, capacity_, current, data_, decrementRefcount(), isChained(), length_, next_, prev_, separateChain(), setFlagsAndSharedInfo(), and uint8_t.
Referenced by coalesceSlow(), and moveToFbString().
|
inlineprivate |
Definition at line 1391 of file IOBuf.h.
References prev_, tailroom(), uint16_t, and uint8_t.
|
private |
Definition at line 677 of file IOBuf.cpp.
References coalesceAndReallocate(), end(), isChained(), length_, and next_.
Referenced by unshareChained().
|
private |
Definition at line 695 of file IOBuf.cpp.
References coalesceAndReallocate(), end(), isChained(), length_, and next_.
|
inline |
This is similar to the coalesce() method, except this allows to set a headroom and tailroom after coalescing.
Returns ByteRange that points to the data IOBuf stores.
Definition at line 1107 of file IOBuf.h.
References data_, and length_.
std::size_t folly::IOBuf::computeChainDataLength | ( | ) | const |
Get the length of all the data in this IOBuf chain.
Beware that this method has to walk the entire chain.
Definition at line 501 of file IOBuf.cpp.
References current, length_, and next_.
Referenced by MoveToFbStringTest::check(), checkQError(), fizz::test::chunkIOBuf(), cloneCoalescedAsValueWithHeadroomTailroom(), folly::io::Codec::compress(), proxygen::SecondaryAuthManager::createAuthRequest(), proxygen::compress::QMINScheme::decode(), fizz::AsyncFizzBase::deliverAppData(), TestAbortPost< stage >::doAbortTest(), folly::io::StreamCodec::doCompress(), folly::io::StreamCodec::doUncompress(), proxygen::HTTP1xCodec::generateBody(), proxygen::SPDYCodec::generateBody(), proxygen::FlowControlFilter::generateBody(), proxygen::SPDYCodec::generateSynReply(), proxygen::SPDYCodec::generateSynStream(), proxygen::HTTPSession::getCertAuthSettingVal(), folly::io::Codec::getUncompressedLength(), folly::io::RWCursor< access >::insert(), isLowercase(), moveToFbString(), HTTP1xCodecCallback::onBody(), proxygen::FlowControlFilter::onBody(), proxygen::FakeHTTPCodecCallback::onBody(), proxygen::HTTPSession::onBody(), proxygen::HTTPDirectResponseHandler::onHeadersComplete(), proxygen::HTTP1xCodec::onIngress(), proxygen::SPDYCodec::onIngress(), proxygen::HTTPTransaction::onIngressBody(), MockCodecDownstreamTest::onIngressImpl(), proxygen::SPDYCodec::parseIngress(), fizz::test::LocalTransport::receiveData(), proxygen::HPACKCodec::recordCompressedSize(), proxygen::HTTPTransaction::resumeIngress(), proxygen::HTTPSession::runLoopCallback(), proxygen::HTTPTransaction::sendBody(), TEST(), TEST_F(), fizz::test::TEST_F(), folly::io::test::TEST_P(), folly::io::Codec::uncompress(), proxygen::HTTPSession::verifyCertAuthSetting(), wangle::LengthFieldPrepender::write(), proxygen::http2::writeCertificate(), and proxygen::http2::writeCertificateRequest().
|
inlinestatic |
Convenience function to create a new IOBuf object that copies data from a user-supplied buffer, optionally allocating a given amount of headroom and tailroom.
Definition at line 1587 of file IOBuf.h.
References data, and folly::size().
Referenced by fizz::test::TestMessages::addPsk(), fizz::test::TestMessages::appData(), fizz::server::appendClientCertificate(), fizz::test::appWrite(), fizz::test::TestMessages::appWrite(), fizz::test::TestMessages::certificate(), fizz::test::TestMessages::certificateRequest(), fizz::test::TestMessages::certificateVerify(), fizz::test::TestMessages::clientHello(), folly::AsyncSSLSocket::clientHelloParsingCallback(), fizz::test::HandshakeTest::clientWrite(), fizz::client::test::AsyncFizzClientTest::completeEarlyHandshake(), fizz::test::TestMessages::compressedCertificate(), fizz::test::copyBuffer(), ZlibServerFilterTest::createResponseChain(), fizz::detail::decodeAuthRequest(), fizz::test::HandshakeTypesTest::decodeHex(), fizz::test::ZlibCertificateCompressorTest::decodeHex(), fizz::KeyDerivationImpl< Hash >::deriveSecret(), fizz::client::test::ClientProtocolTest::doFinishedFlow(), fizz::test::TestMessages::earlyAppWrite(), ObservingHandlerTest::MockIntToByteEncoder::encode(), fizz::server::TicketCodec< Storage >::encode(), StringToByteEncoder::encode(), proxygen::compress::QMINScheme::encode(), fizz::encodeHkdfLabel(), fizz::test::TestMessages::encryptedExt(), fizz::test::TestMessages::endOfEarlyData(), ZlibServerFilterTest::exercise_compression(), fizz::server::test::AsyncFizzServerTest::expectAppClose(), fizz::client::test::AsyncFizzClientTest::expectAppClose(), fizz::server::test::ServerProtocolTest::expectCookie(), fizz::server::test::AeadTicketCipherTest::expectDecode(), fizz::test::ProtocolTest< ClientTypes, Actions >::expectError(), fizz::test::TestMessages::finished(), fizz::server::test::AsyncFizzServerTest::fullHandshakeSuccess(), fizz::client::test::AsyncFizzClientTest::fullHandshakeSuccess(), fizz::sm::generateTicket(), fizz::test::ExtensionsTest::getBuf(), fizz::test::PlaintextRecordTest::getBuf(), fizz::extensions::test::TokenBindingConstructorTest::getBuf(), fizz::test::EncryptedRecordTest::getBuf(), fizz::test::RecordTest::getBuf(), fizz::extensions::test::ValidatorTest::getBuf(), fizz::sm::getCertificateRequest(), getChunkedRequest1st(), getChunkedRequest2nd(), fizz::sm::getClientHello(), fizz::client::test::ClientProtocolTest::getEarlyDataParams(), fizz::sm::getEarlyDataParams(), fizz::sm::getEncryptedExt(), TestData::getInBuf(), fizz::X25519KeyExchange::getKeyShare(), fizz::sm::getPskExtension(), getSimpleRequestData(), fizz::server::test::getTestResumptionState(), fizz::server::test::getV2ClientHello(), getVersionedSpdyFrame(), GSOBuf::GSOBuf(), fizz::sm::handleCertMsg(), fizz::test::TestMessages::helloRetryRequest(), makeRandom(), fizz::test::MATCHER_P(), MATCHER_P2(), fizz::sm::negotiatePsk(), fizz::test::TestMessages::newSessionTicket(), TestHandlerFactory::TestHandler::onEOM(), proxygen::HTTPSession::onSessionParseError(), proxygen::parse(), HTTPDownstreamTest< SPDY3_1CodecPair >::parseOutput(), proxygen::parseUnidirectional(), wangle::SocketPeeker::readDataAvailable(), fizz::test::HandshakeTest::resetTransportsAndStartCookieHandshake(), folly::io::test::CompressionVarintTest::runSimpleTest(), proxygen::HTTPHandlerBase::sendBody(), proxygen::HTTPHandlerBase::sendChunkedReplyWithBody(), proxygen::ZlibServerFilter::sendEOM(), UDPClient::sendPing(), UDPAcceptor::sendPong(), fizz::test::TestMessages::serverHello(), fizz::test::HandshakeTest::serverWrite(), fizz::MockKeyExchange::setDefaults(), fizz::test::MockKeyScheduler::setDefaults(), fizz::test::MockAead::setDefaults(), fizz::MockPlaintextWriteRecordLayer::setDefaults(), fizz::test::MockHandshakeContext::setDefaults(), fizz::server::test::MockTicketCipher::setDefaults(), fizz::test::AuthenticatorTest::SetUp(), fizz::client::test::ClientProtocolTest::setupAcceptingData(), fizz::server::test::ServerProtocolTest::setUpExpectingCertificate(), fizz::server::test::ServerProtocolTest::setUpExpectingCertificateVerify(), fizz::server::test::ServerProtocolTest::setUpExpectingFinished(), fizz::client::test::ClientProtocolTest::setupExpectingFinished(), fizz::client::test::ClientProtocolTest::setupExpectingServerHello(), fizz::setWriteDefaults(), folly::io::test::CompressionTest::split(), fizz::test::TEST(), fizz::server::test::TEST(), folly::test::TEST(), folly::TEST(), TEST(), fizz::server::test::TEST_F(), fizz::test::TEST_F(), fizz::client::test::TEST_F(), TEST_F(), fizz::testing::TEST_P(), fizz::test::TEST_P(), TEST_P(), folly::io::test::TEST_P(), fizz::test::toIOBuf(), toIOBuf(), ThreadPrintingHandler::transportActive(), fizz::test::TYPED_TEST(), ClientSerializeHandler::write(), ServerSerializeHandler::write(), wangle::StringCodec::write(), fizz::EncryptedWriteRecordLayer::write(), and fizz::test::writeNewSessionTicket().
|
inlinestatic |
Definition at line 415 of file IOBuf.h.
References fizz::test::copyBuffer(), folly::Range< Iter >::data(), folly::Range< Iter >::size(), and string.
|
inlinestatic |
Convenience function to create a new IOBuf object that copies data from a user-supplied string, optionally allocating a given amount of headroom and tailroom.
Beware when attempting to invoke this function with a constant string literal and a headroom argument: you will likely end up invoking the version of copyBuffer() above. IOBuf::copyBuffer("hello", 3) will treat the first argument as a const void*, and will invoke the version of copyBuffer() above, with the size argument of 3.
Definition at line 1602 of file IOBuf.h.
References fizz::test::copyBuffer().
size_t folly::IOBuf::countChainElements | ( | ) | const |
Get the number of IOBufs in this chain.
Beware that this method has to walk the entire chain. Use isChained() if you just want to check if this IOBuf is part of a chain or not.
Definition at line 493 of file IOBuf.cpp.
References current, and next_.
Referenced by MoveToFbStringTest::check(), fizz::test::chunkIOBuf(), ZlibServerFilterTest::exercise_compression(), getIov(), TEST(), TEST_F(), and fizz::trimBytes().
|
static |
Allocate a new IOBuf object with the requested capacity.
Returns a new IOBuf object that must be (eventually) deleted by the caller. The returned IOBuf may actually have slightly more capacity than requested.
The data pointer will initially point to the start of the newly allocated buffer, and will have a data length of 0.
Throws std::bad_alloc on error.
Definition at line 229 of file IOBuf.cpp.
References createCombined(), and createSeparate().
Referenced by folly::io::addOutputBuffer(), folly::IOBufQueue::append(), fizz::server::appendClientCertificate(), BENCHMARK(), fizz::test::ExtensionsTest::checkEncode(), AcceptRoutingHandlerTest::clientConnectAndWrite(), fizz::test::TestMessages::clientHello(), fizz::KeyScheduler::clientKeyUpdate(), folly::io::test::compressSome(), fizz::detail::computeFinishedTranscript(), fizz::detail::computeTranscript(), fizz::detail::computeTranscriptHash(), fizz::extensions::Validator::constructECDSASig(), fizz::extensions::Validator::constructEcKeyFromBuf(), fizz::extensions::TokenBindingUtils::constructMessage(), fizz::JavaCryptoCertificateVerifier::createAuthorities(), fizz::DefaultCertificateVerifier::createAuthorities(), fizz::test::createBuf(), createChain(), fizz::extensions::TokenBindingConstructor::createTokenBinding(), fizz::ZlibCertificateDecompressor::decompress(), proxygen::ZstdStreamDecompressor::decompress(), fizz::test::defaultCreator(), folly::ssl::OpenSSLCertUtils::derEncode(), folly::io::StreamCodec::doUncompress(), fizz::detail::ecSign(), fizz::server::TicketCodec< Storage >::encode(), fizz::encode(), fizz::encode< Alert >(), fizz::encode< CertificateRequest >(), fizz::encode< CertificateVerify >(), fizz::encode< CompressedCertificate & >(), fizz::encode< const CertificateMsg & >(), fizz::encode< const ClientHello & >(), fizz::encode< EncryptedExtensions >(), fizz::encode< EndOfEarlyData >(), fizz::encode< HelloRetryRequest >(), fizz::encode< KeyUpdate >(), fizz::encode< NewSessionTicket >(), fizz::encode< ServerHello >(), fizz::server::detail::encodeCookie(), fizz::extensions::TokenBindingConstructor::encodeEcdsaSignature(), fizz::detail::encodeECPublicKey(), fizz::encodeExtension(), fizz::encodeHandshake(), fizz::encodeHkdfLabel(), fizz::server::AeadTokenCipher< AeadType, HkdfType >::encrypt(), folly::io::Appender::ensure(), fizz::detail::evpDecrypt(), fizz::detail::evpEncrypt(), fizz::HkdfImpl< Hash >::expand(), fizz::server::test::ServerProtocolTest::expectCookie(), folly::gen::fromFile(), fizz::detail::generateEvpSharedSecret(), fizz::X25519KeyExchange::generateSharedSecret(), fizz::sm::generateTicket(), fizz::CertUtils::getCertMessage(), fizz::sm::getEarlyDataParams(), fizz::Exporter::getEkm(), fizz::HandshakeContextImpl< Hash >::getFinishedData(), fizz::detail::getFinishedData(), fizz::HandshakeContextImpl< Hash >::getHandshakeContext(), fizz::sm::getPskExtension(), fizz::server::getStatelessHelloRetryRequest(), fizz::KeyScheduler::getTrafficKey(), folly::AsyncPipeReader::handlerReady(), main(), makeBuf(), proxygen::makeBuf(), fizz::test::TestMessages::newSessionTicket(), poolGetIOBuf(), folly::IOBufQueue::preallocateSlow(), fizz::CertUtils::prepareSignData(), folly::recordio_helpers::prependHeader(), fizz::EncryptedReadRecordLayer::read(), fizz::detail::rsaPssSign(), fizz::test::TestMessages::serverHello(), fizz::KeyScheduler::serverKeyUpdate(), fizz::test::KeySchedulerTest::SetUp(), fizz::client::test::ClientProtocolTest::setupExpectingServerHello(), fizz::extensions::test::ValidatorTest::setUpWithKeyParameters(), folly::IOBufQueue::split(), takeOwnershipIov(), fizz::test::TEST(), folly::io::test::TEST(), TEST(), fizz::test::TEST_F(), TEST_F(), fizz::client::test::TEST_F(), fizz::server::test::TEST_F(), fizz::test::TEST_P(), TEST_P(), folly::io::test::TEST_P(), folly::bser::toBserIOBuf(), folly::gen::toFile(), folly::io::Appender::tryGrowChain(), folly::io::Codec::uncompress(), folly::io::test::uncompressSome(), fizz::ExportedAuthenticator::validate(), wrapIov(), wangle::LengthFieldPrepender::write(), fizz::PlaintextWriteRecordLayer::write(), and fizz::EncryptedWriteRecordLayer::write().
|
static |
Allocate a new IOBuf chain with the requested total capacity, allocating no more than maxBufCapacity to each buffer.
Definition at line 272 of file IOBuf.cpp.
References create(), min, and folly::gen::move.
|
static |
Create a new IOBuf, using a single memory allocation to allocate space for both the IOBuf object and the data storage space.
This saves one memory allocation. However, it can be wasteful if you later need to grow the buffer using reserve(). If the buffer needs to be reallocated, the space originally allocated will not be freed() until the IOBuf object itself is also freed. (It can also be slightly wasteful in some cases where you clone this IOBuf and then free the original IOBuf.)
Definition at line 245 of file IOBuf.cpp.
References capacity(), folly::checkedMalloc(), freeInternalBuf(), folly::goodMallocSize(), packFlagsAndSharedInfo(), and uint8_t.
Referenced by create().
|
static |
Create a new IOBuf, using separate memory allocations for the IOBuf object for the IOBuf and the data storage space.
This requires two memory allocations, but saves space in the long run if you know that you will need to reallocate the data buffer later.
Definition at line 268 of file IOBuf.cpp.
References capacity(), and CREATE.
Referenced by create().
|
inline |
Get the pointer to the start of the data.
Definition at line 499 of file IOBuf.h.
References data_.
Referenced by TestAsyncTransport::addReadEvent(), appendToIov(), checkBuf(), checkChain(), folly::gen::detail::consumeBufferPlus(), folly::TypedIOBuf< T >::data(), proxygen::HPACKDecodeBuffer::decodeLiteral(), folly::io::StreamCodec::doCompress(), folly::io::StreamCodec::doUncompress(), proxygen::dumpBinToFile(), proxygen::hpack::dumpToFile(), fillIov(), proxygen::SPDYCodec::generateGoaway(), fizz::EncryptedReadRecordLayer::getDecryptedBuf(), IOBuf(), CurlService::CurlClient::onBody(), proxygen::HTTP1xCodec::onBody(), wangle::SSLSessionCacheManager::onGetSuccess(), proxygen::HTTPCodecPrinter::onGoaway(), proxygen::HTTPSession::onGoaway(), proxygen::HTTP1xCodec::onIngress(), folly::io::detail::CursorBase< Cursor, const IOBuf >::operator==(), proxygen::HTTP2Codec::parseGoaway(), proxygen::Hex16Printer::print(), proxygen::HexFollyPrinter::print(), proxygen::BinPrinter::print(), wangle::StringCodec::read(), HTTPUpstreamTest< SPDY3CodecPair >::readAndLoop(), proxygen::RFC1867Codec::readToBoundary(), takeOwnershipIov(), TEST(), TEST_F(), fizz::trimBytes(), wrapIov(), TestAsyncTransport::writeChain(), folly::AsyncUDPSocket::writeGSO(), and ConnectedWriteUDPClient::writePing().
|
private |
Definition at line 773 of file IOBuf.cpp.
References flags(), freeExtBuffer(), deadlock::info(), kFlagFreeSharedInfo, folly::IOBuf::SharedInfo::refcount, sharedInfo(), and uint32_t.
Referenced by coalesceAndReallocate(), operator=(), unshareOneSlow(), and ~IOBuf().
|
inlinestatic |
Convenience function to free a chain of IOBufs held by a unique_ptr.
Definition at line 467 of file IOBuf.h.
References data, folly::empty(), and folly::gen::move.
bool folly::IOBuf::empty | ( | ) | const |
Check whether the chain is empty (i.e., whether the IOBufs in the chain have a total data length of zero).
This method is semantically equivalent to i->computeChainDataLength()==0 but may run faster because it can short-circuit as soon as it encounters a buffer with length()!=0
Definition at line 482 of file IOBuf.cpp.
References current, length(), and next_.
Referenced by folly::TypedIOBuf< T >::empty(), proxygen::HTTP2Codec::parseAllData(), proxygen::HTTP2Codec::parseDataFrameData(), and folly::io::Codec::uncompress().
|
inline |
Definition at line 1687 of file IOBuf.h.
References folly::padded::cend(), and FOLLY_POP_WARNING.
Referenced by coalesceSlow().
size_t folly::IOBuf::fillIov | ( | struct iovec * | iov, |
size_t | len | ||
) | const |
Fill an iovec array with the IOBuf data.
Returns the number of iovec filled. If there are more buffer than iovec, returns 0. This version is suitable to use with stack iovec arrays.
Naturally, the filled iovec data will be invalid if you modify the buffer chain.
Definition at line 1072 of file IOBuf.cpp.
References data(), i, length(), next(), and uint8_t.
Referenced by folly::AsyncUDPSocket::writeGSO(), and ConnectedWriteUDPClient::writePing().
|
inlineprivate |
Definition at line 1459 of file IOBuf.h.
Referenced by decrementRefcount(), moveToFbString(), and reserveSlow().
|
private |
Definition at line 909 of file IOBuf.cpp.
References buf_, bm::free(), folly::IOBuf::SharedInfo::freeFn, deadlock::info(), sharedInfo(), and folly::IOBuf::SharedInfo::userData.
Referenced by decrementRefcount(), and reserveSlow().
|
staticprivate |
Definition at line 190 of file IOBuf.cpp.
References releaseStorage(), and folly::IOBuf::SharedInfo::userData.
Referenced by createCombined().
|
inlinestaticprivate |
|
inline |
Ensure that this chain has at least maxLength bytes available as a contiguous memory range.
This method coalesces whole buffers in the chain into this buffer as necessary until this buffer's length() is at least maxLength.
After coalescing, the IOBuf will have at least as much headroom as the first IOBuf in the chain, and at least as much tailroom as the last IOBuf that was coalesced.
Throws std::bad_alloc or std::overflow_error on error. On error the IOBuf chain will be unmodified. Throws std::overflow_error if maxLength is longer than the total chain length.
Upon return, either enough of the chain was coalesced into a contiguous region, or the entire chain was coalesced. That is, length() >= maxLength || !isChained() is true.
Definition at line 1136 of file IOBuf.h.
References length_.
folly::fbvector< struct iovec > folly::IOBuf::getIov | ( | ) | const |
Return an iovector suitable for e.g. writev()
auto iov = buf->getIov(); auto xfer = writev(fd, iov.data(), iov.size());
Naturally, the returned iovector is invalid if you modify the buffer chain.
Definition at line 1009 of file IOBuf.cpp.
References appendToIov(), countChainElements(), and folly::fbvector< T, Allocator >::reserve().
|
staticprivate |
Definition at line 938 of file IOBuf.cpp.
References folly::goodMallocSize().
Referenced by allocExtBuffer(), and reserveSlow().
|
inline |
Get the amount of head room.
Returns the number of bytes in the buffer before the start of the data.
Definition at line 542 of file IOBuf.h.
References buffer(), and data_.
Referenced by cloneCoalescedAsValue(), proxygen::SPDYCodec::generateDataFrame(), folly::TypedIOBuf< T >::headroom(), moveToFbString(), prepend(), reserveSlow(), TEST(), TEST_F(), and unshareOneSlow().
|
staticprivate |
Definition at line 954 of file IOBuf.cpp.
References sharedInfo(), and uint8_t.
Referenced by allocExtBuffer(), and reserveSlow().
|
inline |
Return true if this IOBuf is part of a chain of multiple IOBufs, or false if this is the only IOBuf in its chain.
Definition at line 760 of file IOBuf.h.
Referenced by MoveToFbStringTest::check(), cloneCoalescedAsValueWithHeadroomTailroom(), coalesceAndReallocate(), coalesceSlow(), folly::io::StreamCodec::doUncompress(), ZlibServerFilterTest::exercise_compression(), makeManagedChained(), moveToFbString(), TEST(), fizz::test::TEST_F(), TEST_F(), and unshareChained().
|
inline |
|
inline |
Return true if this IOBuf is managed by the usual refcounting mechanism (and so the lifetime of the underlying memory can be extended by cloneOne()).
Definition at line 938 of file IOBuf.h.
Referenced by isManaged().
|
inline |
Return true if at least one of the IOBufs in this chain are shared, or false if all of the IOBufs point to unique buffers.
Use isSharedOne() to only check this IOBuf rather than the entire chain.
Definition at line 902 of file IOBuf.h.
References current, isSharedOne(), and next_.
Referenced by moveToFbString(), and TEST().
|
inline |
Return true if other IOBufs are also pointing to the buffer used by this IOBuf, and false otherwise.
If this IOBuf points at a buffer owned by another (non-IOBuf) part of the code (i.e., if the IOBuf was created using wrapBuffer(), or was cloned from such an IOBuf), it is always considered shared.
This only checks the current IOBuf, and not other IOBufs in the chain.
Definition at line 952 of file IOBuf.h.
References LIKELY, and UNLIKELY.
Referenced by proxygen::SPDYCodec::generateDataFrame(), isShared(), reserveSlow(), TEST(), unshareChained(), and folly::IOBufQueue::updateWritableTailCache().
|
inline |
Get the data length.
Definition at line 533 of file IOBuf.h.
References length_.
Referenced by TestAsyncTransport::addReadEvent(), appendToIov(), folly::io::detail::CursorBase< Cursor, const IOBuf >::canAdvance(), MoveToFbStringTest::check(), checkBuf(), checkChain(), folly::io::detail::CursorBase< Cursor, const IOBuf >::cloneAtMost(), folly::gen::detail::consumeBufferPlus(), folly::io::StreamCodec::doCompress(), folly::io::StreamCodec::doUncompress(), proxygen::dumpBinToFile(), proxygen::hpack::dumpToFile(), empty(), proxygen::GzipHeaderCodec::encode(), fillBuf(), fillIov(), proxygen::SPDYCodec::generateDataFrame(), fizz::EncryptedWriteRecordLayer::getBufToEncrypt(), fizz::EncryptedReadRecordLayer::getDecryptedBuf(), IOBuf(), folly::io::detail::CursorBase< Cursor, const IOBuf >::isAtEnd(), folly::TypedIOBuf< T >::length(), moveToFbString(), proxygen::HTTPCodecPrinter::onBody(), CurlService::CurlClient::onBody(), proxygen::HTTP1xCodec::onBody(), wangle::SSLSessionCacheManager::onGetSuccess(), proxygen::HTTPCodecPrinter::onGoaway(), proxygen::HTTP1xCodec::onIngress(), proxygen::HTTP2Codec::parseGoaway(), proxygen::Hex16Printer::print(), proxygen::HexFollyPrinter::print(), proxygen::ChainInfoPrinter::print(), proxygen::BinPrinter::print(), proxygen::HTTPSession::processReadData(), wangle::StringCodec::read(), HTTPUpstreamTest< SPDY3CodecPair >::readAndLoop(), proxygen::RFC1867Codec::readToBoundary(), takeOwnership(), TEST(), TEST_F(), fizz::transformBuffer(), fizz::trimBytes(), TestAsyncTransport::writeChain(), folly::AsyncUDPSocket::writeGSO(), and ConnectedWriteUDPClient::writePing().
|
inline |
Ensure that the memory that IOBufs in this chain refer to will continue to be allocated for as long as the IOBufs of the chain (or any clone()s created from this point onwards) is alive.
This only has an effect for user-owned buffers (created with the WRAP_BUFFER constructor or wrapBuffer factory function), in which case those buffers are unshared.
Definition at line 1054 of file IOBuf.h.
|
private |
Definition at line 664 of file IOBuf.cpp.
References current, isChained(), makeManagedOne(), and next_.
|
inline |
Ensure that the memory that this IOBuf refers to will continue to be allocated for as long as this IOBuf (or any clone()s created from this point onwards) is alive.
This only has an effect for user-owned buffers (created with the WRAP_BUFFER constructor or wrapBuffer factory function), in which case those buffers are unshared.
Definition at line 1071 of file IOBuf.h.
Referenced by makeManagedChained().
void folly::IOBuf::markExternallyShared | ( | ) |
Mark the underlying buffers in this chain as shared with external memory management mechanism. This will make isShared() always returns true.
This function is not thread-safe, and only safe to call immediately after creating an IOBuf, before it has been shared with other threads.
Definition at line 656 of file IOBuf.cpp.
References current, markExternallySharedOne(), and next_.
|
inline |
Mark the underlying buffer that this IOBuf refers to as shared with external memory management mechanism. This will make isSharedOne() always returns true.
This function is not thread-safe, and only safe to call immediately after creating an IOBuf, before it has been shared with other threads.
Definition at line 1038 of file IOBuf.h.
References folly::IOBuf::SharedInfo::externallyShared, and deadlock::info().
Referenced by markExternallyShared().
|
inlinestatic |
A version of copyBuffer() that returns a null pointer if the input string is empty.
Definition at line 1609 of file IOBuf.h.
References fizz::test::copyBuffer().
Referenced by proxygen::ResponseBuilder::body().
fbstring folly::IOBuf::moveToFbString | ( | ) |
Destructively convert this IOBuf to a fbstring efficiently. We rely on fbstring's AcquireMallocatedString constructor to transfer memory.
Definition at line 968 of file IOBuf.cpp.
References buf_, capacity(), clear(), coalesceAndReallocate(), computeChainDataLength(), flags(), flagsAndSharedInfo_, headroom(), isChained(), isShared(), kFlagFreeSharedInfo, length(), sharedInfo(), tailroom(), writableData(), and writableTail().
Referenced by MoveToFbStringTest::check(), HTTP2FramerTest::dataFrameTest(), TEST(), TEST_F(), TEST_P(), and fizz::test::TEST_P().
|
inline |
Get a pointer to the next IOBuf in this chain.
Definition at line 600 of file IOBuf.h.
Referenced by appendToIov(), folly::io::detail::CursorBase< Cursor, const IOBuf >::canAdvance(), checkChain(), folly::IOBufQueue::clear(), proxygen::ZlibStreamDecompressor::decompress(), folly::io::StreamCodec::doCompress(), folly::io::StreamCodec::doUncompress(), proxygen::dumpBinToFile(), proxygen::hpack::dumpToFile(), ZlibServerFilterTest::exercise_compression(), fillIov(), folly::io::detail::CursorBase< Cursor, const IOBuf >::isAtEnd(), CurlService::CurlClient::onBody(), folly::io::detail::CursorBase< Cursor, const IOBuf >::operator==(), TEST(), TEST_F(), fizz::transformBuffer(), and TestAsyncTransport::writeChain().
|
inline |
void folly::IOBuf::operator delete | ( | void * | ptr | ) |
Definition at line 145 of file IOBuf.cpp.
References ptr, releaseStorage(), and uint8_t.
void folly::IOBuf::operator delete | ( | void * | ptr, |
void * | placement | ||
) |
void * folly::IOBuf::operator new | ( | size_t | size | ) |
void * folly::IOBuf::operator new | ( | size_t | size, |
void * | ptr | ||
) |
|
inlinestaticprivate |
Definition at line 1440 of file IOBuf.h.
References deadlock::info().
Referenced by createCombined().
|
inline |
Remove this IOBuf from its current chain and return a unique_ptr to the IOBuf that formerly followed it in the chain.
Definition at line 859 of file IOBuf.h.
References cpp.ast::next().
Referenced by proxygen::SPDYCodec::generateDataFrame(), poolPutIOBuf(), and folly::IOBufQueue::pop_front().
|
inline |
Adjust the data pointer to include more valid data at the beginning.
This moves the data pointer backwards to include more of the available buffer. The caller is responsible for ensuring that there is sufficient headroom for the new data. The caller is also responsible for populating this section with valid data.
This does not modify any actual data in the buffer.
Definition at line 673 of file IOBuf.h.
References data_, and length_.
Referenced by proxygen::SPDYCodec::generateSynReply(), proxygen::SPDYCodec::generateSynStream(), prepend(), and folly::TypedIOBuf< T >::prepend().
void folly::IOBuf::prependChain | ( | std::unique_ptr< IOBuf > && | iobuf | ) |
Insert another IOBuf chain immediately before this IOBuf.
For example, if there are two IOBuf chains (A, B, C) and (D, E, F), and B->prependChain(D) is called, the (D, E, F) chain will be subsumed and become part of the chain starting at A, which will now look like (A, D, E, F, B, C)
Note that since IOBuf chains are circular, head->prependChain(other) can be used to append the other chain at the very end of the chain pointed to by head. For example, if there are two IOBuf chains (A, B, C) and (D, E, F), and A->prependChain(D) is called, the chain starting at A will now consist of (A, B, C, D, E, F)
The elements in the specified IOBuf chain will become part of this chain, and will be owned by the head of this chain. When this chain is destroyed, all elements in the supplied chain will also be destroyed.
For this reason, appendChain() only accepts an rvalue-reference to a unique_ptr(), to make it clear that it is taking ownership of the supplied chain. If you have a raw pointer, you can pass in a new temporary unique_ptr around the raw pointer. If you have an existing, non-temporary unique_ptr, you must call std::move(ptr) to make it clear that you are destroying the original pointer.
Definition at line 509 of file IOBuf.cpp.
Referenced by BENCHMARK(), fizz::test::chunkIOBuf(), folly::io::detail::CursorBase< Cursor, const IOBuf >::cloneAtMost(), fizz::test::copyBuffer(), ZlibServerFilterTest::createResponseChain(), fizz::detail::evpEncrypt(), ZlibServerFilterTest::exercise_compression(), TestData::getInBuf(), folly::io::RWCursor< access >::insert(), main(), proxygen::RFC1867Base::parse(), TEST(), TEST_F(), and fizz::EncryptedWriteRecordLayer::write().
|
inline |
Get a pointer to the previous IOBuf in this chain.
Definition at line 610 of file IOBuf.h.
Referenced by cloneCoalescedAsValue(), proxygen::ZlibStreamCompressor::compress(), folly::IOBufQueue::dcheckCacheIntegrity(), fizz::detail::evpEncrypt(), folly::IOBufQueue::flushCache(), folly::io::detail::CursorBase< Cursor, const IOBuf >::operator==(), TEST(), fizz::trimBytes(), and folly::IOBufQueue::updateWritableTailCache().
|
inline |
|
staticprivate |
Definition at line 157 of file IOBuf.cpp.
References folly::IOBuf::HeapPrefix::flags, bm::free(), folly::IOBuf::HeapPrefix::magic, folly::IOBuf::HeapStorage::prefix, and uint16_t.
Referenced by freeInternalBuf(), and operator delete().
|
inline |
Ensure that this buffer has at least minHeadroom headroom bytes and at least minTailroom tailroom bytes. The buffer must be writable (you must call unshare() before this, if necessary).
Postcondition: headroom() >= minHeadroom, tailroom() >= minTailroom, the data (between data() and data() + length()) is preserved.
Definition at line 741 of file IOBuf.h.
References data_.
Referenced by BENCHMARK(), folly::gen::detail::consumeBufferPlus(), folly::TypedIOBuf< T >::reserve(), and TEST().
|
private |
Definition at line 808 of file IOBuf.cpp.
References buf_, capacity(), capacity_, folly::checkedMalloc(), data_, flags(), freeExtBuffer(), folly::IOBuf::SharedInfo::freeFn, goodExtBufferSize(), headroom(), deadlock::info(), initExtBuffer(), isSharedOne(), folly::jemallocMinInPlaceExpandable, kFlagFreeSharedInfo, length_, setFlagsAndSharedInfo(), sharedInfo(), tailroom(), uint8_t, UNLIKELY, folly::usingJEMalloc(), writableBuffer(), and xallocx.
|
inline |
Shift the data backwards in the buffer.
The caller is responsible for ensuring that there is sufficient headroom in the buffer before calling retreat().
If there is a non-zero data length, retreat() will use memmove() to shift the data backwards in the buffer. In this case, the caller is responsible for making sure the buffer is unshared, so it will not affect other IOBufs that may be sharing the same underlying buffer.
Definition at line 653 of file IOBuf.h.
References data_, and length_.
Referenced by proxygen::SPDYCodec::generateDataFrame(), and folly::TypedIOBuf< T >::retreat().
Remove a subchain from this chain.
Remove the subchain starting at head and ending at tail from this chain.
Returns a unique_ptr pointing to head. (In other words, ownership of the head of the subchain is transferred to the caller.) If the caller ignores the return value and lets the unique_ptr be destroyed, the subchain will be immediately destroyed.
The subchain referenced by the specified head and tail must be part of the same chain as the current IOBuf, but must not contain the current IOBuf. However, the specified head and tail may be equal to each other (i.e., they may be a subchain of length 1).
Definition at line 883 of file IOBuf.h.
Referenced by coalesceAndReallocate().
|
inlineprivate |
|
inlineprivate |
Definition at line 1474 of file IOBuf.h.
Referenced by coalesceAndReallocate(), reserveSlow(), and unshareOneSlow().
|
inlineprivate |
Definition at line 1453 of file IOBuf.h.
References deadlock::info().
Referenced by IOBuf().
|
inlineprivate |
Definition at line 1449 of file IOBuf.h.
Referenced by cloneOneAsValue(), decrementRefcount(), freeExtBuffer(), initExtBuffer(), moveToFbString(), reserveSlow(), and unshareOneSlow().
|
inline |
Get the pointer to the end of the data.
Definition at line 516 of file IOBuf.h.
References data_, and length_.
Referenced by folly::io::detail::CursorBase< Cursor, const IOBuf >::operator==(), folly::TypedIOBuf< T >::tail(), and TEST().
|
inline |
Get the amount of tail room.
Returns the number of bytes in the buffer after the end of the data.
Definition at line 551 of file IOBuf.h.
Referenced by append(), folly::IOBufQueue::append(), cloneCoalescedAsValue(), coalesceAndReallocate(), folly::IOBufQueue::dcheckCacheIntegrity(), folly::io::StreamCodec::doUncompress(), fizz::detail::evpEncrypt(), moveToFbString(), proxygen::ChainInfoPrinter::print(), reserveSlow(), folly::TypedIOBuf< T >::tailroom(), TEST(), and folly::IOBufQueue::updateWritableTailCache().
|
inlinestatic |
Create a new IOBuf pointing to an existing data buffer.
The new IOBuffer will assume ownership of the buffer, and free it by calling the specified FreeFunction when the last IOBuf pointing to this buffer is destroyed. The function will be called with a pointer to the buffer as the first argument, and the supplied userData value as the second argument. The free function must never throw exceptions.
If no FreeFunction is specified, the buffer will be freed using free() which will result in undefined behavior if the memory was allocated using 'new'.
The IOBuf data pointer will initially point to the start of the buffer,
In the first version of this function, the length of data is unspecified and is initialized to the capacity of the buffer
In the second version, the user specifies the valid length of data in the buffer
On error, std::bad_alloc will be thrown. If freeOnError is true (the default) the buffer will be freed before throwing the error.
Definition at line 304 of file IOBuf.h.
Referenced by folly::AsyncSocket::handleRead(), takeOwnershipIov(), and folly::ZeroCopyTestAsyncSocket::writeBuffer().
|
static |
Definition at line 313 of file IOBuf.cpp.
References capacity(), length(), and TAKE_OWNERSHIP.
|
static |
Create a new IOBuf pointing to an existing data buffer made up of count objects of a given standard-layout type.
This is dangerous – it is essentially equivalent to doing reinterpret_cast<unsigned char*> on your data – but it's often useful for serialization / deserialization.
The new IOBuffer will assume ownership of the buffer, and free it appropriately (by calling the UniquePtr's custom deleter, or by calling delete or delete[] appropriately if there is no custom deleter) when the buffer is destroyed. The custom deleter, if any, must never throw exceptions.
The IOBuf data pointer will initially point to the start of the buffer, and the length will be the full capacity of the buffer (count * sizeof(T)).
On error, std::bad_alloc will be thrown, and the buffer will be freed before throwing the error.
Definition at line 1580 of file IOBuf.h.
References folly::size().
|
static |
A helper that takes ownerships a number of iovecs into an IOBuf chain. If count == 0, then a zero length buf is returned. This function never returns nullptr.
Definition at line 1047 of file IOBuf.cpp.
References count, create(), data(), i, folly::gen::move, takeOwnership(), and UNLIKELY.
|
inline |
Adjust the tail pointer backwards to include less valid data.
This moves the tail pointer backwards so that the last amount bytes are no longer considered valid data. The caller is responsible for ensuring that amount is less than or equal to the actual data length.
This does not modify any actual data in the buffer.
Definition at line 718 of file IOBuf.h.
References length_.
Referenced by folly::io::detail::CursorBase< Cursor, const IOBuf >::cloneAtMost(), proxygen::ZlibStreamCompressor::compress(), proxygen::SPDYCodec::generateDataFrame(), TEST(), fizz::trimBytes(), and folly::TypedIOBuf< T >::trimEnd().
|
inline |
Adjust the data pointer forwards to include less valid data.
This moves the data pointer forwards so that the first amount bytes are no longer considered valid data. The caller is responsible for ensuring that amount is less than or equal to the actual data length.
This does not modify any actual data in the buffer.
Definition at line 703 of file IOBuf.h.
References data_, and length_.
Referenced by folly::io::detail::CursorBase< Cursor, const IOBuf >::cloneAtMost(), proxygen::compress::HPACKScheme::decode(), proxygen::compress::QMINScheme::decode(), folly::io::RWCursor< access >::insert(), TEST(), folly::io::test::TEST_P(), and folly::TypedIOBuf< T >::trimStart().
|
inline |
Remove this IOBuf from its current chain.
Since ownership of all elements an IOBuf chain is normally maintained by the head of the chain, unlink() transfers ownership of this IOBuf from the chain and gives it to the caller. A new unique_ptr to the IOBuf is returned to the caller. The caller must store the returned unique_ptr (or call release() on it) to take ownership, otherwise the IOBuf will be immediately destroyed.
Since unlink transfers ownership of the IOBuf to the caller, be careful not to call unlink() on the head of a chain if you already maintain ownership on the head of the chain via other means. The pop() method is a better choice for that situation.
Definition at line 847 of file IOBuf.h.
Referenced by operator=(), TEST(), and ~IOBuf().
|
inline |
Ensure that this IOBuf has a unique buffer that is not shared by other IOBufs.
unshare() operates on an entire chain of IOBuf objects. If the chain is shared, it may also coalesce the chain when making it unique. If the chain is coalesced, subsequent IOBuf objects in the current chain will be automatically deleted.
Note that buffers owned by other (non-IOBuf) users are automatically considered shared.
Throws std::bad_alloc on error. On error the IOBuf chain will be unmodified.
Currently unshare may also throw std::overflow_error if it tries to coalesce. (TODO: In the future it would be nice if unshare() were smart enough not to coalesce the entire buffer if the data is too large. However, in practice this seems unlikely to become an issue.)
Definition at line 997 of file IOBuf.h.
Referenced by fillBuf(), and TEST().
|
private |
Definition at line 632 of file IOBuf.cpp.
References coalesceSlow(), current, isChained(), isSharedOne(), and next_.
|
inline |
Ensure that this IOBuf has a unique buffer that is not shared by other IOBufs.
unshareOne() operates on a single IOBuf object. This IOBuf will have a unique buffer after unshareOne() returns, but other IOBufs in the chain may still be shared after unshareOne() returns.
Throws std::bad_alloc on error. On error the IOBuf will be unmodified.
Definition at line 1015 of file IOBuf.h.
Referenced by TEST().
|
private |
Definition at line 606 of file IOBuf.cpp.
References allocExtBuffer(), buf_, capacity_, data_, decrementRefcount(), headroom(), length_, setFlagsAndSharedInfo(), sharedInfo(), and uint8_t.
|
static |
Create a new IOBuf object that points to an existing user-owned buffer.
This should only be used when the caller knows the lifetime of the IOBuf object ahead of time and can ensure that all IOBuf objects that will point to this buffer will be destroyed before the buffer itself is destroyed.
This buffer will not be freed automatically when the last IOBuf referencing it is destroyed. It is the caller's responsibility to free the buffer after the last IOBuf has been destroyed.
The IOBuf data pointer will initially point to the start of the buffer, and the length will be the full capacity of the buffer.
An IOBuf created using wrapBuffer() will always be reported as shared. unshare() may be used to create a writable copy of the buffer.
On error, std::bad_alloc will be thrown.
Definition at line 353 of file IOBuf.cpp.
References capacity(), and WRAP_BUFFER.
Referenced by folly::AsyncSSLSocket::clientHelloParsingCallback(), fizz::server::AeadTokenCipher< AeadType, HkdfType >::createAead(), fizz::sm::getCertificateRequest(), fizz::Exporter::getEkm(), fizz::sm::getHrrKeyExchangers(), fizz::KeyScheduler::getResumptionSecret(), fizz::sm::handleCertMsg(), fizz::sm::handleEarlyAppWrite(), folly::bser::parseBser(), folly::io::test::StreamingCompressionTest::runFlushTest(), folly::io::test::CompressionTest::runSimpleIOBufTest(), folly::io::test::CompressionVarintTest::runSimpleTest(), folly::io::test::CompressionCorruptionTest::runSimpleTest(), folly::io::test::AutomaticCodecTest::runSimpleTest(), folly::io::test::StreamingCompressionTest::runUncompressStreamTest(), fizz::server::test::TEST(), folly::test::TEST(), TEST(), folly::io::test::TEST(), fizz::testing::TEST_P(), folly::io::test::TEST_P(), folly::IOBufQueue::wrapBuffer(), wrapIov(), folly::WriteChainAsyncTransportWrapper< folly::AsyncTransportWrapper >::write(), and folly::AsyncPipeWriter::write().
Definition at line 387 of file IOBuf.h.
References folly::Range< Iter >::data(), folly::pushmi::__adl::noexcept(), and folly::Range< Iter >::size().
|
staticnoexcept |
Similar to wrapBuffer(), but returns IOBuf by value rather than heap-allocating it.
Definition at line 357 of file IOBuf.cpp.
References capacity(), and IOBuf().
Referenced by fizz::HkdfImpl< Hash >::extract(), fizz::EncryptedReadRecordLayer::getDecryptedBuf(), and fizz::EncryptedWriteRecordLayer::write().
Definition at line 398 of file IOBuf.h.
References fizz::test::copyBuffer(), folly::pushmi::__adl::noexcept(), and folly::size().
|
static |
A helper that wraps a number of iovecs into an IOBuf chain. If count == 0, then a zero length buf is returned. This function never returns nullptr.
Definition at line 1027 of file IOBuf.cpp.
References count, create(), data(), i, folly::gen::move, UNLIKELY, and wrapBuffer().
Referenced by folly::WriteChainAsyncTransportWrapper< folly::AsyncTransportWrapper >::writev().
|
inline |
Get a writable pointer to the start of the buffer.
The caller is responsible for calling unshare() first to ensure that it is actually safe to write to the buffer.
Definition at line 572 of file IOBuf.h.
Referenced by folly::AsyncPipeReader::handlerReady(), reserveSlow(), and folly::TypedIOBuf< T >::writableBuffer().
|
inline |
Get a writable pointer to the start of the data.
The caller is responsible for calling unshare() first to ensure that it is actually safe to write to the buffer.
Definition at line 509 of file IOBuf.h.
References data_.
Referenced by append(), fizz::detail::decFunc(), proxygen::HPACKDecodeBuffer::decodeLiteral(), fizz::detail::encFunc(), proxygen::GzipHeaderCodec::encode(), fizz::detail::evpEncrypt(), fillBuf(), IOBuf(), MoveToFbStringTest::makeBuf(), fizz::testing::modifyData(), fizz::testing::modifySig(), moveToFbString(), prepend(), proxygen::readFileToIOBuf(), CurlService::CurlClient::sendRequest(), TEST(), TEST_F(), fizz::transformBuffer(), and folly::TypedIOBuf< T >::writableData().
|
inline |
Get a writable pointer to the end of the data.
The caller is responsible for calling unshare() first to ensure that it is actually safe to write to the buffer.
Definition at line 526 of file IOBuf.h.
References data_, and length_.
Referenced by folly::IOBufQueue::append(), folly::gen::detail::consumeBufferPlus(), folly::IOBufQueue::dcheckCacheIntegrity(), folly::io::StreamCodec::doUncompress(), moveToFbString(), TEST(), folly::IOBufQueue::updateWritableTailCache(), and folly::TypedIOBuf< T >::writableTail().
Definition at line 1433 of file IOBuf.h.
Referenced by cloneOneAsValue(), coalesceAndReallocate(), freeExtBuffer(), IOBuf(), moveToFbString(), operator=(), reserveSlow(), and unshareOneSlow().
|
private |
Definition at line 1435 of file IOBuf.h.
Referenced by cloneOneAsValue(), coalesceAndReallocate(), IOBuf(), operator=(), reserveSlow(), and unshareOneSlow().
Definition at line 1432 of file IOBuf.h.
Referenced by cloneOneAsValue(), coalesceAndReallocate(), IOBuf(), operator=(), reserveSlow(), and unshareOneSlow().
|
mutableprivate |
Definition at line 1438 of file IOBuf.h.
Referenced by cloneOneAsValue(), moveToFbString(), and operator=().
|
private |
Definition at line 1434 of file IOBuf.h.
Referenced by cloneOneAsValue(), coalesceAndReallocate(), coalesceSlow(), computeChainDataLength(), operator=(), reserveSlow(), and unshareOneSlow().
|
private |
Definition at line 1423 of file IOBuf.h.
Referenced by cloneAsValue(), coalesceAndReallocate(), coalesceSlow(), computeChainDataLength(), countChainElements(), empty(), IOBuf(), isManaged(), isShared(), makeManagedChained(), markExternallyShared(), operator=(), prependChain(), separateChain(), unshareChained(), and ~IOBuf().
|
private |
Definition at line 1424 of file IOBuf.h.
Referenced by coalesceAndReallocate(), IOBuf(), operator=(), prependChain(), and separateChain().