免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
1234
最近访问板块 发新帖
楼主: converse
打印 上一主题 下一主题

[函数] epoll学习笔记 [复制链接]

论坛徽章:
0
31 [报告]
发表于 2008-06-03 15:09 |只看该作者

对十楼的质疑

“如果对应的缓冲区本身已经有了N字节的数据,而只取出了小于N字节的数据,那么残存的数据不会造成状态发生变化.”
我测了一下,上述情况epoll_wait下次仍会返回该sockfd的

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
32 [报告]
发表于 2008-06-03 18:35 |只看该作者
我也发现有问题..我在接收的地方sleep(10).结果epoll_wait 马上就又检测到可读事件. 倒致多个线程全都是去接收了..

论坛徽章:
1
寅虎
日期:2014-11-30 21:25:54
33 [报告]
发表于 2008-12-02 19:38 |只看该作者
原帖由 marxn 于 2008-5-22 21:42 发表


recv 返回值小于请求的长度时说明缓冲区已经没有可读数据. 但再读不一定会触发EAGAIN.有可能返回0表示TCP连接已被关闭。


这个没有必要的,没有数据就不用再读了,tcp断开的时候会触发EPOLLHUP事件

原帖由 UnixStudier 于 2008-5-23 09:40 发表
converse:"
1)对于监听可读事件时,如果是socket是监听socket,那么当有新的主动连接到来为状态发生变化;对一般的socket而言,协议栈中相应的缓冲区有新的数据为状态发生变化.但是,如果在一个时间同时接收了N个连 ...


在ET模式下 accetp应该一直运行到EAGAIN错误 这样就可以了

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:172015亚冠之水原三星
日期:2015-06-02 16:34:202015年亚冠纪念徽章
日期:2015-10-19 18:13:37程序设计版块每日发帖之星
日期:2015-11-08 06:20:00
34 [报告]
发表于 2008-12-02 22:09 |只看该作者
原帖由 vbs100 于 2008-12-2 19:38 发表
这个没有必要的,没有数据就不用再读了,tcp断开的时候会触发EPOLLHUP事件
在ET模式下 accetp应该一直运行到EAGAIN错误 这样就可以了


TCP断开大部分时候触发的是EPOLLIN吧,recv得0

论坛徽章:
1
寅虎
日期:2014-11-30 21:25:54
35 [报告]
发表于 2008-12-04 14:46 |只看该作者
Q9     Do I need to continuously read/write a file descriptor until EAGAIN when using the EPOLLET flag (edge-trig-
              gered behavior) ?

       A9     No  you  don't.   Receiving  an event from epoll_wait(2) should suggest to you that such file descriptor is
              ready for the requested I/O operation.  You have simply to consider it ready until  you  will  receive  the
              next  EAGAIN.   When  and how you will use such file descriptor is entirely up to you.  Also, the condition
              that the read/write I/O space is exhausted can be detected by checking the amount of data read from / writ-
              ten  to the target file descriptor.  For example, if you call read(2) by asking to read a certain amount of
              data and read(2) returns a lower number of bytes, you can be sure of having exhausted the  read  I/O  space
              for such file descriptor.  The same is true when writing using write(2).
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP