diff --git a/include/libtorrent/chained_buffer.hpp b/include/libtorrent/chained_buffer.hpp index a308cf717..24ea1c761 100644 --- a/include/libtorrent/chained_buffer.hpp +++ b/include/libtorrent/chained_buffer.hpp @@ -160,7 +160,7 @@ namespace libtorrent { // enough room, returns 0 char* allocate_appendix(int s); - std::vector const& build_iovec(int to_send); + span build_iovec(int to_send); void clear(); diff --git a/include/libtorrent/span.hpp b/include/libtorrent/span.hpp index 72dbbd03d..ddbb5850f 100644 --- a/include/libtorrent/span.hpp +++ b/include/libtorrent/span.hpp @@ -121,6 +121,8 @@ namespace aux { bool empty() const noexcept { return m_len == 0; } T* data() const noexcept { return m_ptr; } + using const_iterator = T const*; + using const_reverse_iterator = std::reverse_iterator; using iterator = T*; using reverse_iterator = std::reverse_iterator; diff --git a/src/chained_buffer.cpp b/src/chained_buffer.cpp index 4c458d0e9..a8fe15341 100644 --- a/src/chained_buffer.cpp +++ b/src/chained_buffer.cpp @@ -112,7 +112,7 @@ namespace libtorrent { return insert; } - std::vector const& chained_buffer::build_iovec(int const to_send) + span chained_buffer::build_iovec(int const to_send) { TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(!m_destructed); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 2ab0df465..b504bf0c4 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -5616,7 +5616,7 @@ namespace libtorrent { #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::outgoing, "ASYNC_WRITE", "bytes: %d", amount_to_send); #endif - std::vector const& vec = m_send_buffer.build_iovec(amount_to_send); + auto const vec = m_send_buffer.build_iovec(amount_to_send); ADD_OUTSTANDING_ASYNC("peer_connection::on_send_data"); #if TORRENT_USE_ASSERTS diff --git a/test/test_buffer.cpp b/test/test_buffer.cpp index e4586f792..51ae718de 100644 --- a/test/test_buffer.cpp +++ b/test/test_buffer.cpp @@ -175,7 +175,7 @@ bool compare_chained_buffer(chained_buffer& b, char const* mem, int size) { if (size == 0) return true; std::vector flat((std::size_t(size))); - std::vector const& iovec2 = b.build_iovec(size); + auto const iovec2 = b.build_iovec(size); int copied = copy_buffers(iovec2, &flat[0]); TEST_CHECK(copied == size); return std::memcmp(&flat[0], mem, std::size_t(size)) == 0;