J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @bug 4468997 |
| 26 | * @summary SO_LINGER is ignored on Windows with Winsock 2 |
| 27 | */ |
| 28 | import java.net.*; |
| 29 | import java.io.*; |
| 30 | |
| 31 | public class RST implements Runnable { |
| 32 | |
| 33 | Socket client; |
| 34 | |
| 35 | public void run() { |
| 36 | try { |
| 37 | client.setSoLinger(true, 0); // hard reset |
| 38 | client.close(); |
| 39 | } catch (Exception e) { |
| 40 | e.printStackTrace(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | RST() throws Exception { |
| 45 | ServerSocket ss = new ServerSocket(0); |
| 46 | client = new Socket("localhost", ss.getLocalPort()); |
| 47 | Socket server = ss.accept(); |
| 48 | |
| 49 | Thread thr = new Thread(this); |
| 50 | thr.start(); |
| 51 | |
| 52 | SocketException exc = null; |
| 53 | try { |
| 54 | InputStream in = server.getInputStream(); |
| 55 | |
| 56 | /* |
| 57 | * This read should throw a SocketException indicating a |
| 58 | * connection reset. |
| 59 | */ |
| 60 | int n = in.read(); |
| 61 | } catch (SocketException se) { |
| 62 | exc = se; |
| 63 | } |
| 64 | |
| 65 | server.close(); |
| 66 | ss.close(); |
| 67 | |
| 68 | if (exc == null) { |
| 69 | throw new Exception("Expected SocketException not thrown"); |
| 70 | } |
| 71 | if (exc.getMessage().toLowerCase().indexOf("reset") == -1) { |
| 72 | throw new Exception("SocketException thrown but not expected \"connection reset\""); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | |
| 77 | public static void main(String args[]) throws Exception { |
| 78 | new RST(); |
| 79 | } |
| 80 | } |