提交 0587dc28 编写于 作者: A alanb

4516760: (so) Intermittent SocketException: Transport endpoint is not connected (lnx)

Reviewed-by: sherman
上级 1da43f43
...@@ -541,7 +541,7 @@ Java_sun_nio_ch_Net_shutdown(JNIEnv *env, jclass cl, jobject fdo, jint jhow) ...@@ -541,7 +541,7 @@ Java_sun_nio_ch_Net_shutdown(JNIEnv *env, jclass cl, jobject fdo, jint jhow)
{ {
int how = (jhow == sun_nio_ch_Net_SHUT_RD) ? SHUT_RD : int how = (jhow == sun_nio_ch_Net_SHUT_RD) ? SHUT_RD :
(jhow == sun_nio_ch_Net_SHUT_WR) ? SHUT_WR : SHUT_RDWR; (jhow == sun_nio_ch_Net_SHUT_WR) ? SHUT_WR : SHUT_RDWR;
if (shutdown(fdval(env, fdo), how) < 0) if ((shutdown(fdval(env, fdo), how) < 0) && (errno != ENOTCONN))
handleSocketError(env, errno); handleSocketError(env, errno);
} }
......
/* /*
* Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2002-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -22,26 +22,65 @@ ...@@ -22,26 +22,65 @@
*/ */
/* @test /* @test
* @bug 4618960 * @bug 4618960 4516760
* @summary Test isInputShutdown * @summary Test shutdownXXX and isInputShutdown
* @library ..
*/ */
import java.io.IOException;
import java.net.*; import java.net.*;
import java.nio.*; import java.nio.ByteBuffer;
import java.nio.channels.*; import java.nio.channels.*;
public class Shutdown { public class Shutdown {
public static void main(String args[]) throws Exception { /**
InetSocketAddress sa = new InetSocketAddress( * Accept a connection, and close it immediately causing a hard reset.
InetAddress.getByName(TestUtil.HOST), 23); */
SocketChannel sc = SocketChannel.open(sa); static void acceptAndReset(ServerSocketChannel ssc) throws IOException {
boolean before = sc.socket().isInputShutdown(); SocketChannel peer = ssc.accept();
sc.socket().shutdownInput(); try {
boolean after = sc.socket().isInputShutdown(); peer.setOption(StandardSocketOption.SO_LINGER, 0);
sc.close(); peer.configureBlocking(false);
if (before || !after) peer.write(ByteBuffer.wrap(new byte[128*1024]));
throw new Exception("Test failed"); } finally {
peer.close();
}
}
public static void main(String[] args) throws Exception {
ServerSocketChannel ssc = ServerSocketChannel.open()
.bind(new InetSocketAddress(0));
try {
InetAddress lh = InetAddress.getLocalHost();
int port = ((InetSocketAddress)(ssc.getLocalAddress())).getPort();
SocketAddress remote = new InetSocketAddress(lh, port);
// Test SocketChannel shutdownXXX
SocketChannel sc;
sc = SocketChannel.open(remote);
try {
acceptAndReset(ssc);
sc.shutdownInput();
sc.shutdownOutput();
} finally {
sc.close();
}
// Test Socket adapter shutdownXXX and isShutdownInput
sc = SocketChannel.open(remote);
try {
acceptAndReset(ssc);
boolean before = sc.socket().isInputShutdown();
sc.socket().shutdownInput();
boolean after = sc.socket().isInputShutdown();
if (before || !after)
throw new RuntimeException("Before and after test failed");
sc.socket().shutdownOutput();
} finally {
sc.close();
}
} finally {
ssc.close();
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册