Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
747 B

  1. #include <sys/types.h>
  2. #include <sys/event.h>
  3. #include <sys/time.h>
  4. int main() {
  5. int kq=kqueue();
  6. struct kevent kev;
  7. struct timespec ts;
  8. if (kq==-1) return 111;
  9. EV_SET(&kev, 0 /* fd */, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
  10. ts.tv_sec=0; ts.tv_nsec=0;
  11. if (kevent(kq,&kev,1,0,0,&ts)==-1) return 111;
  12. {
  13. struct kevent events[100];
  14. int i,n;
  15. ts.tv_sec=1; ts.tv_nsec=0;
  16. switch (n=kevent(kq,0,0,events,100,&ts)) {
  17. case -1: return 111;
  18. case 0: puts("no data on fd #0"); break;
  19. }
  20. for (i=0; i<n; ++i) {
  21. printf("ident %d, filter %d, flags %d, fflags %d, data %d\n",
  22. events[i].ident,events[i].filter,events[i].flags,
  23. events[i].fflags,events[i].data);
  24. }
  25. }
  26. return 0;
  27. }