diff --git a/src/share/classes/sun/nio/ch/NativeThreadSet.java b/src/share/classes/sun/nio/ch/NativeThreadSet.java index 51eabbcaf231b7fdf82a1b3f8b2cf82cbbd72644..8c976ce0667d9100bf23a6ba7d400ecc9f650abf 100644 --- a/src/share/classes/sun/nio/ch/NativeThreadSet.java +++ b/src/share/classes/sun/nio/ch/NativeThreadSet.java @@ -44,8 +44,9 @@ class NativeThreadSet { // int add() { long th = NativeThread.current(); - if (th == -1) - return -1; + // 0 and -1 are treated as placeholders, not real thread handles + if (th == 0) + th = -1; synchronized (this) { int start = 0; if (used >= elts.length) { @@ -71,8 +72,6 @@ class NativeThreadSet { // Removes the thread at the given index. // void remove(int i) { - if (i < 0) - return; synchronized (this) { elts[i] = 0; used--; @@ -91,7 +90,8 @@ class NativeThreadSet { long th = elts[i]; if (th == 0) continue; - NativeThread.signal(th); + if (th != -1) + NativeThread.signal(th); if (--u == 0) break; } diff --git a/src/windows/classes/sun/nio/ch/NativeThread.java b/src/windows/classes/sun/nio/ch/NativeThread.java index 2138ad5239c24553bf9c96785995d1659a62ab8a..39a9fc6b90274915b66dceac30f469bf44a2513d 100644 --- a/src/windows/classes/sun/nio/ch/NativeThread.java +++ b/src/windows/classes/sun/nio/ch/NativeThread.java @@ -31,7 +31,11 @@ package sun.nio.ch; class NativeThread { - static long current() { return -1; } + static long current() { + // return 0 to ensure that async close of blocking sockets will close + // the underlying socket. + return 0; + } static void signal(long nt) { } diff --git a/src/windows/classes/sun/nio/ch/SocketDispatcher.java b/src/windows/classes/sun/nio/ch/SocketDispatcher.java index acbab4cfb3cfb9214be82fb69028e994aec06037..faf99215cdc2b4512129b478c1badc6d4990edff 100644 --- a/src/windows/classes/sun/nio/ch/SocketDispatcher.java +++ b/src/windows/classes/sun/nio/ch/SocketDispatcher.java @@ -55,10 +55,11 @@ class SocketDispatcher extends NativeDispatcher return writev0(fd, address, len); } - void close(FileDescriptor fd) throws IOException { + void preClose(FileDescriptor fd) throws IOException { + preClose0(fd); } - void preClose(FileDescriptor fd) throws IOException { + void close(FileDescriptor fd) throws IOException { close0(fd); } @@ -75,5 +76,7 @@ class SocketDispatcher extends NativeDispatcher static native long writev0(FileDescriptor fd, long address, int len) throws IOException; + static native void preClose0(FileDescriptor fd) throws IOException; + static native void close0(FileDescriptor fd) throws IOException; } diff --git a/src/windows/native/sun/nio/ch/SocketDispatcher.c b/src/windows/native/sun/nio/ch/SocketDispatcher.c index 2a0ba288e15f2b17364a753186b746b59ef12da5..4dc8259dfc44a7dc9ec5ea25cd8997ccc7834028 100644 --- a/src/windows/native/sun/nio/ch/SocketDispatcher.c +++ b/src/windows/native/sun/nio/ch/SocketDispatcher.c @@ -238,23 +238,25 @@ Java_sun_nio_ch_SocketDispatcher_writev0(JNIEnv *env, jclass clazz, } JNIEXPORT void JNICALL -Java_sun_nio_ch_SocketDispatcher_close0(JNIEnv *env, jclass clazz, - jobject fdo) +Java_sun_nio_ch_SocketDispatcher_preClose0(JNIEnv *env, jclass clazz, + jobject fdo) { jint fd = fdval(env, fdo); struct linger l; int len = sizeof(l); - - if (fd != -1) { - int result = 0; - if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) { - if (l.l_onoff == 0) { - WSASendDisconnect(fd, NULL); - } - } - result = closesocket(fd); - if (result == SOCKET_ERROR) { - JNU_ThrowIOExceptionWithLastError(env, "Socket close failed"); + if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) { + if (l.l_onoff == 0) { + WSASendDisconnect(fd, NULL); } } } + +JNIEXPORT void JNICALL +Java_sun_nio_ch_SocketDispatcher_close0(JNIEnv *env, jclass clazz, + jobject fdo) +{ + jint fd = fdval(env, fdo); + if (closesocket(fd) == SOCKET_ERROR) { + JNU_ThrowIOExceptionWithLastError(env, "Socket close failed"); + } +}