Linux TCP 阻塞套接字使用 EAGAIN 返回零

发布于 2025-01-12 01:56:08 字数 303 浏览 2 评论 0原文

我有一个阻塞 TCP 套接字,作为用 C++ 实现的 TCP 客户端的一部分。它尝试使用套接字描述符上的 ::read() 调用来读取数据。我经常看到这样的情况,读取返回的值为 0,但 errno 的值为 EAGAIN。

在阻塞套接字的情况下,EAGAIN 意味着什么?

我了解非阻塞套接字的功能,但不清楚阻塞套接字的情况。

我知道这可能是因为遇到读取超时,但我目前没有设置读取超时值。

Linux TCP 套接字的默认读取超时值是多少?

I have a blocking TCP socket as a part of a TCP client implemented in C++. It is trying to read data using a ::read() call on the socket descriptor. I am seeing very frequent cases, where the read returns with a value of 0, but the value of errno is EAGAIN.

What is EAGAIN supposed to mean in case of blocking sockets?

I understand the functioning in case of a non-blocking socket, but unclear about a blocking socket.

I understand it might be because of hitting a read timeout, but I am currently not setting a read timeout value.

What is the default read timeout value in case of linux TCP sockets?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

嘴硬脾气大 2025-01-19 01:56:08

读取返回值为 0

这意味着对等方已正常关闭其连接端。您需要关闭该连接的套接字描述符。不要费心检查errno,在这种情况下它是没有意义的。仅当 read() 返回 时它才有意义。 0 代替。

where the read returns with a value of 0

This means the peer has gracefully closed its end of the connection. You need to close your socket descriptor for that connection. Don't bother checking errno, it is meaningless in this condition. It only has meaning if read() had returned < 0 instead.

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