diff --git a/jdk/src/solaris/native/sun/nio/ch/SctpNet.c b/jdk/src/solaris/native/sun/nio/ch/SctpNet.c index f58157f1fae..61d7764d23e 100644 --- a/jdk/src/solaris/native/sun/nio/ch/SctpNet.c +++ b/jdk/src/solaris/native/sun/nio/ch/SctpNet.c @@ -110,6 +110,38 @@ jboolean loadSocketExtensionFuncs return JNI_TRUE; } +jint +handleSocketError(JNIEnv *env, jint errorValue) +{ + char *xn; + switch (errorValue) { + case EINPROGRESS: /* Non-blocking connect */ + return 0; + case EPROTO: + xn= JNU_JAVANETPKG "ProtocolException"; + break; + case ECONNREFUSED: + xn = JNU_JAVANETPKG "ConnectException"; + break; + case ETIMEDOUT: + xn = JNU_JAVANETPKG "ConnectException"; + break; + case EHOSTUNREACH: + xn = JNU_JAVANETPKG "NoRouteToHostException"; + break; + case EADDRINUSE: /* Fall through */ + case EADDRNOTAVAIL: + xn = JNU_JAVANETPKG "BindException"; + break; + default: + xn = JNU_JAVANETPKG "SocketException"; + break; + } + errno = errorValue; + JNU_ThrowByNameWithLastError(env, xn, "NioSocketError"); + return IOS_THROWN; +} + /* * Class: sun_nio_ch_SctpNet * Method: init diff --git a/jdk/test/com/sun/nio/sctp/SctpChannel/Connect.java b/jdk/test/com/sun/nio/sctp/SctpChannel/Connect.java index 78cb52770ba..33f4441d356 100644 --- a/jdk/test/com/sun/nio/sctp/SctpChannel/Connect.java +++ b/jdk/test/com/sun/nio/sctp/SctpChannel/Connect.java @@ -192,6 +192,18 @@ public class Connect { testCCE(new Callable() { public Void call() throws IOException { cceChannel.finishConnect(); return null; } }); + + /* TEST 8: IOException: Connection refused. Exercises handleSocketError. + * Assumption: no sctp socket listening on 3456 */ + SocketAddress addr = new InetSocketAddress("localhost", 3456); + channel = SctpChannel.open(); + try { + channel.connect(addr); + fail("should have thrown ConnectException: Connection refused"); + } catch (IOException ioe) { + pass(); + } + } catch (IOException ioe) { unexpected(ioe); } finally {