summaryrefslogtreecommitdiff
path: root/src/network/core/tcp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/core/tcp.cpp')
-rw-r--r--src/network/core/tcp.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index 1461a9298..aa1e1cbed 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -156,9 +156,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
/* Read packet size */
if (!p->HasPacketSizeData()) {
- while (!p->HasPacketSizeData()) {
- /* Read the size of the packet */
- res = recv(this->sock, (char*)p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
+ while (p->RemainingBytesToTransfer() != 0) {
+ res = p->TransferIn<int>(recv, this->sock, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
@@ -175,7 +174,6 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
this->CloseConnection();
return nullptr;
}
- p->pos += res;
}
/* Parse the size in the received packet and if not valid, close the connection. */
@@ -186,8 +184,8 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
}
/* Read rest of packet */
- while (p->pos < p->size) {
- res = recv(this->sock, (char*)p->buffer + p->pos, p->size - p->pos, 0);
+ while (p->RemainingBytesToTransfer() != 0) {
+ res = p->TransferIn<int>(recv, this->sock, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
@@ -204,8 +202,6 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
this->CloseConnection();
return nullptr;
}
-
- p->pos += res;
}
/* Prepare for receiving a new packet */