码迷,mamicode.com
首页 > 其他好文 > 详细

epoll

时间:2015-12-06 17:27:52      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

epoll

epoll - I/O event notification facility

epoll is a variant of poll(2) that can be used either as an edge-triggered or a level-triggered interface and scales well to large numbers of watched file descriptors.

  • epoll_create

#include <sys/epoll.h>

int epoll_create(int size);

size不用,0即可。

int epoll_create1(int flags);

  • epoll_ctl

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

op: EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD;

typedef union epoll_data{

void *ptr;

int fd;

uint32_t u32;

uint64_t u64;

}epoll_data_t;

typedef epoll_event {

uint32_t events; /*Epoll events*/

epoll_data_t data;

};

events:EPOLLIN:可读;EPOLLOUT:可写;EPOLLET:边沿触发;EPOLLLT:水平触发(默认)。

The suggested way to use epoll as an edge-triggered (EPOLLET) interface is as follows:

          i   with nonblocking file descriptors; and

          ii  by waiting for an event only after  read(2) or write(2) return EAGAIN.

  • epoll_wait

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

int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, int timeout, const sigset_t *sigmask);

timeout: -1死等;0,不等;>0,有限等待时间。

成功:事件个数,失败-1。

epoll

标签:

原文地址:http://www.cnblogs.com/embedded-linux/p/5023862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!