linux recv()函数标志参数?
如果我在非阻塞套接字上使用 recv(sockfd, buffer, len, 0);
会发生什么?
如果套接字 sockfd
已关闭或没有任何内容可读取,则 recv()
是否会阻塞? (注:recv()
中的标志是0
)。
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 recv()
block? (note: the flag in recv ()
is 0
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果套接字被标记为非阻塞,则recv将永远不会阻塞。时期。
如果套接字正常但没有数据可读取,您将得到 -1 作为返回值,并且 errno 将设置为 EAGAIN。
如果出现错误(关闭套接字等),您仍然会得到 -1 返回值,但 errno 将被设置为适当的值。
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.
如果没有任何内容可读取,它将阻塞,如果套接字关闭,它将返回错误。
请参阅 recv 手册页。
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.