diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-04-21 15:31:43 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-04-21 15:31:43 +0200 |
commit | 71760514fc044f273914c17b1510fa3cf10419b3 (patch) | |
tree | 72f822efde300d8e1e9de1cc578d431ff72e0e03 /Network.cpp | |
parent | 2017-04-15 (diff) | |
download | AltCraft-71760514fc044f273914c17b1510fa3cf10419b3.tar AltCraft-71760514fc044f273914c17b1510fa3cf10419b3.tar.gz AltCraft-71760514fc044f273914c17b1510fa3cf10419b3.tar.bz2 AltCraft-71760514fc044f273914c17b1510fa3cf10419b3.tar.lz AltCraft-71760514fc044f273914c17b1510fa3cf10419b3.tar.xz AltCraft-71760514fc044f273914c17b1510fa3cf10419b3.tar.zst AltCraft-71760514fc044f273914c17b1510fa3cf10419b3.zip |
Diffstat (limited to 'Network.cpp')
-rw-r--r-- | Network.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Network.cpp b/Network.cpp index 8b25756..d979037 100644 --- a/Network.cpp +++ b/Network.cpp @@ -65,10 +65,20 @@ Packet Network::ReceivePacket() { return Packet(bufLen); } byte *bufPack = new byte[packetLen]; - for (int i = 0; i < packetLen; i++) - bufPack[i] = 'N'; - memcpy(bufPack, bufLen, rec); - if (m_socket.receive(bufPack + rec, packetLen - rec, rec) != sf::Socket::Done) { + std::copy(bufLen, bufLen + rec, bufPack); + size_t dataLen = rec; + while (m_socket.receive(bufPack + dataLen, packetLen - dataLen, rec) == sf::Socket::Done && dataLen < packetLen) { + dataLen += rec; + } + if (dataLen < packetLen) + throw 93; + else { + Packet p(bufPack); + delete[] bufPack; + return p; + } + + /*if (m_socket.receive(bufPack + rec, packetLen - rec, rec) != sf::Socket::Done) { delete[] bufPack; throw 93; } @@ -93,8 +103,6 @@ Packet Network::ReceivePacket() { std::cout << "\x1b[31m" << "Losted " << losted << " bytes of " << packetLen << "\x1b[0m" << std::endl; delete[] bufPack; throw 93; - } - Packet p(bufPack); - delete[] bufPack; - return p; + }*/ + throw 94; } |