move assignment operators for folly::Synchronized
[folly.git] / folly / io / IOBuf.h
index 90dcb1e3cfc658de5f104e92bd297825077bc8f8..3a2fa383b71cafffd38a75543ac5e60c719def24 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"
+
+// Ignore shadowing warnings within this file, so includers can use -Wshadow.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
 
 namespace folly {
 
@@ -216,6 +222,13 @@ class IOBuf {
    */
   static std::unique_ptr<IOBuf> create(uint32_t capacity);
 
+  /**
+   * Allocate a new IOBuf chain with the requested total capacity, allocating
+   * no more than maxBufCapacity to each buffer.
+   */
+  static std::unique_ptr<IOBuf> createChain(
+      size_t totalCapacity, uint32_t maxBufCapacity);
+
   /**
    * Create a new IOBuf pointing to an existing data buffer.
    *
@@ -922,6 +935,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
@@ -1194,4 +1218,6 @@ inline IOBuf::Iterator IOBuf::end() const { return cend(); }
 
 } // folly
 
+#pragma GCC diagnostic pop
+
 #endif // FOLLY_IO_IOBUF_H_