diff --git a/Source/dvlnet/frame_queue.cpp b/Source/dvlnet/frame_queue.cpp index d35d119c1f6..afcb42dda9b 100644 --- a/Source/dvlnet/frame_queue.cpp +++ b/Source/dvlnet/frame_queue.cpp @@ -57,10 +57,10 @@ buffer_t frame_queue::read_packet() return ret; } -void frame_queue::write(buffer_t buf) +void frame_queue::write(const buffer_t& buf, unsigned len) { - current_size += buf.size(); - buffer_deque.push_back(std::move(buf)); + current_size += len; + buffer_deque.push_back(buffer_t(buf.begin(), buf.begin() + len)); } void frame_queue::clear() diff --git a/Source/dvlnet/frame_queue.h b/Source/dvlnet/frame_queue.h index 5f43f4150cf..482c7892278 100644 --- a/Source/dvlnet/frame_queue.h +++ b/Source/dvlnet/frame_queue.h @@ -35,7 +35,7 @@ class frame_queue { /* Read the next packet from the queue. Assumes the packet is ready (packet_ready returns true). */ buffer_t read_packet(); /* Append the content of a buffer to the frame. */ - void write(buffer_t buf); + void write(const buffer_t& buf, unsigned len); /* Clear the content of the frame. */ void clear(); diff --git a/Source/dvlnet/protocol_zt.cpp b/Source/dvlnet/protocol_zt.cpp index 239512b239e..8b667ce160d 100644 --- a/Source/dvlnet/protocol_zt.cpp +++ b/Source/dvlnet/protocol_zt.cpp @@ -143,7 +143,7 @@ bool protocol_zt::recv_peer(const endpoint& peer) while (true) { auto len = lwip_recv(ps.fd, recv_buffer.data(), frame_queue::MAX_FRAME_SIZE, 0); if (len >= 0) { - ps.recv_queue.write(buffer_t(buf, buf + len)); + ps.recv_queue.write(recv_buffer, len); } else { return errno == EAGAIN || errno == EWOULDBLOCK; } diff --git a/Source/dvlnet/tcp_client.cpp b/Source/dvlnet/tcp_client.cpp index d4f4dc1160a..2a0eace315c 100644 --- a/Source/dvlnet/tcp_client.cpp +++ b/Source/dvlnet/tcp_client.cpp @@ -75,9 +75,7 @@ void tcp_client::handle_recv(const asio::error_code& ec, size_t bytesRead) // as if all connections to other clients were lost return; } - recv_buffer.resize(bytesRead); - recv_queue.write(std::move(recv_buffer)); - recv_buffer.resize(frame_queue::MAX_FRAME_SIZE); + recv_queue.write(recv_buffer, bytesRead); while (recv_queue.packet_ready()) { packet* pkt = pktfty.make_in_packet(recv_queue.read_packet()); if (pkt != NULL) diff --git a/Source/dvlnet/tcp_server.cpp b/Source/dvlnet/tcp_server.cpp index 3b4b1c7427f..9471a341693 100644 --- a/Source/dvlnet/tcp_server.cpp +++ b/Source/dvlnet/tcp_server.cpp @@ -126,9 +126,7 @@ void tcp_server::handle_recv(const scc& con, const asio::error_code& ec, size_t return; } con->timeout = NET_TIMEOUT_ACTIVE; - con->recv_buffer.resize(bytesRead); - con->recv_queue.write(std::move(con->recv_buffer)); - con->recv_buffer.resize(frame_queue::MAX_FRAME_SIZE); + con->recv_queue.write(con->recv_buffer, bytesRead); while (con->recv_queue.packet_ready()) { packet* pkt = pktfty.make_in_packet(con->recv_queue.read_packet()); if (pkt == NULL || !handle_recv_packet(*pkt, con)) { diff --git a/Source/dvlnet/tcpd_client.cpp b/Source/dvlnet/tcpd_client.cpp index a7b97586454..61e2bc058be 100644 --- a/Source/dvlnet/tcpd_client.cpp +++ b/Source/dvlnet/tcpd_client.cpp @@ -205,9 +205,7 @@ void tcpd_client::handle_recv_conn(const scc& con, const asio::error_code& ec, s return; } con->timeout = NET_TIMEOUT_ACTIVE; - con->recv_buffer.resize(bytesRead); - con->recv_queue.write(std::move(con->recv_buffer)); - con->recv_buffer.resize(frame_queue::MAX_FRAME_SIZE); + con->recv_queue.write(con->recv_buffer, bytesRead); while (con->recv_queue.packet_ready()) { packet* pkt = pktfty.make_in_packet(con->recv_queue.read_packet()); if (pkt == NULL || !handle_recv_packet(con, *pkt)) {