epoll EPOLLET模式的疑问?

yuyunliuhen 2014-06-26 05:32:00
Level-Triggered and Edge-Triggered
The epoll event distribution interface is able to behave both as edge-triggered (ET) and as level-triggered (LT). The difference between the two mechanisms can be described
as follows. Suppose that this scenario happens:

1. The file descriptor that represents the read side of a pipe (rfd) is registered on the epoll instance.

2. A pipe writer writes 2 kB of data on the write side of the pipe.

3. A call to epoll_wait(2) is done that will return rfd as a ready file descriptor.

4. The pipe reader reads 1 kB of data from rfd.

5. A call to epoll_wait(2) is done.

If the rfd file descriptor has been added to the epoll interface using the EPOLLET (edge-triggered) flag, the call to epoll_wait(2) done in step 5 will probably hang despite the available data still present in the file input buffer; meanwhile the remote peer might be expecting a response based on the data it already sent. The reason for this is that edge-triggered mode only delivers events when changes occur on the monitored file descriptor. So, in step 5 the caller might end up waiting for some data that is already present inside the input buffer. In the above example, an event on rfd will be generated because of the write done in 2 and the event is consumed in 3. Since the read operation done in 4 does not consume the whole buffer data, the call to epoll_wait(2) done in step 5 might block indefinitely.

最后一句 :
Since the read operation done in 4 does not consume the whole buffer data, the call to epoll_wait(2) done in step 5 might block indefinitely.(2) done in step 5 might block indefinitely.
是不是如果上一次数据没有接收完全,即便是客户端再次发送数据,epoll_wait也一直是 阻塞的,不会触发!?
...全文
133 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuyunliuhen 2014-06-26
  • 打赏
  • 举报
回复
好吧,测试了下,客户端不断发送数据,每秒一次,1次100bytes左右,服务器每次只接收数据头大小的字节。

static const int __head_size = 12;
			unsigned long __usable_size = 0;
			int __packet_length = 0;
			int __log_level = 0;
			int __frame_number = 0;
			int __head = 0;
			unsigned int __guid = 0;
			unsigned char __packet_head[__head_size] = {};
			int __recv_size = 0;
			{
			  {
				_get_usable(__fd,__usable_size);
				printf("__usable_size1 = %ld\n",__usable_size);  
				{
					__recv_size = Event_Handle_Srv::read(__fd,(char*)&__packet_head,__head_size);
					printf("__recv_size = %d\n",__recv_size);  
					if(__head_size != __recv_size)
					{
						printf("error: __recv_size = %d",__recv_size);  
						return ;
					}
				}
			  }
			}
结果: hostname: localhost.localdomain address list: 127.0.0.1 on_connected __fd = 5 __usable_size1 = 178 __recv_size = 12 __usable_size1 = 230 __recv_size = 12 __usable_size1 = 340 __recv_size = 12 __usable_size1 = 419 __recv_size = 12 __usable_size1 = 483 __recv_size = 12 __usable_size1 = 543 __recv_size = 12 __usable_size1 = 595 __recv_size = 12 __usable_size1 = 655 __recv_size = 12 __usable_size1 = 760 __recv_size = 12 __usable_size1 = 825 __recv_size = 12 __usable_size1 = 877 __recv_size = 12 __usable_size1 = 929 __recv_size = 12 __usable_size1 = 1036 __recv_size = 12 __usable_size1 = 1122 __recv_size = 12 __usable_size1 = 1232 __recv_size = 12 __usable_size1 = 1322 __recv_size = 12 __usable_size1 = 1382 __recv_size = 12 __usable_size1 = 1442 __recv_size = 12 __usable_size1 = 1552 __recv_size = 12 __usable_size1 = 1627 __recv_size = 12 __usable_size1 = 1684 __recv_size = 12 __usable_size1 = 1774 __recv_size = 12 __usable_size1 = 1831 __recv_size = 12 __usable_size1 = 1895 __recv_size = 12 __usable_size1 = 1952 __recv_size = 12 __usable_size1 = 2004 __recv_size = 12 __usable_size1 = 2114 __recv_size = 12 __usable_size1 = 2204 __recv_size = 12 __usable_size1 = 2264 __recv_size = 12 __usable_size1 = 2430 __recv_size = 12 还是可以继续受到的,而且数据好像是没有丢的,累积到下一次了,所以,下次接收的时候,数据应该是完整的! 备注一下,不知道理解是不是有错!

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧