Skip to content

Commit d5ceec6

Browse files
AlanBatemanMichael-Mc-Mahon
authored andcommitted
8229018: Switching to an infinite socket timeout on Windows leads to high CPU load
Reviewed-by: michaelm
1 parent 2f16ca0 commit d5ceec6

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

  • src/java.base/windows/native/libnio/ch

src/java.base/windows/native/libnio/ch/Net.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,6 @@ Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlo
623623
fd_set rd, wr, ex;
624624
jint fd = fdval(env, fdo);
625625

626-
t.tv_sec = (long)(timeout / 1000);
627-
t.tv_usec = (timeout % 1000) * 1000;
628-
629626
FD_ZERO(&rd);
630627
FD_ZERO(&wr);
631628
FD_ZERO(&ex);
@@ -638,7 +635,12 @@ Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlo
638635
}
639636
FD_SET(fd, &ex);
640637

641-
rv = select(fd+1, &rd, &wr, &ex, &t);
638+
if (timeout >= 0) {
639+
t.tv_sec = (long)(timeout / 1000);
640+
t.tv_usec = (timeout % 1000) * 1000;
641+
}
642+
643+
rv = select(fd+1, &rd, &wr, &ex, (timeout >= 0) ? &t : NULL);
642644

643645
/* save last winsock error */
644646
if (rv == SOCKET_ERROR) {

0 commit comments

Comments
 (0)