diff --git a/io/iom_wait.c b/io/iom_wait.c index 4d548d3..5647f34 100644 --- a/io/iom_wait.c +++ b/io/iom_wait.c @@ -3,10 +3,10 @@ #ifdef HAVE_EPOLL #include #endif +#include #ifdef HAVE_KQUEUE #include #include -#include #endif #include #ifdef __dietlibc__ @@ -171,8 +171,16 @@ int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout) { } else { /* somebody else has the job to fill the queue */ struct timespec ts; - ts.tv_sec = timeout / 1000; - ts.tv_nsec = (timeout % 1000) * 1000000; + struct timeval tv; + gettimeofday(&tv, NULL); + tv.tv_sec += timeout/1000; + tv.tv_usec += timeout%1000; + if (tv.tv_usec>1000) { + tv.tv_usec-=1000; + ++tv.tv_sec; + } + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_usec * 1000; #ifdef __dietlibc__ r=cnd_timedwait(&c->sem,&c->mtx,&ts); #elif defined(__APPLE__)