Path: blob/master/test/jdk/java/net/Socket/TrafficClass.java
41149 views
/*1* Copyright (c) 2001, 2018, 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 451178326* @library /test/lib27* @summary Test that setTrafficClass/getTraffiClass don't28* throw an exception29* @run main TrafficClass30* @run main/othervm -Djava.net.preferIPv4Stack=true TrafficClass31*/32import java.net.*;33import java.nio.*;34import java.nio.channels.*;35import jdk.test.lib.net.IPSupport;3637public class TrafficClass {3839static final int IPTOS_RELIABILITY = 0x4;4041static int failures = 0;4243static void testDatagramSocket(DatagramSocket s) {44try {45s.setTrafficClass( IPTOS_RELIABILITY );46int tc = s.getTrafficClass();47} catch (Exception e) {48failures++;49System.err.println("testDatagramSocket failed: " + e);50}51}5253static void testSocket(Socket s) {54try {55s.setTrafficClass(IPTOS_RELIABILITY);56int tc = s.getTrafficClass();57} catch (Exception e) {58failures++;59System.err.println("testSocket failed: " + e);60}6162}6364public static void main(String args[]) throws Exception {65IPSupport.throwSkippedExceptionIfNonOperational();6667DatagramSocket ds = new DatagramSocket();68testDatagramSocket(ds);6970DatagramChannel dc = DatagramChannel.open();71testDatagramSocket(dc.socket());7273Socket s = new Socket();74testSocket(s);7576SocketChannel sc = SocketChannel.open();77testSocket(sc.socket());7879if (failures > 0) {80throw new Exception(failures + " sub-test(s) failed - " +81"see log for details.");82}83}8485}868788