选择()的recv()和EWOULDBLOCK在非阻塞套接字 [英] select(), recv() and EWOULDBLOCK on non-blocking sockets

查看:648
本文介绍了选择()的recv()和EWOULDBLOCK在非阻塞套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果下面的场景是真实的吗?!


    非阻塞TCP套接字
  1. 选择()(RD)说,在插槽中安装

  2. 下面的recv()尽管调用将返回EWOULDBLOCK选择()


解决方案

我在一个流行的桌面操作系统意识到错误的,其中 O_NONBLOCK TCP套接字,尤其是那些运行在环回接口,可有时返回 EAGAIN 的recv()选择()报告插槽中安装的阅读。在我的情况,这种情况对方半关闭发送流之后。

有关详细信息,请参阅源$ C ​​$ C为 t_nx.ml 在我的OCaml的网络应用环境分布的NX库。 (链接

I would like to know if the following scenario is real?!

  1. select() (RD) on non-blocking TCP socket says that the socket is ready
  2. following recv() would return EWOULDBLOCK despite the call to select()

解决方案

I am aware of an error in a popular desktop operating where O_NONBLOCK TCP sockets, particularly those running over the loopback interface, can sometimes return EAGAIN from recv() after select() reports the socket is ready for reading. In my case, this happens after the other side half-closes the sending stream.

For more details, see the source code for t_nx.ml in the NX library of my OCaml Network Application Environment distribution. (link)

这篇关于选择()的recv()和EWOULDBLOCK在非阻塞套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆