don't copy a vector into the async_write operation for iovec. Since the chained_buffer will own the vector anyway, just make it return a span and copy that
This commit is contained in:
parent
3ce277ba7f
commit
8fc69f5d2e
|
@ -160,7 +160,7 @@ namespace libtorrent {
|
||||||
// enough room, returns 0
|
// enough room, returns 0
|
||||||
char* allocate_appendix(int s);
|
char* allocate_appendix(int s);
|
||||||
|
|
||||||
std::vector<boost::asio::const_buffer> const& build_iovec(int to_send);
|
span<boost::asio::const_buffer const> build_iovec(int to_send);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,8 @@ namespace aux {
|
||||||
bool empty() const noexcept { return m_len == 0; }
|
bool empty() const noexcept { return m_len == 0; }
|
||||||
T* data() const noexcept { return m_ptr; }
|
T* data() const noexcept { return m_ptr; }
|
||||||
|
|
||||||
|
using const_iterator = T const*;
|
||||||
|
using const_reverse_iterator = std::reverse_iterator<T const*>;
|
||||||
using iterator = T*;
|
using iterator = T*;
|
||||||
using reverse_iterator = std::reverse_iterator<T*>;
|
using reverse_iterator = std::reverse_iterator<T*>;
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ namespace libtorrent {
|
||||||
return insert;
|
return insert;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<boost::asio::const_buffer> const& chained_buffer::build_iovec(int const to_send)
|
span<boost::asio::const_buffer const> chained_buffer::build_iovec(int const to_send)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(is_single_thread());
|
TORRENT_ASSERT(is_single_thread());
|
||||||
TORRENT_ASSERT(!m_destructed);
|
TORRENT_ASSERT(!m_destructed);
|
||||||
|
|
|
@ -5616,7 +5616,7 @@ namespace libtorrent {
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#ifndef TORRENT_DISABLE_LOGGING
|
||||||
peer_log(peer_log_alert::outgoing, "ASYNC_WRITE", "bytes: %d", amount_to_send);
|
peer_log(peer_log_alert::outgoing, "ASYNC_WRITE", "bytes: %d", amount_to_send);
|
||||||
#endif
|
#endif
|
||||||
std::vector<boost::asio::const_buffer> 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");
|
ADD_OUTSTANDING_ASYNC("peer_connection::on_send_data");
|
||||||
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
|
|
|
@ -175,7 +175,7 @@ bool compare_chained_buffer(chained_buffer& b, char const* mem, int size)
|
||||||
{
|
{
|
||||||
if (size == 0) return true;
|
if (size == 0) return true;
|
||||||
std::vector<char> flat((std::size_t(size)));
|
std::vector<char> flat((std::size_t(size)));
|
||||||
std::vector<boost::asio::const_buffer> const& iovec2 = b.build_iovec(size);
|
auto const iovec2 = b.build_iovec(size);
|
||||||
int copied = copy_buffers(iovec2, &flat[0]);
|
int copied = copy_buffers(iovec2, &flat[0]);
|
||||||
TEST_CHECK(copied == size);
|
TEST_CHECK(copied == size);
|
||||||
return std::memcmp(&flat[0], mem, std::size_t(size)) == 0;
|
return std::memcmp(&flat[0], mem, std::size_t(size)) == 0;
|
||||||
|
|
Loading…
Reference in New Issue