I am using the below code to read from a non-blocking socket, but occasionally I read 1 byte less than is shown for the same socket on wireshark. For example wireshark could show that the data received has a length of 185 as it should but the recv only gets 184 bytes.
int len = 0;
unsigned char buffer[**Twice larger than could be received**];
while (1) {
int rc = recv(sock, buffer+len, sizeof(buffer) - len, 0);
if (rc < 0) {
if (errno == EWOULDBLOCK){
continue;
}
break;
}
if (rc == 0) {
break;
}
len += rc;
}