标签:
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.
#include <sys/epoll.h>
int epoll_create(int size);
size不用,0即可。
int epoll_create1(int flags);
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.
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。
标签:
原文地址:http://www.cnblogs.com/embedded-linux/p/5023862.html