不一定,hp_ux下就不是。请看man recv。基本意思是设置了 O_NDELAY后,如果没数据可读也会返回0。
If the remote side of a connection-based socket has performed an
orderly shutdown and there is no more data to read (the socket
has reached the end of its data stream), recv() completes and
returns 0. The recv() call will also complete and return 0 when
there is no data to read. To distinguish this condition from the
end of the data stream, you can use a select() or poll() call to
check for data before calling recv(). If the select() or poll()
call indicates that an event has occurred on the socket, the
subsequent but recv() call will only return 0 if the socket has
reached the end of the data stream.
RETURN VALUE
recv(), recvfrom(), and recvmsg() return the following values:
n Successful completion. n is the number of bytes received.
0 The socket is blocking and the transport connection to the
remote node failed, or the remote side of a connection-based
socket has performed an orderly shutdown and there is no
more data to read (the socket has reached the end of its
data stream). Sockets with the O_NDELAY flag set may also
return 0 at any time when there is no data available.
-1 Failure. errno is set to indicate the error.
阅读(1770) | 评论(0) | 转发(0) |