fixes bug 226022 "overflow error in PR_Poll means timeout < 1 second returns too quickly" patch=brofield@jellycan.com r=wtc,darin NSPRPUB_PRE_4_2_CLIENT_BRANCH
authordarin%meer.net
Tue, 18 Nov 2003 06:14:57 +0000
branchNSPRPUB_PRE_4_2_CLIENT_BRANCH
changeset 2972 cb0548eb51be8c082307bcef10615bc3c88c1273
parent 2970 d9cee2331294a3f506e435879fe17c278a932453
child 2974 4ff42520294774cd287925cdd125d4a08da4e690
push idunknown
push userunknown
push dateunknown
reviewerswtc, darin
bugs226022
fixes bug 226022 "overflow error in PR_Poll means timeout < 1 second returns too quickly" patch=brofield@jellycan.com r=wtc,darin
pr/src/md/beos/bfile.c
pr/src/md/os2/os2poll.c
pr/src/md/unix/uxpoll.c
pr/src/md/windows/w32poll.c
--- a/pr/src/md/beos/bfile.c
+++ b/pr/src/md/beos/bfile.c
@@ -684,18 +684,17 @@ PRInt32
 	remaining = timeout;
 	start = PR_IntervalNow(); 
 
  retry:
 	if (timeout != PR_INTERVAL_NO_TIMEOUT)
 	{
 		PRInt32 ticksPerSecond = PR_TicksPerSecond();
 		tv.tv_sec = remaining / ticksPerSecond;
-		tv.tv_usec = remaining - (ticksPerSecond * tv.tv_sec);
-		tv.tv_usec = (PR_USEC_PER_SEC * tv.tv_usec) / ticksPerSecond;
+		tv.tv_usec = PR_IntervalToMicroseconds( remaining % ticksPerSecond );
 		tvp = &tv;
 	}
 	
 	ready = _MD_SELECT(maxfd + 1, &rd, &wt, &ex, tvp);
 	
 	if (ready == -1 && errno == EINTR)
 	{
 		if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry;
--- a/pr/src/md/os2/os2poll.c
+++ b/pr/src/md/os2/os2poll.c
@@ -232,18 +232,17 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, 
     start = PR_IntervalNow();
 
 retry:
 #ifdef BSD_SELECT
     if (timeout != PR_INTERVAL_NO_TIMEOUT)
     {
         PRInt32 ticksPerSecond = PR_TicksPerSecond();
         tv.tv_sec = remaining / ticksPerSecond;
-        tv.tv_usec = remaining - (ticksPerSecond * tv.tv_sec);
-        tv.tv_usec = (PR_USEC_PER_SEC * tv.tv_usec) / ticksPerSecond;
+        tv.tv_usec = PR_IntervalToMicroseconds( remaining % ticksPerSecond );
         tvp = &tv;
     }
 
     ready = bsdselect(maxfd + 1, &rd, &wt, &ex, tvp);
 #else
     switch (timeout)
     {
         case PR_INTERVAL_NO_WAIT:
--- a/pr/src/md/unix/uxpoll.c
+++ b/pr/src/md/unix/uxpoll.c
@@ -397,18 +397,17 @@ static PRInt32 NativeThreadSelect(
     remaining = timeout;
     start = PR_IntervalNow();
 
 retry:
     if (timeout != PR_INTERVAL_NO_TIMEOUT)
     {
         PRInt32 ticksPerSecond = PR_TicksPerSecond();
         tv.tv_sec = remaining / ticksPerSecond;
-        tv.tv_usec = remaining - (ticksPerSecond * tv.tv_sec);
-        tv.tv_usec = (PR_USEC_PER_SEC * tv.tv_usec) / ticksPerSecond;
+        tv.tv_usec = PR_IntervalToMicroseconds( remaining % ticksPerSecond );
         tvp = &tv;
     }
 
     ready = _MD_SELECT(maxfd + 1, &rd, &wt, &ex, tvp);
 
     if (ready == -1 && errno == EINTR)
     {
         if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry;
--- a/pr/src/md/windows/w32poll.c
+++ b/pr/src/md/windows/w32poll.c
@@ -257,18 +257,17 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, 
         PR_Sleep(timeout);
         return 0;
     }
 
     if (timeout != PR_INTERVAL_NO_TIMEOUT)
     {
         PRInt32 ticksPerSecond = PR_TicksPerSecond();
         tv.tv_sec = timeout / ticksPerSecond;
-        tv.tv_usec = timeout - (ticksPerSecond * tv.tv_sec);
-        tv.tv_usec = (PR_USEC_PER_SEC * tv.tv_usec) / ticksPerSecond;
+        tv.tv_usec = PR_IntervalToMicroseconds( timeout % ticksPerSecond );
         tvp = &tv;
     }
 
 #if defined(_PR_GLOBAL_THREADS_ONLY)
     ready = _MD_SELECT(0, rdp, wtp, exp, tvp);
 #else
     ready = _PR_NTFiberSafeSelect(0, rdp, wtp, exp, tvp);
 #endif