Path: blob/master/test/jdk/java/net/Socket/RST.java
41149 views
/*1* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 446899726* @library /test/lib27* @summary SO_LINGER is ignored on Windows with Winsock 228* @run main RST29* @run main/othervm -Djava.net.preferIPv4Stack=true RST30*/31import java.net.*;32import java.io.*;33import jdk.test.lib.net.IPSupport;3435public class RST implements Runnable {3637Socket client;3839public void run() {40try {41client.setSoLinger(true, 0); // hard reset42client.close();43} catch (Exception e) {44e.printStackTrace();45}46}4748RST() throws Exception {49InetAddress loopback = InetAddress.getLoopbackAddress();50ServerSocket ss = new ServerSocket();51ss.bind(new InetSocketAddress(loopback, 0));52client = new Socket(loopback, ss.getLocalPort());53Socket server = ss.accept();5455Thread thr = new Thread(this);56thr.start();5758SocketException exc = null;59try {60InputStream in = server.getInputStream();6162/*63* This read should throw a SocketException indicating a64* connection reset.65*/66int n = in.read();67} catch (SocketException se) {68exc = se;69}7071server.close();72ss.close();7374if (exc == null) {75throw new Exception("Expected SocketException not thrown");76}77if (exc.getMessage().toLowerCase().indexOf("reset") == -1) {78throw new Exception("SocketException thrown but not expected \"connection reset\"");79}80}818283public static void main(String args[]) throws Exception {84IPSupport.throwSkippedExceptionIfNonOperational();8586new RST();87}88}899091