Skip to content

Commit

Permalink
simplify frame_queue.write
Browse files Browse the repository at this point in the history
  • Loading branch information
pionere committed Dec 1, 2023
1 parent 9df0853 commit 4d384f1
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Source/dvlnet/frame_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Source/dvlnet/frame_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion Source/dvlnet/protocol_zt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions Source/dvlnet/tcp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions Source/dvlnet/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 1 addition & 3 deletions Source/dvlnet/tcpd_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 4d384f1

Please sign in to comment.