TimeToLive.java revision 2362
1292N/A/*
3261N/A * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
1292N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1292N/A *
1292N/A * This code is free software; you can redistribute it and/or modify it
1292N/A * under the terms of the GNU General Public License version 2 only, as
1292N/A * published by the Free Software Foundation.
1292N/A *
1292N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1292N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1292N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1292N/A * version 2 for more details (a copy is included in the LICENSE file that
1292N/A * accompanied this code).
1292N/A *
1292N/A * You should have received a copy of the GNU General Public License version
1292N/A * 2 along with this work; if not, write to the Free Software Foundation,
1292N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1292N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1292N/A */
1292N/A
1292N/A/*
1292N/A * @test
1292N/A *
1292N/A * @bug 4091012
1292N/A *
1292N/A * @summary Tests MulticastSocket send for new set/getTimeToLived
1292N/A *
1292N/A */
1292N/Aimport java.net.*;
1292N/A
1292N/Apublic class TimeToLive {
1292N/A
1292N/A static int[] new_ttls = { 0, 1, 127, 254, 255 };
1292N/A static int[] bad_ttls = { -1, 256 };
1292N/A
1292N/A public static void main(String[] args) throws Exception {
1292N/A MulticastSocket socket = new MulticastSocket(6789);
1292N/A int ttl = socket.getTimeToLive();
1292N/A System.out.println("default ttl: " + ttl);
1292N/A for (int i = 0; i < new_ttls.length; i++) {
1292N/A socket.setTimeToLive(new_ttls[i]);
1292N/A if (!(new_ttls[i] == socket.getTimeToLive())) {
1292N/A throw new RuntimeException("test failure, set/get differ: " +
1292N/A new_ttls[i] + " / " +
1292N/A socket.getTimeToLive());
1292N/A }
1292N/A }
1292N/A for (int j = 0; j < bad_ttls.length; j++) {
1292N/A boolean exception = false;
2692N/A try {
2692N/A socket.setTimeToLive(bad_ttls[j]);
2692N/A } catch (IllegalArgumentException e) {
1292N/A exception = true;
1292N/A }
1292N/A if (!exception) {
1292N/A throw new RuntimeException("bad argument accepted: " + bad_ttls[j]);
1292N/A }
1292N/A }
1292N/A }
1292N/A}
1292N/A