This code running on Linux:
int r, c;
...
assert(0 == (O_NONBLOCK & fcntl(sockfd, F_GETFL, 0)));
errno = 0;
r = read(sockfd, &c, 1);
if (r == 0 && errno == 0) {
printf("What gives?\n");
}
...
which is performing a read from a socket, will occasionally return zero (in r) and leave errno set to zero (0) as well. What situation am I encountering? I’d really like to have the read block unless there is an error.
This means that the client finished sending data (eg: did a
shutdownfor writing), and you already read all available data.