author | dfuchs |
Fri, 30 Aug 2019 12:44:52 +0100 | |
changeset 57965 | ef15850629cd |
parent 47216 | 71c04702a3d5 |
child 58688 | 2b1e684c3ce6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57965
ef15850629cd
8193596: java/net/DatagramPacket/ReuseBuf.java failed due to timeout
dfuchs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* |
|
27 |
* @bug 4424096 |
|
28 |
* |
|
29 |
* @summary DatagramPacket spec needs clarification (reuse buf) |
|
30 |
*/ |
|
31 |
import java.net.*; |
|
32 |
||
33 |
public class ReuseBuf { |
|
34 |
static String msgs[] = {"Hello World", "Java", "Good Bye"}; |
|
35 |
static int port; |
|
36 |
||
37 |
static class ServerThread extends Thread{ |
|
38 |
DatagramSocket ds; |
|
39 |
public ServerThread() { |
|
40 |
try { |
|
57965
ef15850629cd
8193596: java/net/DatagramPacket/ReuseBuf.java failed due to timeout
dfuchs
parents:
47216
diff
changeset
|
41 |
InetAddress local = InetAddress.getLocalHost(); |
ef15850629cd
8193596: java/net/DatagramPacket/ReuseBuf.java failed due to timeout
dfuchs
parents:
47216
diff
changeset
|
42 |
InetSocketAddress bindaddr = new InetSocketAddress(local, 0); |
ef15850629cd
8193596: java/net/DatagramPacket/ReuseBuf.java failed due to timeout
dfuchs
parents:
47216
diff
changeset
|
43 |
ds = new DatagramSocket(bindaddr); |
2 | 44 |
port = ds.getLocalPort(); |
45 |
} catch (Exception e) { |
|
46 |
throw new RuntimeException(e.getMessage()); |
|
47 |
} |
|
48 |
} |
|
49 |
||
50 |
public void run() { |
|
51 |
byte b[] = new byte[100]; |
|
52 |
DatagramPacket dp = new DatagramPacket(b,b.length); |
|
53 |
while (true) { |
|
54 |
try { |
|
55 |
ds.receive(dp); |
|
56 |
String reply = new String(dp.getData(), dp.getOffset(), dp.getLength()); |
|
57 |
ds.send(new DatagramPacket(reply.getBytes(),reply.length(), |
|
58 |
dp.getAddress(),dp.getPort())); |
|
59 |
if (reply.equals(msgs[msgs.length-1])) { |
|
60 |
break; |
|
61 |
} |
|
62 |
} catch (Exception e) { |
|
63 |
throw new RuntimeException(e.getMessage()); |
|
64 |
} |
|
65 |
} |
|
66 |
ds.close(); |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
public static void main(String args[]) throws Exception { |
|
71 |
ServerThread st = new ServerThread(); |
|
72 |
st.start(); |
|
57965
ef15850629cd
8193596: java/net/DatagramPacket/ReuseBuf.java failed due to timeout
dfuchs
parents:
47216
diff
changeset
|
73 |
InetAddress local = InetAddress.getLocalHost(); |
ef15850629cd
8193596: java/net/DatagramPacket/ReuseBuf.java failed due to timeout
dfuchs
parents:
47216
diff
changeset
|
74 |
InetSocketAddress bindaddr = new InetSocketAddress(local, 0); |
ef15850629cd
8193596: java/net/DatagramPacket/ReuseBuf.java failed due to timeout
dfuchs
parents:
47216
diff
changeset
|
75 |
DatagramSocket ds = new DatagramSocket(bindaddr); |
2 | 76 |
byte b[] = new byte[100]; |
77 |
DatagramPacket dp = new DatagramPacket(b,b.length); |
|
78 |
for (int i = 0; i < msgs.length; i++) { |
|
79 |
ds.send(new DatagramPacket(msgs[i].getBytes(),msgs[i].length(), |
|
13359
edb9f5468e9a
7081476: test/java/net/InetSocketAddress/B6469803.java failing intermittently
chegar
parents:
5506
diff
changeset
|
80 |
InetAddress.getLocalHost(), |
2 | 81 |
port)); |
82 |
ds.receive(dp); |
|
83 |
if (!msgs[i].equals(new String(dp.getData(), dp.getOffset(), dp.getLength()))) { |
|
84 |
throw new RuntimeException("Msg expected: "+msgs[i] +msgs[i].length()+ |
|
85 |
"msg received: "+new String(dp.getData(), dp.getOffset(), dp.getLength())+dp.getLength()); |
|
86 |
} |
|
87 |
} |
|
88 |
ds.close(); |
|
89 |
System.out.println("Test Passed!!!"); |
|
90 |
} |
|
91 |
} |