From 5dfa99193a51f42da25a315979f4165b747654dd Mon Sep 17 00:00:00 2001 From: Shaun Edwards Date: Thu, 8 Aug 2013 15:07:34 -0500 Subject: [PATCH] Minor tweaks to catch partial reads and split packets --- simple_message/src/socket/simple_socket.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/simple_message/src/socket/simple_socket.cpp b/simple_message/src/socket/simple_socket.cpp index 7bb95f20..99194952 100644 --- a/simple_message/src/socket/simple_socket.cpp +++ b/simple_message/src/socket/simple_socket.cpp @@ -121,24 +121,26 @@ namespace industrial { if(ready) { - rc = rawReceiveBytes(this->buffer_, num_bytes); + rc = rawReceiveBytes(this->buffer_, remainBytes); if (this->SOCKET_FAIL == rc) { this->logSocketError("Socket received failed", rc); + remainBytes = 0; rtn = false; break; } else if (0 == rc) { LOG_WARN("Recieved zero bytes: %u", rc); + remainBytes = 0; rtn = false; break; } else { - remainBytes = num_bytes - rc; - LOG_COMM("Byte array receive, bytes read: %u, bytes left: %u", - rc, remainBytes); + remainBytes = remainBytes - rc; + LOG_COMM("Byte array receive, bytes read: %u, bytes reqd: %u, bytes left: %u", + rc, num_bytes, remainBytes); buffer.load(&this->buffer_, rc); rtn = true; }