Timestamping callback interface in folly::AsyncSocket
[folly.git] / folly / io / IOBufQueue.cpp
index 37e0635e505c59344e267c1c62b96f01af0b198e..6e4715d7d3af94c00135807488194de2e1136afb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -150,9 +150,9 @@ IOBufQueue::append(const void* buf, size_t len) {
   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();
@@ -187,13 +187,16 @@ IOBufQueue::preallocateSlow(uint64_t min, uint64_t newAllocationSize,
                    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();
@@ -209,7 +212,7 @@ IOBufQueue::split(size_t n) {
       break;
     }
   }
-  return std::move(result);
+  return result;
 }
 
 void IOBufQueue::trimStart(size_t amount) {
@@ -286,4 +289,10 @@ void IOBufQueue::appendToString(std::string& out) const {
   }
 }
 
+void IOBufQueue::gather(uint64_t maxLength) {
+  if (head_ != nullptr) {
+    head_->gather(maxLength);
+  }
+}
+
 } // folly