Created
November 14, 2009 07:03
-
-
Save oza/234422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/epoll.h> | |
void start_epoll(int fd) | |
{ | |
int efd,ret; | |
struct epoll_event ev,events; | |
int buf; | |
efd = epoll_create(1); | |
ev.events = EPOLLIN | EPOLLET ; | |
ev.data.fd = fd; | |
epoll_ctl(efd,EPOLL_CTL_ADD,fd,&ev); | |
printf("start to epoll wait...\n"); | |
while(1){ | |
ret = epoll_wait(efd, &events, 1, -1); | |
/* events is overwritten by epoll_wait, and have ev.data.fd */ | |
read(events.data.fd, &buf, sizeof(int)); | |
printf("[%s] ret %d cnt %d \n",__FUNCTION__,ret,buf); | |
} | |
} | |
main() | |
{ | |
int fd[2]; | |
int cnt = 0; | |
pipe(fd); | |
if ( fork() == 0 ){ | |
int rfd = fd[0]; | |
start_epoll(rfd); | |
} | |
while(1){ | |
sleep(1); | |
write(fd[1],&cnt,sizeof(int)); | |
cnt++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment