X-Git-Url: http://git.pond.sub.org/?p=empserver;a=blobdiff_plain;f=src%2Flib%2Fempthread%2Fio.c;h=b440a4f3e5cbfd0add227d018734f03bf561ee94;hp=f73d89d5dd28db6c8d18e55c1852349321e9829c;hb=ed1cbc97e66405d9bf7639f56fe4f2f98a2961c0;hpb=a96b400da338861e6baa8ef6025b15ff46e924e0 diff --git a/src/lib/empthread/io.c b/src/lib/empthread/io.c index f73d89d5d..b440a4f3e 100644 --- a/src/lib/empthread/io.c +++ b/src/lib/empthread/io.c @@ -124,6 +124,24 @@ io_close(struct iop *iop, struct timeval *timeout) free(iop); } +void +io_timeout(struct timeval *timeout, time_t deadline) +{ + struct timeval now; + + gettimeofday(&now, NULL); + if (now.tv_sec >= deadline) { + /* deadline reached already */ + timeout->tv_sec = 0; + timeout->tv_usec = 0; + } else { + /* deadline in future */ + timeout->tv_sec = deadline - now.tv_sec - 1; + timeout->tv_usec = 999999 - now.tv_usec; + /* yes, this is 1usec early; sue me */ + } +} + /* * Read input from IOP and enqueue it. * If TIMEOUT is non-null, wait at most that long for input to arrive.