Chinaunix首页 | 论坛 | 博客
  • 博客访问: 35855
  • 博文数量: 18
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 117
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-23 14:39
文章分类

全部博文(18)

文章存档

2013年(18)

我的朋友

分类: LINUX

2013-05-20 16:01:38

名词解释:man epoll之后,得到如下结果: 

NAME 
       epoll - I/O event notification facility 

SYNOPSIS 
       #include  

DEscrīptION 
       epoll is a variant of poll(2) that can be used either as Edge or Level 
       Triggered interface and scales well to large numbers of watched fds. 
       Three system calls are provided to set up and control an epoll set: 
       epoll_create(2), epoll_ctl(2), epoll_wait(2). 

       An epoll set is connected to a file descrīptor created by epoll_create(2).   Interest for certain file descrīptors is then registered via 
       epoll_ctl(2). Finally, the actual wait is started by epoll_wait(2). 

其实,一切的解释都是多余的,按照我目前的了解,EPOLL模型似乎只有一种格式,所以大家只要参考我下面的代码,就能够对EPOLL有所了解了,代码的解释都已经在注释中: 
[cpp]
  1. while (TRUE)   
  2. {   
  3. //等待EPOLL事件的发生,相当于监听,至于相关的端口,需要在初始化EPOLL的时候绑定。   
  4. int nfds = epoll_wait (m_epoll_fd, m_events, MAX_EVENTS, EPOLL_TIME_OUT);   
  5. if (nfds <= 0)   
  6.    continue;   
  7. m_bOnTimeChecking = FALSE;   
  8. G_CurTime = time(NULL);   
  9. for (int i=0; i
  10. {   
  11.    try   
  12.    {   
  13. //如果新监测到一个HTTP用户连接到绑定的HTTP端口,建立新的连接。由于我们新采用了SOCKET连接,所以基本没用   
  14.     if (m_events[i].data.fd == m_listen_http_fd)。   
  15.     {   
  16.      OnAcceptHttpEpoll ();   
  17.     }   
  18.     else if (m_events[i].data.fd == m_listen_sock_fd)//如果新监测到一个SOCKET用户连接到了绑定的SOCKET端口,建立新的连接。    
  19.     {   
  20.      OnAcceptSockEpoll ();   
  21.     }   
  22.     else if (m_events[i].events & EPOLLIN)//如果是已经连接的用户,并且收到数据,那么进行读入。    
  23.     {   
  24.      OnReadEpoll (i);   
  25.     }   
  26.   
  27.     OnWriteEpoll (i);//查看当前的活动连接是否有需要写出的数据。    
  28.    }   
  29.    catch (int)   
  30.    {   
  31.     PRINTF ("CATCH捕获错误\n");   
  32.     continue;   
  33.    }   
  34. }   
  35. m_bOnTimeChecking = TRUE;   
  36. OnTimer ();//进行一些定时的操作,主要就是删除一些断线用户等。    
  37. }   
阅读(869) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~