IOBuf::getIov
[folly.git] / folly / io / IOBuf.h
index 90dcb1e3cfc658de5f104e92bd297825077bc8f8..007c38414279c5a3e3e49bb16210f3a4a32a45ba 100644 (file)
 #include <cstring>
 #include <memory>
 #include <limits>
+#include <sys/uio.h>
 #include <type_traits>
 
 #include <boost/iterator/iterator_facade.hpp>
 
 #include "folly/FBString.h"
 #include "folly/Range.h"
+#include "folly/FBVector.h"
 
 namespace folly {
 
@@ -922,6 +924,17 @@ class IOBuf {
    */
   std::unique_ptr<IOBuf> cloneOne() 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.
+   */
+  folly::fbvector<struct iovec> getIov() const;
+
   // Overridden operator new and delete.
   // These directly use malloc() and free() to allocate the space for IOBuf
   // objects.  This is needed since IOBuf::create() manually uses malloc when