author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 53445 | c96f9aa1f3d8 |
permissions | -rw-r--r-- |
29224
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
1 |
/* |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
29224
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
4 |
* |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
8 |
* |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
13 |
* accompanied this code). |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
14 |
* |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
18 |
* |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
21 |
* questions. |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
22 |
*/ |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
23 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
24 |
/* @test |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
25 |
* @bug 8071599 |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
26 |
* @run main/othervm SendUrgentData |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
27 |
* @run main/othervm SendUrgentData -inline |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
28 |
* @summary Test sending of urgent data. |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
29 |
*/ |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
30 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
31 |
import java.io.IOException; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
32 |
import java.net.InetSocketAddress; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
33 |
import java.net.SocketAddress; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
34 |
import java.net.SocketException; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
35 |
import java.nio.ByteBuffer; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
36 |
import java.nio.channels.ServerSocketChannel; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
37 |
import java.nio.channels.SocketChannel; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
38 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
39 |
public class SendUrgentData { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
40 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
41 |
/** |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
42 |
* The arguments may be one of the following: |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
43 |
* <ol> |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
44 |
* <li>-server</li> |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
45 |
* <li>-client host port [-inline]</li> |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
46 |
* <li>[-inline]</li> |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
47 |
* </ol> |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
48 |
* The first option creates a standalone server, the second a standalone |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
49 |
* client, and the third a self-contained server-client pair on the |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
50 |
* local host. |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
51 |
* |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
52 |
* @param args |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
53 |
* @throws Exception |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
54 |
*/ |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
55 |
public static void main(String[] args) throws Exception { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
56 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
57 |
ServerSocketChannelThread serverThread |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
58 |
= new ServerSocketChannelThread("SendUrgentDataServer"); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
59 |
serverThread.start(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
60 |
boolean b = serverThread.isAlive(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
61 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
62 |
String host = null; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
63 |
int port = 0; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
64 |
boolean inline = false; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
65 |
if (args.length > 0 && args[0].equals("-server")) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
66 |
System.out.println(serverThread.getAddress()); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
67 |
Thread.currentThread().suspend(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
68 |
} else { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
69 |
if (args.length > 0 && args[0].equals("-client")) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
70 |
host = args[1]; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
71 |
port = Integer.parseInt(args[2]); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
72 |
if (args.length > 3) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
73 |
inline = args[2].equals("-inline"); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
74 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
75 |
} else { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
76 |
host = "localhost"; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
77 |
port = serverThread.getAddress().getPort(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
78 |
if (args.length > 0) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
79 |
inline = args[0].equals("-inline"); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
80 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
81 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
82 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
83 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
84 |
System.out.println("OOB Inline : "+inline); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
85 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
86 |
SocketAddress sa = new InetSocketAddress(host, port); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
87 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
88 |
try (SocketChannel sc = SocketChannel.open(sa)) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
89 |
sc.configureBlocking(false); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
90 |
sc.socket().setOOBInline(inline); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
91 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
92 |
sc.socket().sendUrgentData(0); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
93 |
System.out.println("wrote 1 OOB byte"); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
94 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
95 |
ByteBuffer bb = ByteBuffer.wrap(new byte[100 * 1000]); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
96 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
97 |
int blocked = 0; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
98 |
long total = 0; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
99 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
100 |
int n; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
101 |
do { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
102 |
n = sc.write(bb); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
103 |
if (n == 0) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
104 |
System.out.println("blocked, wrote " + total + " so far"); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
105 |
if (++blocked == 10) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
106 |
break; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
107 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
108 |
Thread.sleep(100); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
109 |
} else { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
110 |
total += n; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
111 |
bb.rewind(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
112 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
113 |
} while (n > 0); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
114 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
115 |
long attempted = 0; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
116 |
while (attempted < total) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
117 |
bb.rewind(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
118 |
n = sc.write(bb); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
119 |
System.out.println("wrote " + n + " normal bytes"); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
120 |
attempted += bb.capacity(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
121 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
122 |
String osName = System.getProperty("os.name").toLowerCase(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
123 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
124 |
try { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
125 |
sc.socket().sendUrgentData(0); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
126 |
} catch (IOException ex) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
127 |
if (osName.contains("linux")) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
128 |
if (!ex.getMessage().contains("Socket buffer full")) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
129 |
throw new RuntimeException("Unexpected message", ex); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
130 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
131 |
} else if (osName.contains("os x") || osName.contains("mac")) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
132 |
if (!ex.getMessage().equals("No buffer space available")) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
133 |
throw new RuntimeException("Unexpected message", ex); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
134 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
135 |
} else if (osName.contains("windows")) { |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
47216
diff
changeset
|
136 |
if (!ex.getMessage().equals("Socket buffer full")) { |
29224
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
137 |
throw new RuntimeException("Unexpected message", ex); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
138 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
139 |
} else { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
140 |
throw new RuntimeException("Unexpected IOException", ex); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
141 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
142 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
143 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
144 |
try { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
145 |
Thread.sleep(100); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
146 |
} catch (InterruptedException ex) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
147 |
// don't want to fail on this so just print trace and break |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
148 |
ex.printStackTrace(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
149 |
break; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
150 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
151 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
152 |
} finally { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
153 |
serverThread.close(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
154 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
155 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
156 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
157 |
static class ServerSocketChannelThread extends Thread { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
158 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
159 |
private ServerSocketChannel ssc; |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
160 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
161 |
private ServerSocketChannelThread(String name) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
162 |
super(name); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
163 |
try { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
164 |
ssc = ServerSocketChannel.open(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
165 |
ssc.bind(new InetSocketAddress((0))); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
166 |
} catch (IOException ex) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
167 |
throw new RuntimeException(ex); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
168 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
169 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
170 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
171 |
public void run() { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
172 |
while (ssc.isOpen()) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
173 |
try { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
174 |
Thread.sleep(100); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
175 |
} catch (InterruptedException ex) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
176 |
throw new RuntimeException(ex); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
177 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
178 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
179 |
try { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
180 |
ssc.close(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
181 |
} catch (IOException ex) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
182 |
throw new RuntimeException(ex); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
183 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
184 |
System.out.println("ServerSocketChannelThread exiting ..."); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
185 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
186 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
187 |
public InetSocketAddress getAddress() throws IOException { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
188 |
if (ssc == null) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
189 |
throw new IllegalStateException("ServerSocketChannel not created"); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
190 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
191 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
192 |
return (InetSocketAddress) ssc.getLocalAddress(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
193 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
194 |
|
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
195 |
public void close() { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
196 |
try { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
197 |
ssc.close(); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
198 |
} catch (IOException ex) { |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
199 |
throw new RuntimeException(ex); |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
200 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
201 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
202 |
} |
8433f5f46142
8071599: (so) Socket adapter sendUrgentData throws IllegalBlockingMode when channel configured non-blocking
bpb
parents:
diff
changeset
|
203 |
} |