diff --git a/libtransmission/peer-io.cc b/libtransmission/peer-io.cc index a2cfc1b38..4bc73f1d2 100644 --- a/libtransmission/peer-io.cc +++ b/libtransmission/peer-io.cc @@ -796,11 +796,8 @@ size_t tr_peerIo::getWriteBufferSpace(uint64_t now) const noexcept void tr_peerIo::write(libtransmission::Buffer& buf, bool is_piece_data) { - for (auto& ch : buf) - { - encrypt(1, &ch); - } - + auto [bytes, len] = buf.pullup(); + encrypt(len, bytes); outbuf_info.emplace_back(std::size(buf), is_piece_data); outbuf.add(buf); } diff --git a/libtransmission/tr-buffer.h b/libtransmission/tr-buffer.h index 7368e3a68..a0d8d81c9 100644 --- a/libtransmission/tr-buffer.h +++ b/libtransmission/tr-buffer.h @@ -266,6 +266,11 @@ public: return iov; } + [[nodiscard]] std::pair pullup() + { + return { reinterpret_cast(evbuffer_pullup(buf_.get(), -1)), size() }; + } + void commit(Iovec iov) { evbuffer_commit_space(buf_.get(), &iov, 1);