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.
 
 
 
 

42 lines
970 B

  1. #define _GNU_SOURCE
  2. #include <sys/types.h>
  3. #include <sys/poll.h>
  4. #include <signal.h>
  5. #include <fcntl.h>
  6. #include <stdio.h>
  7. int main() {
  8. int signum=SIGRTMIN+1;
  9. sigset_t ss;
  10. sigemptyset(&ss);
  11. sigaddset(&ss,signum);
  12. sigaddset(&ss,SIGIO);
  13. sigprocmask(SIG_BLOCK,&ss,0);
  14. fcntl(0 /* fd */,F_SETOWN,getpid());
  15. fcntl(0 /* fd */,F_SETSIG,signum);
  16. #if defined(O_ONESIGFD) && defined(F_SETAUXFL)
  17. fcntl(0 /* fd */, F_SETAUXFL, O_ONESIGFD);
  18. #endif
  19. fcntl(0 /* fd */,F_SETFL,fcntl(0 /* fd */,F_GETFL)|O_NONBLOCK|O_ASYNC);
  20. {
  21. siginfo_t info;
  22. struct timespec timeout;
  23. int r;
  24. timeout.tv_sec=1; timeout.tv_nsec=0;
  25. switch ((r=sigtimedwait(&ss,&info,&timeout))) {
  26. case SIGIO:
  27. /* signal queue overflow */
  28. signal(signum,SIG_DFL);
  29. /* do poll */
  30. break;
  31. default:
  32. if (r==signum) {
  33. printf("event %c%c on fd #%d\n",info.si_band&POLLIN?'r':'-',info.si_band&POLLOUT?'w':'-',info.si_fd);
  34. }
  35. }
  36. }
  37. return 0;
  38. }