Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/Socket/TrafficClass.java
38812 views
/*1* Copyright (c) 2001, 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* @summary Test that setTrafficClass/getTraffiClass don't27* throw an exception28*/29import java.net.*;30import java.nio.*;31import java.nio.channels.*;3233public class TrafficClass {3435static final int IPTOS_RELIABILITY = 0x4;3637static int failures = 0;3839static void testDatagramSocket(DatagramSocket s) {40try {41s.setTrafficClass( IPTOS_RELIABILITY );42int tc = s.getTrafficClass();43} catch (Exception e) {44failures++;45System.err.println("testDatagramSocket failed: " + e);46}47}4849static void testSocket(Socket s) {50try {51s.setTrafficClass(IPTOS_RELIABILITY);52int tc = s.getTrafficClass();53} catch (Exception e) {54failures++;55System.err.println("testSocket failed: " + e);56}5758}5960public static void main(String args[]) throws Exception {6162DatagramSocket ds = new DatagramSocket();63testDatagramSocket(ds);6465DatagramChannel dc = DatagramChannel.open();66testDatagramSocket(dc.socket());6768Socket s = new Socket();69testSocket(s);7071SocketChannel sc = SocketChannel.open();72testSocket(sc.socket());7374if (failures > 0) {75throw new Exception(failures + " sub-test(s) failed - " +76"see log for details.");77}78}7980}818283