Skip to content

Commit

Permalink
Minor tweaks to catch partial reads and split packets
Browse files Browse the repository at this point in the history
  • Loading branch information
shaun-edwards committed Aug 8, 2013
1 parent daf3fbc commit 5dfa991
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions simple_message/src/socket/simple_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5dfa991

Please sign in to comment.