开发者

linux recv() function flag parameter?

开发者 https://www.devze.com 2023-03-10 02:17 出处:网络
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 ()

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号