diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index 7d0d828423..a7046f8957 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -152,6 +152,17 @@ init(JNIEnv* e, sockaddr_in* address, jstring hostString, jint port) } } +inline bool +einProgress(int error) +{ +#ifdef PLATFORM_WINDOWS + return error == WSAEINPROGRESS + or error == WSAEWOULDBLOCK; +#else + return error == EINPROGRESS; +#endif +} + inline bool einProgress() { @@ -381,7 +392,11 @@ Java_java_nio_channels_SocketChannel_natFinishConnect(JNIEnv *e, socklen_t size = sizeof(int); int r = getsockopt(socket, SOL_SOCKET, SO_ERROR, reinterpret_cast(&error), &size); - if (r != 0 or size != sizeof(int) or error != 0) { + if (r != 0 or size != sizeof(int)) { + throwIOException(e); + } else if (einProgress(error)) { + return false; + } else if (error != 0) { throwIOException(e); } return true;