libowfat/io/io_timeouted.c

26 lines
739 B
C
Raw Normal View History

2003-09-08 17:37:23 +00:00
#include "io_internal.h"
int64 io_timeouted() {
tai6464 now;
static size_t ptr;
2003-09-08 17:37:23 +00:00
io_entry* e;
size_t alen=iarray_length(&io_fds);
2003-09-08 17:37:23 +00:00
taia_now(&now);
++ptr;
2014-05-08 04:25:42 +00:00
if (ptr>alen) ptr=0;
e=iarray_get(&io_fds,ptr);
2014-05-08 04:25:42 +00:00
// if (!e) return -1;
for (;ptr<=alen; ++ptr,e=iarray_get(&io_fds,ptr)) {
if (e && 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 */
2003-09-08 17:37:23 +00:00
return ptr;
}
}
2007-01-26 14:16:14 +00:00
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 */
2003-09-08 17:37:23 +00:00
return -1;
}