From de5c0a28fb02f1f62f1b9fff770dae8f8360278b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 27 Apr 2017 16:38:20 -0400 Subject: [PATCH] buffer: templatize prepare_iov Allow this to work on std::vector types. Signed-off-by: Sage Weil --- src/common/buffer.cc | 13 ------------- src/include/buffer.h | 14 +++++++++++++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index ae70a21c94f..957f5da8c56 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -2338,19 +2338,6 @@ int buffer::list::write_fd(int fd, uint64_t offset) const return 0; } -void buffer::list::prepare_iov(std::vector *piov) const -{ - assert(_buffers.size() <= IOV_MAX); - piov->resize(_buffers.size()); - unsigned n = 0; - for (std::list::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()) diff --git a/src/include/buffer.h b/src/include/buffer.h index 4d4942adaab..3a93091b83a 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -17,6 +17,7 @@ #if defined(__linux__) || defined(__FreeBSD__) #include #endif +#include #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 *piov) const; + template + void prepare_iov(VectorT *piov) const { + assert(_buffers.size() <= IOV_MAX); + piov->resize(_buffers.size()); + unsigned n = 0; + for (std::list::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(); }; -- 2.39.5