8229018: Switching to an infinite socket timeout on Windows leads to high CPU load
authormichaelm
Mon, 05 Aug 2019 10:40:36 +0100
changeset 57649 b2fde6701654
parent 57648 2b38409a336e
child 57650 8f067351c370
child 57675 830619e8936c
8229018: Switching to an infinite socket timeout on Windows leads to high CPU load Reviewed-by: michaelm Contributed-by: alan.bateman@oracle.com
src/java.base/windows/native/libnio/ch/Net.c
--- a/src/java.base/windows/native/libnio/ch/Net.c	Sat Aug 03 13:53:19 2019 +0530
+++ b/src/java.base/windows/native/libnio/ch/Net.c	Mon Aug 05 10:40:36 2019 +0100
@@ -623,9 +623,6 @@
     fd_set rd, wr, ex;
     jint fd = fdval(env, fdo);
 
-    t.tv_sec = (long)(timeout / 1000);
-    t.tv_usec = (timeout % 1000) * 1000;
-
     FD_ZERO(&rd);
     FD_ZERO(&wr);
     FD_ZERO(&ex);
@@ -638,7 +635,12 @@
     }
     FD_SET(fd, &ex);
 
-    rv = select(fd+1, &rd, &wr, &ex, &t);
+    if (timeout >= 0) {
+        t.tv_sec = (long)(timeout / 1000);
+        t.tv_usec = (timeout % 1000) * 1000;
+    }
+
+    rv = select(fd+1, &rd, &wr, &ex, (timeout >= 0) ? &t : NULL);
 
     /* save last winsock error */
     if (rv == SOCKET_ERROR) {