X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=common%2Fdevices%2Fdevice.c;fp=common%2Fdevices%2Fdevice.c;h=a912a74d325bd48aadff88bea659cd57dc866044;hp=826eee40bbd090b8134f029a7fc3276bd03dc370;hb=47dd33ef5e67856eb012b82b7b16d44bd05166c8;hpb=07e8833740d5c2268df6000ef3856bb05bf0dc67 diff --git a/common/devices/device.c b/common/devices/device.c index 826eee4..a912a74 100644 --- a/common/devices/device.c +++ b/common/devices/device.c @@ -192,6 +192,9 @@ struct timeval target,timeout; target.tv_sec +=usecs/1000000 + (target.tv_usec/1000000); target.tv_usec%=1000000; + target.tv_usec+=1000000; + target.tv_sec --; + for (;;) FD_ZERO(&readfds); if (device_portfd>=0) @@ -202,13 +205,13 @@ struct timeval target,timeout; if (target.tv_sec < timeout.tv_sec) return; timeout.tv_sec =target.tv_sec - timeout.tv_sec; - if (target.tv_usec < timeout.tv_usec) { - target.tv_usec+=1000000; - if (target.tv_sec <= 0) - return; - target.tv_sec--; - } timeout.tv_usec=target.tv_usec - timeout.tv_usec; + if (timeout.tv_usec>=1000000) { + timeout.tv_usec-=1000000; + if (!timeout.tv_sec) + return; + timeout.tv_sec--; + } err=select((device_portfd<0 ? 0 : device_portfd+1),&readfds,NULL,NULL,&timeout); if ( err > 0 ) {