Skip to content

Instantly share code, notes, and snippets.

@katlogic
Created September 18, 2016 00:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katlogic/82fa650b8d4196c26e18ca0ebefa77d6 to your computer and use it in GitHub Desktop.
Save katlogic/82fa650b8d4196c26e18ca0ebefa77d6 to your computer and use it in GitHub Desktop.
#include <sys/epoll.h>
#include <sys/socket.h>
#include <stdio.h>
int main()
{
struct epoll_event ev = {
.data.fd = 1
};
int efd = epoll_create(1);
ev.events = EPOLLIN|EPOLLET;
epoll_ctl(efd, EPOLL_CTL_ADD, 1, &ev);
while (1) {
struct epoll_event ee;
char buf[512];
epoll_wait(efd,&ee,1,-1);
int n = recv(1,buf,512,MSG_PEEK|MSG_DONTWAIT);
fprintf(stderr,"%d bytes pending\n", n);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment