After looking around the net I came across a presentation, which had a bit of information on it and what appears to be a code example. But I can not make heads nor tails of it.
Snippet 1:
Code:
int sigio_add_fd(int fd) {
static const int signum=SIGRTMIN+1;
static pid_t mypid=0;
if (!mypid) mypid=getpid();
fcntl(fd,F_SETOWN,mypid);
fcntl(fd,F_SETSIG,signum);
fcntl(fd,F_SETFL,fcntl(fd,F_GETFL)|O_NONBLOCK|O_ASYNC);
}
int sigio_rm_fd(struct sigio* s,int fd) {
fcntl(fd,F_SETFL,fcntl(fd,F_GETFL)&(~O_ASYNC));
}
Snippet 2:
Code:
for (;;) {
timeout.tv_sec=0;
timeout.tv_nsec=10000;
switch (r=sigtimedwait(&s.ss,&info,&timeout)) {
case -1: if (errno!=EAGAIN) error("sigtimedwait");
case SIGIO: puts("SIGIO queue overflow!"); return 1;
}
if (r==signum) handle_io(info.si_fd,info.si_band);
}
I get the first part, about declaring interest, but have very little idea what is going on in the second bit. I believe that the call to sigtimedwait is getting it to wait for a signal.