1 /* 2 * Copyright (c) 2003, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * 26 * 27 * Tests that the channel returned by System.inheritedChannel() 28 * is in blocking mode, bound, and in the case of a SocketChannel 29 * connected to a peer. 30 * 31 * The test works by launching a test service (called StateTestService) so 32 * that it inherits each type of channel. The test service checks the 33 * socket state and replies back to this class via an out-of-band 34 * channel. 35 */ 36 import java.io.*; 37 import java.net.*; 38 import java.nio.ByteBuffer; 39 import java.nio.channels.*; 40 41 public class StateTest { 42 43 private static int failures = 0; 44 45 private static String TEST_SERVICE = "StateTestService"; 46 47 /* 48 * Reads the test result from the "out-of-band" connection to the test service. 49 * 50 * The out-of-band connection is just a TCP connection from the service to 51 * this class. waitForTestResult just waits (with timeout) for the service 52 * to connect. Once connected it waits (with timeout) for the test result. 53 * The test result is examined. 54 */ 55 private static void waitForTestResult(ServerSocketChannel ssc, boolean expectFail) throws IOException { 56 Selector sel = ssc.provider().openSelector(); 57 SelectionKey sk; 58 SocketChannel sc; 59 | 1 /* 2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * 26 * 27 * Tests that the channel returned by System.inheritedChannel() 28 * is in blocking mode, bound, and in the case of a SocketChannel 29 * connected to a peer. 30 * 31 * The test works by launching a test service (called StateTestService) so 32 * that it inherits each type of channel. The test service checks the 33 * socket state and replies back to this class via an out-of-band 34 * channel. 35 */ 36 import java.io.IOException; 37 import java.net.InetSocketAddress; 38 import java.nio.ByteBuffer; 39 import java.nio.channels.DatagramChannel; 40 import java.nio.channels.SelectionKey; 41 import java.nio.channels.Selector; 42 import java.nio.channels.ServerSocketChannel; 43 import java.nio.channels.SocketChannel; 44 45 public class StateTest { 46 47 private static int failures = 0; 48 49 private static String TEST_SERVICE = "StateTestService"; 50 51 /* 52 * Reads the test result from the "out-of-band" connection to the test service. 53 * 54 * The out-of-band connection is just a TCP connection from the service to 55 * this class. waitForTestResult just waits (with timeout) for the service 56 * to connect. Once connected it waits (with timeout) for the test result. 57 * The test result is examined. 58 */ 59 private static void waitForTestResult(ServerSocketChannel ssc, boolean expectFail) throws IOException { 60 Selector sel = ssc.provider().openSelector(); 61 SelectionKey sk; 62 SocketChannel sc; 63 |