libowfat/io/io_timeouted.c
leitner 51202765fe the #define extern hack in io_fd.c also included time.h, fix that
catch case in timeout loop where we have something to report on an fd;
in that case do not report a timeout but let the other event get through
first.
2009-04-25 19:09:27 +00:00

26 lines
738 B
C

#include "io_internal.h"
int64 io_timeouted() {
tai6464 now;
static long ptr;
io_entry* e;
long alen=array_length(&io_fds,sizeof(io_entry));
taia_now(&now);
++ptr;
if (ptr>=alen) ptr=0;
e=array_get(&io_fds,sizeof(io_entry),ptr);
if (!e) return -1;
for (;ptr<alen; ++ptr,++e) {
if (e->inuse && e->timeout.sec.x && taia_less(&e->timeout,&now)) {
/* we have a timeout */
if ((e->canread&&e->wantread) || (e->canwrite&&e->wantwrite))
continue; /* don't count it if we can signal something else */
return ptr;
}
}
ptr=-1; /* this is for really pathological cases, where more
connections come in all the time and so the timeout
handling does not trigger initially */
return -1;
}