Linux TCP 阻塞套接字使用 EAGAIN 返回零
我有一个阻塞 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这意味着对等方已正常关闭其连接端。您需要关闭该连接的套接字描述符。不要费心检查
errno
,在这种情况下它是没有意义的。仅当read()
返回时它才有意义。 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 ifread()
had returned< 0
instead.