]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
buffer: templatize prepare_iov
authorSage Weil <sage@redhat.com>
Thu, 27 Apr 2017 20:38:20 +0000 (16:38 -0400)
committerSage Weil <sage@redhat.com>
Thu, 27 Apr 2017 20:38:20 +0000 (16:38 -0400)
Allow this to work on std::vector types.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/buffer.cc
src/include/buffer.h

index ae70a21c94f97899bd02be88c7db12d69125c780..957f5da8c56812a1f8c7853c10d5d0bd03a93657 100644 (file)
@@ -2338,19 +2338,6 @@ int buffer::list::write_fd(int fd, uint64_t offset) const
   return 0;
 }
 
-void buffer::list::prepare_iov(std::vector<iovec> *piov) const
-{
-  assert(_buffers.size() <= IOV_MAX);
-  piov->resize(_buffers.size());
-  unsigned n = 0;
-  for (std::list<buffer::ptr>::const_iterator p = _buffers.begin();
-       p != _buffers.end();
-       ++p, ++n) {
-    (*piov)[n].iov_base = (void *)p->c_str();
-    (*piov)[n].iov_len = p->length();
-  }
-}
-
 int buffer::list::write_fd_zero_copy(int fd) const
 {
   if (!can_zero_copy())
index 4d4942adaabf6e4e5191894627090188153c552b..3a93091b83a7b18700a8eda849678c16a01bdaea 100644 (file)
@@ -17,6 +17,7 @@
 #if defined(__linux__) || defined(__FreeBSD__)
 #include <stdlib.h>
 #endif
+#include <limits.h>
 
 #ifndef _XOPEN_SOURCE
 # define _XOPEN_SOURCE 600
@@ -867,7 +868,18 @@ namespace buffer CEPH_BUFFER_API {
     int write_fd(int fd) const;
     int write_fd(int fd, uint64_t offset) const;
     int write_fd_zero_copy(int fd) const;
-    void prepare_iov(std::vector<iovec> *piov) const;
+    template<typename VectorT>
+    void prepare_iov(VectorT *piov) const {
+      assert(_buffers.size() <= IOV_MAX);
+      piov->resize(_buffers.size());
+      unsigned n = 0;
+      for (std::list<buffer::ptr>::const_iterator p = _buffers.begin();
+          p != _buffers.end();
+          ++p, ++n) {
+       (*piov)[n].iov_base = (void *)p->c_str();
+       (*piov)[n].iov_len = p->length();
+      }
+    }
     uint32_t crc32c(uint32_t crc) const;
     void invalidate_crc();
   };