Both the send and receive handling in the TCP code (in net/tcp_channel.h
) goes something like:
while (rem > 0) {
// attempt to read/write using a sys call. The result is a ssize_t type that is stored in a variable res.
if (res < 0) {
// do error handling
}
rem -= res;
}
The decrement rem -= res
at the end of the loop will increase rem
in case of an error, which causes all kinds of weird behavior in other places of the code. The correct behavior should be to guard the decrement so that it only happens if we actually managed to read/write to the socket.