--- a/jdk/src/solaris/native/sun/nio/ch/SctpNet.c Mon Jan 18 14:01:07 2010 +0000
+++ b/jdk/src/solaris/native/sun/nio/ch/SctpNet.c Mon Jan 18 14:56:06 2010 +0000
@@ -110,6 +110,38 @@
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
--- a/jdk/test/com/sun/nio/sctp/SctpChannel/Connect.java Mon Jan 18 14:01:07 2010 +0000
+++ b/jdk/test/com/sun/nio/sctp/SctpChannel/Connect.java Mon Jan 18 14:56:06 2010 +0000
@@ -192,6 +192,18 @@
testCCE(new Callable<Void>() {
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 {