0N/A/*
2362N/A * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
1539N/A * @bug 4618960 4516760
1539N/A * @summary Test shutdownXXX and isInputShutdown
0N/A */
0N/A
1539N/Aimport java.io.IOException;
0N/Aimport java.net.*;
1539N/Aimport java.nio.ByteBuffer;
0N/Aimport java.nio.channels.*;
0N/A
0N/Apublic class Shutdown {
0N/A
1539N/A /**
1539N/A * Accept a connection, and close it immediately causing a hard reset.
1539N/A */
1539N/A static void acceptAndReset(ServerSocketChannel ssc) throws IOException {
1539N/A SocketChannel peer = ssc.accept();
1539N/A try {
4216N/A peer.setOption(StandardSocketOptions.SO_LINGER, 0);
1539N/A peer.configureBlocking(false);
1539N/A peer.write(ByteBuffer.wrap(new byte[128*1024]));
1539N/A } finally {
1539N/A peer.close();
1539N/A }
1539N/A }
1539N/A
1539N/A public static void main(String[] args) throws Exception {
1539N/A ServerSocketChannel ssc = ServerSocketChannel.open()
1539N/A .bind(new InetSocketAddress(0));
1539N/A try {
1539N/A InetAddress lh = InetAddress.getLocalHost();
1539N/A int port = ((InetSocketAddress)(ssc.getLocalAddress())).getPort();
1539N/A SocketAddress remote = new InetSocketAddress(lh, port);
1539N/A
1539N/A // Test SocketChannel shutdownXXX
1539N/A SocketChannel sc;
1539N/A sc = SocketChannel.open(remote);
1539N/A try {
1539N/A acceptAndReset(ssc);
1539N/A sc.shutdownInput();
1539N/A sc.shutdownOutput();
1539N/A } finally {
1539N/A sc.close();
1539N/A }
1539N/A
1539N/A // Test Socket adapter shutdownXXX and isShutdownInput
1539N/A sc = SocketChannel.open(remote);
1539N/A try {
1539N/A acceptAndReset(ssc);
1539N/A boolean before = sc.socket().isInputShutdown();
1539N/A sc.socket().shutdownInput();
1539N/A boolean after = sc.socket().isInputShutdown();
1539N/A if (before || !after)
1539N/A throw new RuntimeException("Before and after test failed");
1539N/A sc.socket().shutdownOutput();
1539N/A } finally {
1539N/A sc.close();
1539N/A }
1539N/A } finally {
1539N/A ssc.close();
1539N/A }
0N/A }
0N/A}