linux recv() function flag parameter?
What will happen if I use recv(sockfd, buffer, len, 0);
on a non-blocking socket?
If the socket sockfd
is closed or nothing to be read, does the 开发者_如何学Crecv()
block? (note: the flag in recv ()
is 0
).
If the socket is marked non blocking, recv will never block. period.
If the socket is fine but there is no data to be read you will get -1 as return value and errno will be set to EAGAIN.
If there is an error (closed socket etc.), you still get a -1 return value but errno will be set to the appropriate value.
If there is nothing to read it will block, if the socket is closed it will return with an error.
See the recv man page.
精彩评论