Sending large data package with TCP - winsock
In both read and write you should leave the loop after an error (unless you have explicitly tested and fixed the error).

while(totalRecieved &lt; readSize)
{
    dataRecieved = recv(socket, date + totalRecieved, readSize - totalRecieved);
    if (dataRecieved &gt; 0)
    {
        totalRecieved += dataRecieved;
        continue;
    }
    if ((dataRecieved == -1) &amp;&amp; (errno == EAGAIN || errno == EWOULDBLOCK))
    {
        // Simple error just try again.
        continue;
    }
    if (dataRecieved == -1 &amp;&amp; errno == EINTR)
    {
        // An interrupt was received.
        // This is usually a signal by another thread to give up
        // but you can ignore it if you want.
        continue;
    }
    // Any other error is bad.
    // looping is just going to cause infinite loops.
    break;
}

if (totalRecieved &lt; readSize)
{
    // BAD THINGS HAVE HAPPENED
}