From d4f027c03bfc5f632b7d63c125dfa57a7ba89926 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 18 Apr 2021 10:23:41 +0200 Subject: Codechange: encapsulate writing data from Packets into sockets/files/buffers to prevent packet state modifications outside of the Packet --- src/network/core/tcp.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/network/core/tcp.cpp') diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index aa1e1cbed..ab18f47a8 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -103,7 +103,7 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down) p = this->packet_queue; while (p != nullptr) { - res = send(this->sock, (const char*)p->buffer + p->pos, p->size - p->pos, 0); + res = p->TransferOut(send, this->sock, 0); if (res == -1) { int err = GET_LAST_ERROR(); if (err != EWOULDBLOCK) { @@ -122,10 +122,8 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down) return SPS_CLOSED; } - p->pos += res; - /* Is this packet sent? */ - if (p->pos == p->size) { + if (p->RemainingBytesToTransfer() == 0) { /* Go to the next packet */ this->packet_queue = p->next; delete p; -- cgit v1.2.3-70-g09d2