Skip to content

Instantly share code, notes, and snippets.

@oza
Created November 14, 2009 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oza/234422 to your computer and use it in GitHub Desktop.
Save oza/234422 to your computer and use it in GitHub Desktop.
#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