]> git.pond.sub.org Git - empserver/blobdiff - src/lib/empthread/io.c
Base idle timeout on player->curup again, not current time
[empserver] / src / lib / empthread / io.c
index f73d89d5dd28db6c8d18e55c1852349321e9829c..b440a4f3e5cbfd0add227d018734f03bf561ee94 100644 (file)
@@ -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.