From cff382a8cec04ea26cd3a45d466c6a2d4f30c3b3 Mon Sep 17 00:00:00 2001 From: CPunch Date: Fri, 21 Aug 2020 21:32:22 -0500 Subject: [PATCH] sets a limit for sendData() --- src/CNProtocol.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CNProtocol.cpp b/src/CNProtocol.cpp index ad724d6..f7df999 100644 --- a/src/CNProtocol.cpp +++ b/src/CNProtocol.cpp @@ -73,12 +73,15 @@ CNSocket::CNSocket(SOCKET s, PacketHandler ph): sock(s), pHandler(ph) { bool CNSocket::sendData(uint8_t* data, int size) { int sentBytes = 0; + int maxTries = 10; while (sentBytes < size) { int sent = send(sock, (buffer_t*)(data + sentBytes), size - sentBytes, 0); // no flags defined if (SOCKETERROR(sent)) { - if (errno == 11) + if (errno == 11 && maxTries > 0) { + maxTries--; continue; // try again + } std::cout << "[FATAL] SOCKET ERROR: " << errno << std::endl; return false; // error occured while sending bytes }