author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 25859 | jdk/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpNet.java@3317bb8137f4 |
child 59204 | 7b10581e9632 |
permissions | -rw-r--r-- |
2542 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
18212
diff
changeset
|
2 |
* Copyright (c) 2009, 2013, 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; |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
10137
diff
changeset
|
37 |
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
|
38 |
import sun.nio.ch.Net; |
2542 | 39 |
import com.sun.nio.sctp.SctpSocketOption; |
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
7668
diff
changeset
|
40 |
import static com.sun.nio.sctp.SctpStandardSocketOptions.*; |
2542 | 41 |
|
42 |
public class SctpNet { |
|
23582
d5fa3327ab3a
8038177: Eliminate unnecessary dependency to sun.security.action
mchung
parents:
23010
diff
changeset
|
43 |
private static final String osName = AccessController.doPrivileged( |
d5fa3327ab3a
8038177: Eliminate unnecessary dependency to sun.security.action
mchung
parents:
23010
diff
changeset
|
44 |
(PrivilegedAction<String>) () -> System.getProperty("os.name")); |
2542 | 45 |
|
46 |
/* -- Miscellaneous SCTP utilities -- */ |
|
47 |
||
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
48 |
private static boolean IPv4MappedAddresses() { |
2542 | 49 |
if ("SunOS".equals(osName)) { |
50 |
/* Solaris supports IPv4Mapped Addresses with bindx */ |
|
51 |
return true; |
|
52 |
} /* else { //other OS/implementations */ |
|
53 |
||
54 |
/* lksctp/linux requires Ipv4 addresses */ |
|
55 |
return false; |
|
56 |
} |
|
57 |
||
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
58 |
static boolean throwAlreadyBoundException() throws IOException { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
59 |
throw new AlreadyBoundException(); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
60 |
} |
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 |
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
|
63 |
listen0(fd, backlog); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
64 |
} |
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 |
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
|
67 |
throws IOException { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
68 |
return connect0(fd, remote, remotePort); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
69 |
} |
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 |
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
|
72 |
close0(fd); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
73 |
} |
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 |
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
|
76 |
preClose0(fd); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
77 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
78 |
|
2542 | 79 |
/** |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
80 |
* @param oneToOne |
2542 | 81 |
* if {@code true} returns a one-to-one sctp socket, otherwise |
82 |
* returns a one-to-many sctp socket |
|
83 |
*/ |
|
84 |
static FileDescriptor socket(boolean oneToOne) throws IOException { |
|
85 |
int nativefd = socket0(oneToOne); |
|
86 |
return IOUtil.newFD(nativefd); |
|
87 |
} |
|
88 |
||
89 |
static void bindx(int fd, InetAddress[] addrs, int port, boolean add) |
|
90 |
throws IOException { |
|
91 |
bindx(fd, addrs, port, addrs.length, add, |
|
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
92 |
IPv4MappedAddresses()); |
2542 | 93 |
} |
94 |
||
95 |
static Set<SocketAddress> getLocalAddresses(int fd) |
|
96 |
throws IOException { |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
97 |
Set<SocketAddress> set = null; |
2542 | 98 |
SocketAddress[] saa = getLocalAddresses0(fd); |
99 |
||
100 |
if (saa != null) { |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
101 |
set = getRevealedLocalAddressSet(saa); |
2542 | 102 |
} |
103 |
||
104 |
return set; |
|
105 |
} |
|
106 |
||
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
107 |
private static Set<SocketAddress> getRevealedLocalAddressSet( |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
108 |
SocketAddress[] saa) |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
109 |
{ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
110 |
SecurityManager sm = System.getSecurityManager(); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
111 |
Set<SocketAddress> set = new HashSet<>(saa.length); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
112 |
for (SocketAddress sa : saa) { |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
113 |
set.add(getRevealedLocalAddress(sa, sm)); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
114 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
115 |
return set; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
116 |
} |
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 |
private static SocketAddress getRevealedLocalAddress(SocketAddress sa, |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
119 |
SecurityManager sm) |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
120 |
{ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
121 |
if (sm == null || sa == null) |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
122 |
return sa; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
123 |
InetSocketAddress ia = (InetSocketAddress)sa; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
124 |
try{ |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
125 |
sm.checkConnect(ia.getAddress().getHostAddress(), -1); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
126 |
// Security check passed |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
127 |
} catch (SecurityException e) { |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
128 |
// Return loopback address |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
129 |
return new InetSocketAddress(InetAddress.getLoopbackAddress(), |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
130 |
ia.getPort()); |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
131 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
132 |
return sa; |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
133 |
} |
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
14342
diff
changeset
|
134 |
|
2542 | 135 |
static Set<SocketAddress> getRemoteAddresses(int fd, int assocId) |
136 |
throws IOException { |
|
137 |
HashSet<SocketAddress> set = null; |
|
138 |
SocketAddress[] saa = getRemoteAddresses0(fd, assocId); |
|
139 |
||
140 |
if (saa != null) { |
|
141 |
set = new HashSet<SocketAddress>(saa.length); |
|
142 |
for (SocketAddress sa : saa) |
|
143 |
set.add(sa); |
|
144 |
} |
|
145 |
||
146 |
return set; |
|
147 |
} |
|
148 |
||
10137
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
149 |
static <T> void setSocketOption(int fd, |
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
150 |
SctpSocketOption<T> name, |
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
151 |
T value, |
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
152 |
int assocId) |
2542 | 153 |
throws IOException { |
154 |
if (value == null) |
|
155 |
throw new IllegalArgumentException("Invalid option value"); |
|
156 |
||
157 |
if (name.equals(SCTP_INIT_MAXSTREAMS)) { |
|
158 |
InitMaxStreams maxStreamValue = (InitMaxStreams)value; |
|
159 |
SctpNet.setInitMsgOption0(fd, |
|
160 |
maxStreamValue.maxInStreams(), maxStreamValue.maxOutStreams()); |
|
161 |
} else if (name.equals(SCTP_PRIMARY_ADDR) || |
|
162 |
name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) { |
|
163 |
||
164 |
SocketAddress addr = (SocketAddress) value; |
|
165 |
if (addr == null) |
|
166 |
throw new IllegalArgumentException("Invalid option value"); |
|
167 |
||
168 |
Net.checkAddress(addr); |
|
169 |
InetSocketAddress netAddr = (InetSocketAddress)addr; |
|
170 |
||
171 |
if (name.equals(SCTP_PRIMARY_ADDR)) { |
|
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
172 |
setPrimAddrOption0(fd, |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
173 |
assocId, |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
174 |
netAddr.getAddress(), |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
175 |
netAddr.getPort()); |
2542 | 176 |
} else { |
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
177 |
setPeerPrimAddrOption0(fd, |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
178 |
assocId, |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
179 |
netAddr.getAddress(), |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
180 |
netAddr.getPort(), |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
5506
diff
changeset
|
181 |
IPv4MappedAddresses()); |
2542 | 182 |
} |
183 |
} else if (name.equals(SCTP_DISABLE_FRAGMENTS) || |
|
184 |
name.equals(SCTP_EXPLICIT_COMPLETE) || |
|
185 |
name.equals(SCTP_FRAGMENT_INTERLEAVE) || |
|
186 |
name.equals(SCTP_NODELAY) || |
|
187 |
name.equals(SO_SNDBUF) || |
|
188 |
name.equals(SO_RCVBUF) || |
|
189 |
name.equals(SO_LINGER)) { |
|
190 |
setIntOption(fd, name, value); |
|
191 |
} else { |
|
192 |
throw new AssertionError("Unknown socket option"); |
|
193 |
} |
|
194 |
} |
|
195 |
||
10137
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
196 |
static Object getSocketOption(int fd, SctpSocketOption<?> name, int assocId) |
2542 | 197 |
throws IOException { |
198 |
if (name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) { |
|
199 |
throw new IllegalArgumentException( |
|
200 |
"SCTP_SET_PEER_PRIMARY_ADDR cannot be retrieved"); |
|
201 |
} else if (name.equals(SCTP_INIT_MAXSTREAMS)) { |
|
202 |
/* container for holding maxIn/Out streams */ |
|
203 |
int[] values = new int[2]; |
|
204 |
SctpNet.getInitMsgOption0(fd, values); |
|
205 |
return InitMaxStreams.create(values[0], values[1]); |
|
206 |
} else if (name.equals(SCTP_PRIMARY_ADDR)) { |
|
207 |
return getPrimAddrOption0(fd, assocId); |
|
208 |
} else if (name.equals(SCTP_DISABLE_FRAGMENTS) || |
|
209 |
name.equals(SCTP_EXPLICIT_COMPLETE) || |
|
210 |
name.equals(SCTP_FRAGMENT_INTERLEAVE) || |
|
211 |
name.equals(SCTP_NODELAY) || |
|
212 |
name.equals(SO_SNDBUF) || |
|
213 |
name.equals(SO_RCVBUF) || |
|
214 |
name.equals(SO_LINGER)) { |
|
215 |
return getIntOption(fd, name); |
|
216 |
} else { |
|
217 |
throw new AssertionError("Unknown socket option"); |
|
218 |
} |
|
219 |
} |
|
220 |
||
10137
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
221 |
static void setIntOption(int fd, SctpSocketOption<?> name, Object value) |
2542 | 222 |
throws IOException { |
223 |
if (value == null) |
|
224 |
throw new IllegalArgumentException("Invalid option value"); |
|
225 |
||
226 |
Class<?> type = name.type(); |
|
227 |
if (type != Integer.class && type != Boolean.class) |
|
228 |
throw new AssertionError("Should not reach here"); |
|
229 |
||
230 |
if (name == SO_RCVBUF || |
|
231 |
name == SO_SNDBUF) |
|
232 |
{ |
|
233 |
int i = ((Integer)value).intValue(); |
|
234 |
if (i < 0) |
|
235 |
throw new IllegalArgumentException( |
|
236 |
"Invalid send/receive buffer size"); |
|
237 |
} else if (name == SO_LINGER) { |
|
238 |
int i = ((Integer)value).intValue(); |
|
239 |
if (i < 0) |
|
240 |
value = Integer.valueOf(-1); |
|
241 |
if (i > 65535) |
|
242 |
value = Integer.valueOf(65535); |
|
243 |
} else if (name.equals(SCTP_FRAGMENT_INTERLEAVE)) { |
|
244 |
int i = ((Integer)value).intValue(); |
|
245 |
if (i < 0 || i > 2) |
|
246 |
throw new IllegalArgumentException( |
|
247 |
"Invalid value for SCTP_FRAGMENT_INTERLEAVE"); |
|
248 |
} |
|
249 |
||
250 |
int arg; |
|
251 |
if (type == Integer.class) { |
|
252 |
arg = ((Integer)value).intValue(); |
|
253 |
} else { |
|
254 |
boolean b = ((Boolean)value).booleanValue(); |
|
255 |
arg = (b) ? 1 : 0; |
|
256 |
} |
|
257 |
||
258 |
setIntOption0(fd, ((SctpStdSocketOption)name).constValue(), arg); |
|
259 |
} |
|
260 |
||
10137
d92637d3d673
7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9679
diff
changeset
|
261 |
static Object getIntOption(int fd, SctpSocketOption<?> name) |
2542 | 262 |
throws IOException { |
263 |
Class<?> type = name.type(); |
|
264 |
||
265 |
if (type != Integer.class && type != Boolean.class) |
|
266 |
throw new AssertionError("Should not reach here"); |
|
267 |
||
268 |
if (!(name instanceof SctpStdSocketOption)) |
|
269 |
throw new AssertionError("Should not reach here"); |
|
270 |
||
271 |
int value = getIntOption0(fd, |
|
272 |
((SctpStdSocketOption)name).constValue()); |
|
273 |
||
274 |
if (type == Integer.class) { |
|
275 |
return Integer.valueOf(value); |
|
276 |
} else { |
|
277 |
return (value == 0) ? Boolean.FALSE : Boolean.TRUE; |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
static void shutdown(int fd, int assocId) |
|
282 |
throws IOException { |
|
283 |
shutdown0(fd, assocId); |
|
284 |
} |
|
285 |
||
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
286 |
static FileDescriptor branch(int fd, int assocId) throws IOException { |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
287 |
int nativefd = branch0(fd, assocId); |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
288 |
return IOUtil.newFD(nativefd); |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
289 |
} |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
290 |
|
2542 | 291 |
/* Native Methods */ |
292 |
static native int socket0(boolean oneToOne) throws IOException; |
|
293 |
||
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
294 |
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
|
295 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
296 |
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
|
297 |
throws IOException; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
298 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
299 |
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
|
300 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
301 |
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
|
302 |
|
2542 | 303 |
static native void bindx(int fd, InetAddress[] addrs, int port, int length, |
304 |
boolean add, boolean preferIPv6) throws IOException; |
|
305 |
||
306 |
static native int getIntOption0(int fd, int opt) throws IOException; |
|
307 |
||
308 |
static native void setIntOption0(int fd, int opt, int arg) |
|
309 |
throws IOException; |
|
310 |
||
311 |
static native SocketAddress[] getLocalAddresses0(int fd) throws IOException; |
|
312 |
||
313 |
static native SocketAddress[] getRemoteAddresses0(int fd, int assocId) |
|
314 |
throws IOException; |
|
315 |
||
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
316 |
static native int branch0(int fd, int assocId) throws IOException; |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
317 |
|
2542 | 318 |
static native void setPrimAddrOption0(int fd, int assocId, InetAddress ia, |
319 |
int port) throws IOException; |
|
320 |
||
321 |
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
|
322 |
InetAddress ia, int port, boolean preferIPv6) throws IOException; |
2542 | 323 |
|
324 |
static native SocketAddress getPrimAddrOption0(int fd, int assocId) |
|
325 |
throws IOException; |
|
326 |
||
327 |
/* retVals [0] maxInStreams, [1] maxOutStreams */ |
|
328 |
static native void getInitMsgOption0(int fd, int[] retVals) throws IOException; |
|
329 |
||
330 |
static native void setInitMsgOption0(int fd, int arg1, int arg2) |
|
331 |
throws IOException; |
|
332 |
||
333 |
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
|
334 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
335 |
static native void init(); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
336 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
337 |
static { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
338 |
init(); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
339 |
} |
2542 | 340 |
} |
341 |