X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fio%2FIOBufQueue.h;h=c90deaf87e405de7dd2b61734a77d7a725c5ce62;hb=d84b1b628d8b723135a34de8dc79cbae3412d8fb;hp=59fdc940057626f483e94df7146ff23f043b9412;hpb=ce64f0f685111ac24c7a321ea56d0c3524621df1;p=folly.git diff --git a/folly/io/IOBufQueue.h b/folly/io/IOBufQueue.h index 59fdc940..c90deaf8 100644 --- a/folly/io/IOBufQueue.h +++ b/folly/io/IOBufQueue.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef FOLLY_IO_IOBUF_QUEUE_H -#define FOLLY_IO_IOBUF_QUEUE_H +#pragma once #include @@ -196,7 +195,17 @@ class IOBufQueue { * @throws std::underflow_error if n exceeds the number of bytes * in the queue. */ - std::unique_ptr split(size_t n); + std::unique_ptr split(size_t n) { + return split(n, true); + } + + /** + * Similar to split, but will return the entire queue instead of throwing + * if n exceeds the number of bytes in the queue. + */ + std::unique_ptr splitAtMost(size_t n) { + return split(n, false); + } /** * Similar to IOBuf::trimStart, but works on the whole queue. Will @@ -204,12 +213,24 @@ class IOBufQueue { */ void trimStart(size_t amount); + /** + * Similar to trimStart, but will trim at most amount bytes and returns + * the number of bytes trimmed. + */ + size_t trimStartAtMost(size_t amount); + /** * Similar to IOBuf::trimEnd, but works on the whole queue. Will * pop off buffers that have been completely trimmed. */ void trimEnd(size_t amount); + /** + * Similar to trimEnd, but will trim at most amount bytes and returns + * the number of bytes trimmed. + */ + size_t trimEndAtMost(size_t amount); + /** * Transfer ownership of the queue's entire IOBuf chain to the caller. */ @@ -261,8 +282,18 @@ class IOBufQueue { */ void clear(); + /** + * Append the queue to a std::string. Non-destructive. + */ + void appendToString(std::string& out) const; + + /** + * Calls IOBuf::gather() on the head of the queue, if it exists. + */ + void gather(uint64_t maxLength); + /** Movable */ - IOBufQueue(IOBufQueue&&); + IOBufQueue(IOBufQueue&&) noexcept; IOBufQueue& operator=(IOBufQueue&&); private: @@ -274,6 +305,8 @@ class IOBufQueue { std::pair preallocateSlow( uint64_t min, uint64_t newAllocationSize, uint64_t max); + std::unique_ptr split(size_t n, bool throwOnUnderflow); + static const size_t kChainLengthNotCached = (size_t)-1; /** Not copyable */ IOBufQueue(const IOBufQueue&) = delete; @@ -290,5 +323,3 @@ class IOBufQueue { }; } // folly - -#endif // FOLLY_IO_IOBUF_QUEUE_H