From 1b893c7a19cdb411e704b43ea6326967552557ba Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 12 Oct 2009 09:28:04 -0600 Subject: [PATCH] check for EINPROGRESS in Java_java_nio_channels_SocketChannel_natFinishConnect --- classpath/java-nio.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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;