IOBuf::getIov
[folly.git] / folly / io / IOBuf.cpp
index aac0be5154798b04bf44c36d8d43553bafe9a6f1..e9b9151b13dc93a29d1e31a715f4c4994bec7d48 100644 (file)
@@ -643,4 +643,18 @@ IOBuf::Iterator IOBuf::cend() const {
   return Iterator(nullptr, nullptr);
 }
 
+folly::fbvector<struct iovec> IOBuf::getIov() const {
+  folly::fbvector<struct iovec> iov;
+  iov.reserve(countChainElements());
+  IOBuf const* p = this;
+  do {
+    // some code can get confused by empty iovs, so skip them
+    if (p->length() > 0) {
+      iov.push_back({(void*)p->data(), p->length()});
+    }
+    p = p->next();
+  } while (p != this);
+  return iov;
+}
+
 } // folly