iopause.c (736B)
1 /* Public domain. */ 2 3 #include "taia.h" 4 #include <sys/select.h> 5 #include <poll.h> 6 7 #include "iopause.h" 8 9 void iopause(struct pollfd *x,unsigned int len,struct taia *deadline,struct taia *stamp) 10 { 11 struct taia t; 12 int millisecs; 13 double d; 14 int i; 15 16 if (taia_less(deadline,stamp)) 17 millisecs = 0; 18 else { 19 t = *stamp; 20 taia_sub(&t,deadline,&t); 21 d = taia_approx(&t); 22 if (d > 1000.0) d = 1000.0; 23 millisecs = (int)( d * 1000.0 + 20.0 ); 24 } 25 26 for (i = 0;i < len;++i) 27 x[i].revents = 0; 28 29 poll(x,len,millisecs); 30 /* XXX: some kernels apparently need x[0] even if len is 0 */ 31 /* XXX: how to handle EAGAIN? are kernels really this dumb? */ 32 /* XXX: how to handle EINVAL? when exactly can this happen? */ 33 34 }