測試的實例:
int fd = open("a.txt", 'r');
epoll_event ev;
int efd = epoll_create(1);
ev.events = EPOLLIN | EPOLLOUT;
ev.data.fd = fd;
epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
epoll_event evs[3];
int r = epoll_wait(efd, evs, 1, 0);
if(r == -1) {
std::cout << "error" << std::endl;
}
for(int i =0; i < 1; ++i) {
std::cout << " >>>"<< evs[i].data.fd << std::endl;
std::cout << "===" << evs[i].events << std::endl;
char buff[300];
read(fd, buff, 12);
std::cout << buff<< std::endl;
}
epoll_ctl(efd, EPOLL_CTL_MOD, fd, &ev);
int m = epoll_wait(efd, evs, 1, 0);
if(m == -1) {
std::cout << "error" << std::endl;
}
for(int i =0; i < 1; ++i) {
std::cout << " >>>"<< evs[i].data.fd << std::endl;
std::cout << "===" << evs[i].events << std::endl;
}
close(sfd);