/*
- * Copyright 2015 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.
while (len != 0) {
if ((head_ == nullptr) || head_->prev()->isSharedOne() ||
(head_->prev()->tailroom() == 0)) {
- appendToChain(head_, std::move(
+ appendToChain(head_,
IOBuf::create(std::max(MIN_ALLOC_SIZE,
- std::min(len, MAX_ALLOC_SIZE)))),
+ std::min(len, MAX_ALLOC_SIZE))),
false);
}
IOBuf* last = head_->prev();
std::min(max, last->tailroom()));
}
-unique_ptr<IOBuf>
-IOBufQueue::split(size_t n) {
+unique_ptr<IOBuf> IOBufQueue::split(size_t n, bool throwOnUnderflow) {
unique_ptr<IOBuf> result;
while (n != 0) {
if (head_ == nullptr) {
- throw std::underflow_error(
- "Attempt to remove more bytes than are present in IOBufQueue");
+ if (throwOnUnderflow) {
+ throw std::underflow_error(
+ "Attempt to remove more bytes than are present in IOBufQueue");
+ } else {
+ break;
+ }
} else if (head_->length() <= n) {
n -= head_->length();
chainLength_ -= head_->length();
break;
}
}
- return std::move(result);
+ return result;
}
void IOBufQueue::trimStart(size_t amount) {
}
}
+void IOBufQueue::gather(uint64_t maxLength) {
+ if (head_ != nullptr) {
+ head_->gather(maxLength);
+ }
+}
+
} // folly