Concurrent.java revision 0
869N/A/*
869N/A * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
869N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
869N/A *
869N/A * This code is free software; you can redistribute it and/or modify it
869N/A * under the terms of the GNU General Public License version 2 only, as
869N/A * published by the Free Software Foundation.
869N/A *
869N/A * This code is distributed in the hope that it will be useful, but WITHOUT
869N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
869N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
869N/A * version 2 for more details (a copy is included in the LICENSE file that
869N/A * accompanied this code).
869N/A *
869N/A * You should have received a copy of the GNU General Public License version
869N/A * 2 along with this work; if not, write to the Free Software Foundation,
869N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
873N/A *
869N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
869N/A * CA 95054 USA or visit www.sun.com if you need additional information or
869N/A * have any questions.
869N/A */
869N/A
869N/A/*
869N/A * @test
0N/A * @bug 4431020
0N/A * @summary On Windows 2000 we observed behaviour that reflects the underlying
0N/A * implementation :-
0N/A * 1. PortUnreachableException throw per underlying reset
869N/A * 2. No PUE throw for DatagramSocket.send
0N/A */
0N/Aimport java.net.*;
0N/A
869N/Apublic class Concurrent implements Runnable {
0N/A
869N/A DatagramSocket s;
0N/A
869N/A public void run() {
869N/A try {
869N/A byte b[] = new byte[512];
0N/A DatagramPacket p = new DatagramPacket(b, b.length);
869N/A
48N/A int pue_count = 0;
869N/A while (true) {
0N/A try {
869N/A System.out.println("receive...");
716N/A s.receive(p);
869N/A } catch (PortUnreachableException pue) {
0N/A System.out.println("receive threw PortUnreachableException");
0N/A pue_count++;
869N/A }
868N/A System.out.println("receiver sleeping");
983N/A Thread.currentThread().sleep(100*pue_count);
1004N/A }
1007N/A
1378N/A } catch (Exception e) { }
1411N/A }
1503N/A
869N/A Concurrent(InetAddress ia, int port) throws Exception {
869N/A
1004N/A System.out.println("");
0N/A System.out.println("***");
0N/A System.out.println("Test Description:");
869N/A System.out.println(" - Block reader thread on receive");
868N/A System.out.println(" - Send datagrams to bad destination with wee pauses");
0N/A System.out.println(" - Observe which thread gets the PUE");
0N/A System.out.println("");
65N/A
869N/A /*
868N/A * Create the datagram and connect it to destination
65N/A */
869N/A s = new DatagramSocket();
65N/A s.connect(ia, port);
65N/A s.setSoTimeout(60000);
65N/A
65N/A /*
65N/A * Start the reader thread
65N/A */
65N/A Thread thr = new Thread(this);
65N/A thr.start();
65N/A Thread.currentThread().sleep(2000);
65N/A
65N/A byte b[] = new byte[512];
65N/A DatagramPacket p = new DatagramPacket(b, b.length);
65N/A
65N/A /*
65N/A * Send a bunch of packets to the destination
0N/A */
869N/A for (int i=0; i<10; i++) {
868N/A try {
0N/A System.out.println("Sending...");
0N/A s.send(p);
0N/A } catch (PortUnreachableException e) {
0N/A System.out.println("send threw PortUnreachableException");
0N/A }
0N/A Thread.currentThread().sleep(100);
0N/A }
1501N/A
0N/A /*
0N/A * Give time for ICMP port unreachables to return
869N/A */
868N/A Thread.currentThread().sleep(5000);
0N/A
0N/A s.close();
869N/A }
0N/A
0N/A
869N/A public static void main(String args[]) throws Exception {
868N/A
869N/A InetAddress ia;
869N/A int port;
868N/A if (args.length >= 2) {
868N/A ia = InetAddress.getByName(args[0]);
869N/A port = Integer.parseInt(args[1]);
869N/A } else {
0N/A ia = InetAddress.getLocalHost();
0N/A DatagramSocket s1 = new DatagramSocket();
48N/A port = s1.getLocalPort();
869N/A s1.close();
869N/A }
869N/A
868N/A new Concurrent(ia, port);
869N/A }
868N/A
869N/A}
1155N/A