高性能大并发服务器 3

epoll

poll模型每次调用poll函数都需要把监听套接字与已连接套接字所感兴趣的事件数组 拷贝到内核(效率低)

函数原型:

#include <sys/epoll.h>

int epoll_creat(int size);

int epoll_create1(int flags);

int epoll_ctl(int epfd, int op ,int fd, struct epoll_event *event);

int epoll_wait(int epfd, struct epoll_event *event,int  maxevents,int timeout);

typedef uoin epoll_data

{

  void *ptr;

  int fd;

     uint32_t  u32;

  uint64_t  u64;

}epoll_data_t;

 

struct epoll_event

{

uint32_t events;

epoll_data_t data;

}

两种触发模型;

1. LT (遍历活跃套接字)     2.ET

 

posted @ 2021-08-07 17:02  白米a  阅读(30)  评论(0)    收藏  举报