author | chegar |
Thu, 21 Nov 2019 12:14:29 +0000 | |
changeset 59205 | afcc8af048e6 |
parent 59204 | 7b10581e9632 |
permissions | -rw-r--r-- |
2542 | 1 |
/* |
59204
7b10581e9632
8232097: (sctp) SctpNet.init() results in java.lang.UnsatisfiedLinkError
chegar
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. |
2542 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2542 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2542 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2542 | 24 |
*/ |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
10137
diff
changeset
|
25 |
package sun.nio.ch.sctp; |
2542 | 26 |
|
27 |
import java.io.FileDescriptor; |
|
28 |
import java.io.IOException; |
|
29 |
import java.net.InetAddress; |
|
30 |
import java.net.InetSocketAddress; |
|
31 |
import java.net.SocketAddress; |
|
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
32 |
import java.nio.channels.AlreadyBoundException; |
2542 | 33 |
import java.util.Set; |
34 |
import java.util.HashSet; |
|
35 |
import java.security.AccessController; |
|
23582
d5fa3327ab3a
8038177: Eliminate unnecessary dependency to sun.security.action
mchung
parents:
23010
diff
changeset
|
36 |
import java.security.PrivilegedAction; |
59205
afcc8af048e6
8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents:
59204
diff
changeset
|
37 |
import sun.net.util.IPAddressUtil; |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
10137
diff
changeset
|
38 |
import sun.nio.ch.IOUtil; |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
10137
diff
changeset
|
39 |
import sun.nio.ch.Net; |
2542 | 40 |
import com.sun.nio.sctp.SctpSocketOption; |
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
7668
diff
changeset
|
41 |
import static com.sun.nio.sctp.SctpStandardSocketOptions.*; |
2542 | 42 |
|
43 |
public class SctpNet { |
|
23582
d5fa3327ab3a
8038177: Eliminate unnecessary dependency to sun.security.action
mchung
parents:
23010
diff
changeset
|
44 |
private static final String osName = AccessController.doPrivileged( |
d5fa3327ab3a
8038177: Eliminate unnecessary dependency to sun.security.action
mchung
parents:
23010
diff
changeset
|
45 |
(PrivilegedAction<String>) () -> System.getProperty("os.name")); |
2542 | 46 |
|
47 |
/* -- Miscellaneous SCTP utilities -- */ |
|
48 |
||
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
49 |
private static boolean IPv4MappedAddresses() { |
2542 | 50 |
if ("SunOS".equals(osName)) { |
51 |
/* Solaris supports IPv4Mapped Addresses with bindx */ |
|
52 |
return true; |
|
53 |
} /* else { //other OS/implementations */ |
|
54 |
||
55 |
/* lksctp/linux requires Ipv4 addresses */ |
|
56 |
return false; |
|
57 |
} |
|
58 |
||
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
59 |
static boolean throwAlreadyBoundException() throws IOException { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
60 |
throw new AlreadyBoundException(); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
61 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
62 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
63 |
static void listen(int fd, int backlog) throws IOException { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
64 |
listen0(fd, backlog); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
65 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
66 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
67 |
static int connect(int fd, InetAddress remote, int remotePort) |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
68 |
throws IOException { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
69 |
return connect0(fd, remote, remotePort); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
70 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
71 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
72 |
static void close(int fd) throws IOException { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
73 |
close0(fd); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
74 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
75 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
76 |
static void preClose(int fd) throws IOException { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
77 |
preClose0(fd); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
78 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
79 |
|
2542 | 80 |
/** |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
81 |
* @param oneToOne |
2542 | 82 |
* if {@code true} returns a one-to-one sctp socket, otherwise |
83 |
* returns a one-to-many sctp socket |
|
84 |
*/ |
|
85 |
static FileDescriptor socket(boolean oneToOne) throws IOException { |
|
86 |
int nativefd = socket0(oneToOne); |
|
87 |
return IOUtil.newFD(nativefd); |
|
88 |
} |
|
89 |
||
90 |
static void bindx(int fd, InetAddress[] addrs, int port, boolean add) |
|
91 |
throws IOException { |
|
92 |
bindx(fd, addrs, port, addrs.length, add, |
|
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
93 |
IPv4MappedAddresses()); |
2542 | 94 |
} |
95 |
||
96 |
static Set<SocketAddress> getLocalAddresses(int fd) |
|
97 |
throws IOException { |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
98 |
Set<SocketAddress> set = null; |
2542 | 99 |
SocketAddress[] saa = getLocalAddresses0(fd); |
100 |
||
101 |
if (saa != null) { |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
102 |
set = getRevealedLocalAddressSet(saa); |
2542 | 103 |
} |
104 |
||
105 |
return set; |
|
106 |
} |
|
107 |
||
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
108 |
private static Set<SocketAddress> getRevealedLocalAddressSet( |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
109 |
SocketAddress[] saa) |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
110 |
{ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
111 |
SecurityManager sm = System.getSecurityManager(); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
112 |
Set<SocketAddress> set = new HashSet<>(saa.length); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
113 |
for (SocketAddress sa : saa) { |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
114 |
set.add(getRevealedLocalAddress(sa, sm)); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
115 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
116 |
return set; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
117 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
118 |
|
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
119 |
private static SocketAddress getRevealedLocalAddress(SocketAddress sa, |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
120 |
SecurityManager sm) |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
121 |
{ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
122 |
if (sm == null || sa == null) |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
123 |
return sa; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
124 |
InetSocketAddress ia = (InetSocketAddress)sa; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
125 |
try{ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
126 |
sm.checkConnect(ia.getAddress().getHostAddress(), -1); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
127 |
// Security check passed |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
128 |
} catch (SecurityException e) { |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
129 |
// Return loopback address |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
130 |
return new InetSocketAddress(InetAddress.getLoopbackAddress(), |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
131 |
ia.getPort()); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
132 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
133 |
return sa; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
134 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
135 |
|
2542 | 136 |
static Set<SocketAddress> getRemoteAddresses(int fd, int assocId) |
137 |
throws IOException { |
|
138 |
HashSet<SocketAddress> set = null; |
|
139 |
SocketAddress[] saa = getRemoteAddresses0(fd, assocId); |
|
140 |
||
141 |
if (saa != null) { |
|
142 |
set = new HashSet<SocketAddress>(saa.length); |
|
143 |
for (SocketAddress sa : saa) |
|
144 |
set.add(sa); |
|
145 |
} |
|
146 |
||
147 |
return set; |
|
148 |
} |
|
149 |
||
10137
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
150 |
static <T> void setSocketOption(int fd, |
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
151 |
SctpSocketOption<T> name, |
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
152 |
T value, |
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
153 |
int assocId) |
2542 | 154 |
throws IOException { |
155 |
if (value == null) |
|
156 |
throw new IllegalArgumentException("Invalid option value"); |
|
157 |
||
158 |
if (name.equals(SCTP_INIT_MAXSTREAMS)) { |
|
159 |
InitMaxStreams maxStreamValue = (InitMaxStreams)value; |
|
160 |
SctpNet.setInitMsgOption0(fd, |
|
161 |
maxStreamValue.maxInStreams(), maxStreamValue.maxOutStreams()); |
|
162 |
} else if (name.equals(SCTP_PRIMARY_ADDR) || |
|
163 |
name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) { |
|
164 |
||
165 |
SocketAddress addr = (SocketAddress) value; |
|
166 |
if (addr == null) |
|
167 |
throw new IllegalArgumentException("Invalid option value"); |
|
168 |
||
169 |
Net.checkAddress(addr); |
|
170 |
InetSocketAddress netAddr = (InetSocketAddress)addr; |
|
171 |
||
172 |
if (name.equals(SCTP_PRIMARY_ADDR)) { |
|
59205
afcc8af048e6
8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents:
59204
diff
changeset
|
173 |
InetAddress inetAddress = netAddr.getAddress(); |
afcc8af048e6
8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents:
59204
diff
changeset
|
174 |
if (inetAddress.isLinkLocalAddress()) { |
afcc8af048e6
8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents:
59204
diff
changeset
|
175 |
inetAddress = IPAddressUtil.toScopedAddress(inetAddress); |
afcc8af048e6
8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents:
59204
diff
changeset
|
176 |
} |
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
177 |
setPrimAddrOption0(fd, |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
178 |
assocId, |
59205
afcc8af048e6
8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents:
59204
diff
changeset
|
179 |
inetAddress, |
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
180 |
netAddr.getPort()); |
2542 | 181 |
} else { |
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
182 |
setPeerPrimAddrOption0(fd, |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
183 |
assocId, |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
184 |
netAddr.getAddress(), |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
185 |
netAddr.getPort(), |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
186 |
IPv4MappedAddresses()); |
2542 | 187 |
} |
188 |
} else if (name.equals(SCTP_DISABLE_FRAGMENTS) || |
|
189 |
name.equals(SCTP_EXPLICIT_COMPLETE) || |
|
190 |
name.equals(SCTP_FRAGMENT_INTERLEAVE) || |
|
191 |
name.equals(SCTP_NODELAY) || |
|
192 |
name.equals(SO_SNDBUF) || |
|
193 |
name.equals(SO_RCVBUF) || |
|
194 |
name.equals(SO_LINGER)) { |
|
195 |
setIntOption(fd, name, value); |
|
196 |
} else { |
|
197 |
throw new AssertionError("Unknown socket option"); |
|
198 |
} |
|
199 |
} |
|
200 |
||
10137
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
201 |
static Object getSocketOption(int fd, SctpSocketOption<?> name, int assocId) |
2542 | 202 |
throws IOException { |
203 |
if (name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) { |
|
204 |
throw new IllegalArgumentException( |
|
205 |
"SCTP_SET_PEER_PRIMARY_ADDR cannot be retrieved"); |
|
206 |
} else if (name.equals(SCTP_INIT_MAXSTREAMS)) { |
|
207 |
/* container for holding maxIn/Out streams */ |
|
208 |
int[] values = new int[2]; |
|
209 |
SctpNet.getInitMsgOption0(fd, values); |
|
210 |
return InitMaxStreams.create(values[0], values[1]); |
|
211 |
} else if (name.equals(SCTP_PRIMARY_ADDR)) { |
|
212 |
return getPrimAddrOption0(fd, assocId); |
|
213 |
} else if (name.equals(SCTP_DISABLE_FRAGMENTS) || |
|
214 |
name.equals(SCTP_EXPLICIT_COMPLETE) || |
|
215 |
name.equals(SCTP_FRAGMENT_INTERLEAVE) || |
|
216 |
name.equals(SCTP_NODELAY) || |
|
217 |
name.equals(SO_SNDBUF) || |
|
218 |
name.equals(SO_RCVBUF) || |
|
219 |
name.equals(SO_LINGER)) { |
|
220 |
return getIntOption(fd, name); |
|
221 |
} else { |
|
222 |
throw new AssertionError("Unknown socket option"); |
|
223 |
} |
|
224 |
} |
|
225 |
||
10137
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
226 |
static void setIntOption(int fd, SctpSocketOption<?> name, Object value) |
2542 | 227 |
throws IOException { |
228 |
if (value == null) |
|
229 |
throw new IllegalArgumentException("Invalid option value"); |
|
230 |
||
231 |
Class<?> type = name.type(); |
|
232 |
if (type != Integer.class && type != Boolean.class) |
|
233 |
throw new AssertionError("Should not reach here"); |
|
234 |
||
235 |
if (name == SO_RCVBUF || |
|
236 |
name == SO_SNDBUF) |
|
237 |
{ |
|
238 |
int i = ((Integer)value).intValue(); |
|
239 |
if (i < 0) |
|
240 |
throw new IllegalArgumentException( |
|
241 |
"Invalid send/receive buffer size"); |
|
242 |
} else if (name == SO_LINGER) { |
|
243 |
int i = ((Integer)value).intValue(); |
|
244 |
if (i < 0) |
|
245 |
value = Integer.valueOf(-1); |
|
246 |
if (i > 65535) |
|
247 |
value = Integer.valueOf(65535); |
|
248 |
} else if (name.equals(SCTP_FRAGMENT_INTERLEAVE)) { |
|
249 |
int i = ((Integer)value).intValue(); |
|
250 |
if (i < 0 || i > 2) |
|
251 |
throw new IllegalArgumentException( |
|
252 |
"Invalid value for SCTP_FRAGMENT_INTERLEAVE"); |
|
253 |
} |
|
254 |
||
255 |
int arg; |
|
256 |
if (type == Integer.class) { |
|
257 |
arg = ((Integer)value).intValue(); |
|
258 |
} else { |
|
259 |
boolean b = ((Boolean)value).booleanValue(); |
|
260 |
arg = (b) ? 1 : 0; |
|
261 |
} |
|
262 |
||
263 |
setIntOption0(fd, ((SctpStdSocketOption)name).constValue(), arg); |
|
264 |
} |
|
265 |
||
10137
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
266 |
static Object getIntOption(int fd, SctpSocketOption<?> name) |
2542 | 267 |
throws IOException { |
268 |
Class<?> type = name.type(); |
|
269 |
||
270 |
if (type != Integer.class && type != Boolean.class) |
|
271 |
throw new AssertionError("Should not reach here"); |
|
272 |
||
273 |
if (!(name instanceof SctpStdSocketOption)) |
|
274 |
throw new AssertionError("Should not reach here"); |
|
275 |
||
276 |
int value = getIntOption0(fd, |
|
277 |
((SctpStdSocketOption)name).constValue()); |
|
278 |
||
279 |
if (type == Integer.class) { |
|
280 |
return Integer.valueOf(value); |
|
281 |
} else { |
|
282 |
return (value == 0) ? Boolean.FALSE : Boolean.TRUE; |
|
283 |
} |
|
284 |
} |
|
285 |
||
286 |
static void shutdown(int fd, int assocId) |
|
287 |
throws IOException { |
|
288 |
shutdown0(fd, assocId); |
|
289 |
} |
|
290 |
||
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
291 |
static FileDescriptor branch(int fd, int assocId) throws IOException { |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
292 |
int nativefd = branch0(fd, assocId); |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
293 |
return IOUtil.newFD(nativefd); |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
294 |
} |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
295 |
|
2542 | 296 |
/* Native Methods */ |
297 |
static native int socket0(boolean oneToOne) throws IOException; |
|
298 |
||
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
299 |
static native void listen0(int fd, int backlog) throws IOException; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
300 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
301 |
static native int connect0(int fd, InetAddress remote, int remotePort) |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
302 |
throws IOException; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
303 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
304 |
static native void close0(int fd) throws IOException; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
305 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
306 |
static native void preClose0(int fd) throws IOException; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
307 |
|
2542 | 308 |
static native void bindx(int fd, InetAddress[] addrs, int port, int length, |
309 |
boolean add, boolean preferIPv6) throws IOException; |
|
310 |
||
311 |
static native int getIntOption0(int fd, int opt) throws IOException; |
|
312 |
||
313 |
static native void setIntOption0(int fd, int opt, int arg) |
|
314 |
throws IOException; |
|
315 |
||
316 |
static native SocketAddress[] getLocalAddresses0(int fd) throws IOException; |
|
317 |
||
318 |
static native SocketAddress[] getRemoteAddresses0(int fd, int assocId) |
|
319 |
throws IOException; |
|
320 |
||
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
321 |
static native int branch0(int fd, int assocId) throws IOException; |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
322 |
|
2542 | 323 |
static native void setPrimAddrOption0(int fd, int assocId, InetAddress ia, |
324 |
int port) throws IOException; |
|
325 |
||
326 |
static native void setPeerPrimAddrOption0(int fd, int assocId, |
|
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
327 |
InetAddress ia, int port, boolean preferIPv6) throws IOException; |
2542 | 328 |
|
329 |
static native SocketAddress getPrimAddrOption0(int fd, int assocId) |
|
330 |
throws IOException; |
|
331 |
||
332 |
/* retVals [0] maxInStreams, [1] maxOutStreams */ |
|
333 |
static native void getInitMsgOption0(int fd, int[] retVals) throws IOException; |
|
334 |
||
335 |
static native void setInitMsgOption0(int fd, int arg1, int arg2) |
|
336 |
throws IOException; |
|
337 |
||
338 |
static native void shutdown0(int fd, int assocId); |
|
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
339 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
340 |
static native void init(); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
341 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
342 |
static { |
59204
7b10581e9632
8232097: (sctp) SctpNet.init() results in java.lang.UnsatisfiedLinkError
chegar
parents:
47216
diff
changeset
|
343 |
IOUtil.load(); // loads nio & net native libraries |
7b10581e9632
8232097: (sctp) SctpNet.init() results in java.lang.UnsatisfiedLinkError
chegar
parents:
47216
diff
changeset
|
344 |
java.security.AccessController.doPrivileged( |
7b10581e9632
8232097: (sctp) SctpNet.init() results in java.lang.UnsatisfiedLinkError
chegar
parents:
47216
diff
changeset
|
345 |
new java.security.PrivilegedAction<Void>() { |
7b10581e9632
8232097: (sctp) SctpNet.init() results in java.lang.UnsatisfiedLinkError
chegar
parents:
47216
diff
changeset
|
346 |
public Void run() { |
7b10581e9632
8232097: (sctp) SctpNet.init() results in java.lang.UnsatisfiedLinkError
chegar
parents:
47216
diff
changeset
|
347 |
System.loadLibrary("sctp"); |
7b10581e9632
8232097: (sctp) SctpNet.init() results in java.lang.UnsatisfiedLinkError
chegar
parents:
47216
diff
changeset
|
348 |
return null; |
7b10581e9632
8232097: (sctp) SctpNet.init() results in java.lang.UnsatisfiedLinkError
chegar
parents:
47216
diff
changeset
|
349 |
} |
7b10581e9632
8232097: (sctp) SctpNet.init() results in java.lang.UnsatisfiedLinkError
chegar
parents:
47216
diff
changeset
|
350 |
}); |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
351 |
init(); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
352 |
} |
2542 | 353 |
} |
354 |