linux recv()函数标志参数?

发布于 2024-11-13 06:05:14 字数 191 浏览 4 评论 0原文

如果我在非阻塞套接字上使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看透却不说透 2024-11-20 06:05:14

如果套接字被标记为非阻塞,则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.

那些过往 2024-11-20 06:05:14

如果没有任何内容可读取,它将阻塞,如果套接字关闭,它将返回错误。

请参阅 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文