summaryrefslogtreecommitdiff
path: root/src/network/core/tcp.cpp
diff options
context:
space:
mode:
authorRubidium <rubidium@openttd.org>2021-04-18 10:23:41 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-04-24 20:42:01 +0200
commitd4f027c03bfc5f632b7d63c125dfa57a7ba89926 (patch)
treebce76afc0a253cf8128153fcb7b5ebae36c93434 /src/network/core/tcp.cpp
parent98aa561cf759f75971afd5dfc4d42e6921a8ab1a (diff)
downloadopenttd-d4f027c03bfc5f632b7d63c125dfa57a7ba89926.tar.xz
Codechange: encapsulate writing data from Packets into sockets/files/buffers to prevent packet state modifications outside of the Packet
Diffstat (limited to 'src/network/core/tcp.cpp')
-rw-r--r--src/network/core/tcp.cpp6
1 files changed, 2 insertions, 4 deletions
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<int>(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;