Would it be possible that a read on a file descriptor (in this case a non-blocking socket) that has reached EOF would block before EOF can be detected?
Like in the following sequence:
read
returns -1 and errno
is set to EWOULDBLOCK
or EAGAIN
read
returns 0, which means that EOF has been reachedor
would it always look like this in case it is waiting for data:
read
returns -1 and errno
is set to EWOULDBLOCK
or EAGAIN
read
returns a value > 0read
returns 0, which means that EOF has been reachedThat is, does EWOULDBLOCK
imply that there will be more data available or is it possible that there are no more data when the file descriptor becomes available again?
... does EWOULDBLOCK imply that there will be more data available
No. EWOULDBLOCK only says that there are currently no data available. It does not make any statements about future traffic, i.e. if new data will be arrive or if the connection will be closed.
If the connection is shutdown by the peer and the FIN received and fully processed by the local OS, then recv
will not return EWOULDBLOCK but will signal the EOF (assuming all data so far where read already).