author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 22646 | jdk/src/solaris/native/sun/nio/ch/sctp/SctpNet.c@5fa3669fd35d |
child 28680 | 79674c06a625 |
permissions | -rw-r--r-- |
2542 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
11823
diff
changeset
|
2 |
* Copyright (c) 2009, 2012, 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 |
*/ |
25 |
||
26 |
#include <stdlib.h> |
|
27 |
#include <string.h> |
|
28 |
#include <dlfcn.h> |
|
29 |
||
30 |
#include "Sctp.h" |
|
31 |
#include "jni.h" |
|
32 |
#include "jni_util.h" |
|
33 |
#include "nio_util.h" |
|
34 |
#include "nio.h" |
|
35 |
#include "net_util.h" |
|
36 |
#include "net_util_md.h" |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
37 |
#include "sun_nio_ch_sctp_SctpNet.h" |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
38 |
#include "sun_nio_ch_sctp_SctpStdSocketOption.h" |
2542 | 39 |
|
40 |
static jclass isaCls = 0; |
|
41 |
static jmethodID isaCtrID = 0; |
|
42 |
||
43 |
static const char* nativeSctpLib = "libsctp.so.1"; |
|
44 |
static jboolean funcsLoaded = JNI_FALSE; |
|
45 |
||
46 |
JNIEXPORT jint JNICALL JNI_OnLoad |
|
47 |
(JavaVM *vm, void *reserved) { |
|
48 |
return JNI_VERSION_1_2; |
|
49 |
} |
|
50 |
||
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
51 |
static int preCloseFD = -1; /* File descriptor to which we dup other fd's |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
52 |
before closing them for real */ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
53 |
|
2542 | 54 |
/** |
55 |
* Loads the native sctp library that contains the socket extension |
|
56 |
* functions, as well as locating the individual functions. |
|
57 |
* There will be a pending exception if this method returns false. |
|
58 |
*/ |
|
59 |
jboolean loadSocketExtensionFuncs |
|
60 |
(JNIEnv* env) { |
|
61 |
if (dlopen(nativeSctpLib, RTLD_GLOBAL | RTLD_LAZY) == NULL) { |
|
62 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
|
63 |
dlerror()); |
|
64 |
return JNI_FALSE; |
|
65 |
} |
|
66 |
||
67 |
if ((nio_sctp_getladdrs = (sctp_getladdrs_func*) |
|
68 |
dlsym(RTLD_DEFAULT, "sctp_getladdrs")) == NULL) { |
|
69 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
|
70 |
dlerror()); |
|
71 |
return JNI_FALSE; |
|
72 |
} |
|
73 |
||
74 |
if ((nio_sctp_freeladdrs = (sctp_freeladdrs_func*) |
|
75 |
dlsym(RTLD_DEFAULT, "sctp_freeladdrs")) == NULL) { |
|
76 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
|
77 |
dlerror()); |
|
78 |
return JNI_FALSE; |
|
79 |
} |
|
80 |
||
81 |
if ((nio_sctp_getpaddrs = (sctp_getpaddrs_func*) |
|
82 |
dlsym(RTLD_DEFAULT, "sctp_getpaddrs")) == NULL) { |
|
83 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
|
84 |
dlerror()); |
|
85 |
return JNI_FALSE; |
|
86 |
} |
|
87 |
||
88 |
if ((nio_sctp_freepaddrs = (sctp_freepaddrs_func*) |
|
89 |
dlsym(RTLD_DEFAULT, "sctp_freepaddrs")) == NULL) { |
|
90 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
|
91 |
dlerror()); |
|
92 |
return JNI_FALSE; |
|
93 |
} |
|
94 |
||
95 |
if ((nio_sctp_bindx = (sctp_bindx_func*) |
|
96 |
dlsym(RTLD_DEFAULT, "sctp_bindx")) == NULL) { |
|
97 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
|
98 |
dlerror()); |
|
99 |
return JNI_FALSE; |
|
100 |
} |
|
101 |
||
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
102 |
if ((nio_sctp_peeloff = (sctp_peeloff_func*) |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
103 |
dlsym(RTLD_DEFAULT, "sctp_peeloff")) == NULL) { |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
104 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
105 |
dlerror()); |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
106 |
return JNI_FALSE; |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
107 |
} |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
108 |
|
2542 | 109 |
funcsLoaded = JNI_TRUE; |
110 |
return JNI_TRUE; |
|
111 |
} |
|
112 |
||
4678
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
113 |
jint |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
114 |
handleSocketError(JNIEnv *env, jint errorValue) |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
115 |
{ |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
116 |
char *xn; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
117 |
switch (errorValue) { |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
118 |
case EINPROGRESS: /* Non-blocking connect */ |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
119 |
return 0; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
120 |
case EPROTO: |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
121 |
xn= JNU_JAVANETPKG "ProtocolException"; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
122 |
break; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
123 |
case ECONNREFUSED: |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
124 |
xn = JNU_JAVANETPKG "ConnectException"; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
125 |
break; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
126 |
case ETIMEDOUT: |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
127 |
xn = JNU_JAVANETPKG "ConnectException"; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
128 |
break; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
129 |
case EHOSTUNREACH: |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
130 |
xn = JNU_JAVANETPKG "NoRouteToHostException"; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
131 |
break; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
132 |
case EADDRINUSE: /* Fall through */ |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
133 |
case EADDRNOTAVAIL: |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
134 |
xn = JNU_JAVANETPKG "BindException"; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
135 |
break; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
136 |
default: |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
137 |
xn = JNU_JAVANETPKG "SocketException"; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
138 |
break; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
139 |
} |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
140 |
errno = errorValue; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
141 |
JNU_ThrowByNameWithLastError(env, xn, "NioSocketError"); |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
142 |
return IOS_THROWN; |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
143 |
} |
99fdf34405de
6917317: (sctp) Remove dependency on handleSocketError
chegar
parents:
4675
diff
changeset
|
144 |
|
2542 | 145 |
/* |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
146 |
* Class: sun_nio_ch_sctp_SctpNet |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
147 |
* Method: init |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
148 |
* Signature: ()V |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
149 |
*/ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
150 |
JNIEXPORT void JNICALL |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
151 |
Java_sun_nio_ch_sctp_SctpNet_init |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
152 |
(JNIEnv *env, jclass cl) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
153 |
int sp[2]; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
154 |
if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) < 0) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
155 |
JNU_ThrowIOExceptionWithLastError(env, "socketpair failed"); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
156 |
return; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
157 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
158 |
preCloseFD = sp[0]; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
159 |
close(sp[1]); |
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
22631
diff
changeset
|
160 |
initInetAddressIDs(env); |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
161 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
162 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
163 |
/* |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
164 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 165 |
* Method: socket0 |
166 |
* Signature: (Z)I |
|
167 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
168 |
JNIEXPORT jint JNICALL Java_sun_nio_ch_sctp_SctpNet_socket0 |
2542 | 169 |
(JNIEnv *env, jclass klass, jboolean oneToOne) { |
170 |
int fd; |
|
171 |
struct sctp_event_subscribe event; |
|
4814 | 172 |
#ifdef AF_INET6 |
173 |
int domain = ipv6_available() ? AF_INET6 : AF_INET; |
|
174 |
#else |
|
175 |
int domain = AF_INET; |
|
176 |
#endif |
|
2542 | 177 |
|
178 |
/* Try to load the socket API extension functions */ |
|
179 |
if (!funcsLoaded && !loadSocketExtensionFuncs(env)) { |
|
180 |
return 0; |
|
181 |
} |
|
182 |
||
4814 | 183 |
fd = socket(domain, (oneToOne ? SOCK_STREAM : SOCK_SEQPACKET), IPPROTO_SCTP); |
2542 | 184 |
|
185 |
if (fd < 0) { |
|
186 |
return handleSocketError(env, errno); |
|
187 |
} |
|
188 |
||
189 |
/* Enable events */ |
|
190 |
memset(&event, 0, sizeof(event)); |
|
191 |
event.sctp_data_io_event = 1; |
|
192 |
event.sctp_association_event = 1; |
|
193 |
event.sctp_address_event = 1; |
|
194 |
event.sctp_send_failure_event = 1; |
|
195 |
//event.sctp_peer_error_event = 1; |
|
196 |
event.sctp_shutdown_event = 1; |
|
197 |
//event.sctp_partial_delivery_event = 1; |
|
198 |
//event.sctp_adaptation_layer_event = 1; |
|
199 |
if (setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(event)) != 0) { |
|
200 |
handleSocketError(env, errno); |
|
201 |
} |
|
202 |
return fd; |
|
203 |
} |
|
204 |
||
205 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
206 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 207 |
* Method: bindx |
208 |
* Signature: (I[Ljava/net/InetAddress;IIZ)V |
|
209 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
210 |
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_bindx |
2542 | 211 |
(JNIEnv *env, jclass klass, jint fd, jobjectArray addrs, jint port, |
212 |
jint addrsLength, jboolean add, jboolean preferIPv6) { |
|
213 |
SOCKADDR *sap, *tmpSap; |
|
214 |
int i, sa_len = sizeof(SOCKADDR); |
|
215 |
jobject ia; |
|
216 |
||
217 |
if (addrsLength < 1) |
|
218 |
return; |
|
219 |
||
220 |
if ((sap = calloc(addrsLength, sa_len)) == NULL) { |
|
221 |
JNU_ThrowOutOfMemoryError(env, "heap allocation failure"); |
|
222 |
return; |
|
223 |
} |
|
224 |
||
225 |
tmpSap = sap; |
|
226 |
for (i=0; i<addrsLength; i++) { |
|
227 |
ia = (*env)->GetObjectArrayElement(env, addrs, i); |
|
228 |
if (NET_InetAddressToSockaddr(env, ia, port, (struct sockaddr*)tmpSap, |
|
229 |
&sa_len, preferIPv6) != 0) { |
|
230 |
free(sap); |
|
231 |
return; |
|
232 |
} |
|
233 |
tmpSap++; |
|
234 |
} |
|
235 |
||
236 |
if (nio_sctp_bindx(fd, (void*)sap, addrsLength, add ? SCTP_BINDX_ADD_ADDR : |
|
237 |
SCTP_BINDX_REM_ADDR) != 0) { |
|
238 |
handleSocketError(env, errno); |
|
239 |
} |
|
240 |
||
241 |
free(sap); |
|
242 |
} |
|
243 |
||
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
244 |
/* |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
245 |
* Class: sun_nio_ch_sctp_SctpNet |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
246 |
* Method: listen0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
247 |
* Signature: (II)V |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
248 |
*/ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
249 |
JNIEXPORT void JNICALL |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
250 |
Java_sun_nio_ch_sctp_SctpNet_listen0 |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
251 |
(JNIEnv *env, jclass cl, jint fd, jint backlog) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
252 |
if (listen(fd, backlog) < 0) |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
253 |
handleSocketError(env, errno); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
254 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
255 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
256 |
/* |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
257 |
* Class: sun_nio_ch_sctp_SctpNet |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
258 |
* Method: connect0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
259 |
* Signature: (ILjava/net/InetAddress;I)I |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
260 |
*/ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
261 |
JNIEXPORT jint JNICALL |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
262 |
Java_sun_nio_ch_sctp_SctpNet_connect0 |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
263 |
(JNIEnv *env, jclass clazz, int fd, jobject iao, jint port) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
264 |
SOCKADDR sa; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
265 |
int sa_len = SOCKADDR_LEN; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
266 |
int rv; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
267 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
268 |
if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *) &sa, |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
269 |
&sa_len, JNI_TRUE) != 0) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
270 |
return IOS_THROWN; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
271 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
272 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
273 |
rv = connect(fd, (struct sockaddr *)&sa, sa_len); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
274 |
if (rv != 0) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
275 |
if (errno == EINPROGRESS) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
276 |
return IOS_UNAVAILABLE; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
277 |
} else if (errno == EINTR) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
278 |
return IOS_INTERRUPTED; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
279 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
280 |
return handleSocketError(env, errno); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
281 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
282 |
return 1; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
283 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
284 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
285 |
/* |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
286 |
* Class: sun_nio_ch_sctp_SctpNet |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
287 |
* Method: close0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
288 |
* Signature: (I)V |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
289 |
*/ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
290 |
JNIEXPORT void JNICALL |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
291 |
Java_sun_nio_ch_sctp_SctpNet_close0 |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
292 |
(JNIEnv *env, jclass clazz, jint fd) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
293 |
if (fd != -1) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
294 |
int rv = close(fd); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
295 |
if (rv < 0) |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
296 |
JNU_ThrowIOExceptionWithLastError(env, "Close failed"); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
297 |
} |
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 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
300 |
/* |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
301 |
* Class: sun_nio_ch_sctp_SctpNet |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
302 |
* Method: preClose0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
303 |
* Signature: (I)V |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
304 |
*/ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
305 |
JNIEXPORT void JNICALL |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
306 |
Java_sun_nio_ch_sctp_SctpNet_preClose0 |
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
307 |
(JNIEnv *env, jclass clazz, jint fd) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
308 |
if (preCloseFD >= 0) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
309 |
if (dup2(preCloseFD, fd) < 0) |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
310 |
JNU_ThrowIOExceptionWithLastError(env, "dup2 failed"); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
311 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
312 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
313 |
|
2542 | 314 |
void initializeISA |
315 |
(JNIEnv* env) { |
|
316 |
if (isaCls == 0) { |
|
317 |
jclass c = (*env)->FindClass(env, "java/net/InetSocketAddress"); |
|
318 |
CHECK_NULL(c); |
|
319 |
isaCls = (*env)->NewGlobalRef(env, c); |
|
320 |
CHECK_NULL(isaCls); |
|
321 |
(*env)->DeleteLocalRef(env, c); |
|
322 |
isaCtrID = (*env)->GetMethodID(env, isaCls, "<init>", |
|
323 |
"(Ljava/net/InetAddress;I)V"); |
|
324 |
} |
|
325 |
} |
|
326 |
||
327 |
jobject SockAddrToInetSocketAddress |
|
328 |
(JNIEnv *env, struct sockaddr* sap) { |
|
329 |
int port = 0; |
|
330 |
||
331 |
jobject ia = NET_SockaddrToInetAddress(env, sap, &port); |
|
332 |
if (ia == NULL) |
|
333 |
return NULL; |
|
334 |
||
335 |
if (isaCls == 0) { |
|
336 |
initializeISA(env); |
|
337 |
CHECK_NULL_RETURN(isaCls, NULL); |
|
338 |
} |
|
339 |
||
340 |
return (*env)->NewObject(env, isaCls, isaCtrID, ia, port); |
|
341 |
} |
|
342 |
||
343 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
344 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 345 |
* Method: getLocalAddresses0 |
346 |
* Signature: (I)[Ljava/net/SocketAddress; |
|
347 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
348 |
JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_sctp_SctpNet_getLocalAddresses0 |
2542 | 349 |
(JNIEnv *env, jclass klass, jint fd) { |
350 |
void *addr_buf, *laddr; |
|
351 |
struct sockaddr* sap; |
|
352 |
int i, addrCount; |
|
353 |
jobjectArray isaa; |
|
354 |
||
355 |
#ifdef __solaris__ |
|
356 |
if ((addrCount = nio_sctp_getladdrs(fd, 0, (void **)&addr_buf)) == -1) { |
|
357 |
#else /* __linux__ */ |
|
358 |
if ((addrCount = nio_sctp_getladdrs(fd, 0, (struct sockaddr **)&addr_buf)) == -1) { |
|
359 |
#endif |
|
360 |
handleSocketError(env, errno); |
|
361 |
return NULL; |
|
362 |
} |
|
363 |
||
364 |
if (addrCount < 1) |
|
365 |
return NULL; |
|
366 |
||
367 |
if (isaCls == 0) { |
|
368 |
initializeISA(env); |
|
369 |
CHECK_NULL_RETURN(isaCls, NULL); |
|
370 |
} |
|
371 |
||
372 |
isaa = (*env)->NewObjectArray(env, addrCount, isaCls, NULL); |
|
373 |
if (isaa == NULL) { |
|
374 |
nio_sctp_freeladdrs(addr_buf); |
|
375 |
return NULL; |
|
376 |
} |
|
377 |
||
378 |
laddr = addr_buf; |
|
379 |
for (i=0; i<addrCount; i++) { |
|
380 |
int port = 0; |
|
381 |
jobject isa = NULL, ia; |
|
382 |
sap = (struct sockaddr*)addr_buf; |
|
383 |
ia = NET_SockaddrToInetAddress(env, sap, &port); |
|
384 |
if (ia != NULL) |
|
385 |
isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port); |
|
22631
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
14342
diff
changeset
|
386 |
if (isa == NULL) |
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
14342
diff
changeset
|
387 |
break; |
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
14342
diff
changeset
|
388 |
(*env)->SetObjectArrayElement(env, isaa, i, isa); |
2542 | 389 |
|
390 |
if (sap->sa_family == AF_INET) |
|
391 |
addr_buf = ((struct sockaddr_in*)addr_buf) + 1; |
|
392 |
else |
|
393 |
addr_buf = ((struct sockaddr_in6*)addr_buf) + 1; |
|
394 |
} |
|
395 |
||
396 |
nio_sctp_freeladdrs(laddr); |
|
397 |
return isaa; |
|
398 |
} |
|
399 |
||
400 |
jobjectArray getRemoteAddresses |
|
401 |
(JNIEnv *env, jint fd, sctp_assoc_t id) { |
|
402 |
void *addr_buf, *paddr; |
|
403 |
struct sockaddr* sap; |
|
404 |
int i, addrCount; |
|
405 |
jobjectArray isaa; |
|
406 |
||
407 |
#if __solaris__ |
|
408 |
if ((addrCount = nio_sctp_getpaddrs(fd, id, (void **)&addr_buf)) == -1) { |
|
409 |
#else /* __linux__ */ |
|
410 |
if ((addrCount = nio_sctp_getpaddrs(fd, id, (struct sockaddr**)&addr_buf)) == -1) { |
|
411 |
#endif |
|
412 |
handleSocketError(env, errno); |
|
413 |
return NULL; |
|
414 |
} |
|
415 |
||
416 |
if (addrCount < 1) |
|
417 |
return NULL; |
|
418 |
||
419 |
if (isaCls == 0) { |
|
420 |
initializeISA(env); |
|
421 |
CHECK_NULL_RETURN(isaCls, NULL); |
|
422 |
} |
|
423 |
||
424 |
isaa = (*env)->NewObjectArray(env, addrCount, isaCls, NULL); |
|
425 |
if (isaa == NULL) { |
|
426 |
nio_sctp_freepaddrs(addr_buf); |
|
427 |
return NULL; |
|
428 |
} |
|
429 |
||
430 |
paddr = addr_buf; |
|
431 |
for (i=0; i<addrCount; i++) { |
|
432 |
jobject ia, isa = NULL; |
|
433 |
int port; |
|
434 |
sap = (struct sockaddr*)addr_buf; |
|
435 |
ia = NET_SockaddrToInetAddress(env, sap, &port); |
|
436 |
if (ia != NULL) |
|
437 |
isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port); |
|
22631
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
14342
diff
changeset
|
438 |
if (isa == NULL) |
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
14342
diff
changeset
|
439 |
break; |
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
14342
diff
changeset
|
440 |
(*env)->SetObjectArrayElement(env, isaa, i, isa); |
2542 | 441 |
|
442 |
if (sap->sa_family == AF_INET) |
|
443 |
addr_buf = ((struct sockaddr_in*)addr_buf) + 1; |
|
444 |
else |
|
445 |
addr_buf = ((struct sockaddr_in6*)addr_buf) + 1; |
|
446 |
} |
|
447 |
||
448 |
nio_sctp_freepaddrs(paddr); |
|
449 |
||
450 |
return isaa; |
|
451 |
} |
|
452 |
||
453 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
454 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 455 |
* Method: getRemoteAddresses0 |
456 |
* Signature: (II)[Ljava/net/SocketAddress; |
|
457 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
458 |
JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_sctp_SctpNet_getRemoteAddresses0 |
2542 | 459 |
(JNIEnv *env, jclass klass, jint fd, jint assocId) { |
460 |
return getRemoteAddresses(env, fd, assocId); |
|
461 |
} |
|
462 |
||
463 |
/* Map the Java level option to the native level */ |
|
464 |
int mapSocketOption |
|
465 |
(jint cmd, int *level, int *optname) { |
|
466 |
static struct { |
|
467 |
jint cmd; |
|
468 |
int level; |
|
469 |
int optname; |
|
470 |
} const opts[] = { |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
471 |
{ sun_nio_ch_sctp_SctpStdSocketOption_SCTP_DISABLE_FRAGMENTS, IPPROTO_SCTP, SCTP_DISABLE_FRAGMENTS }, |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
472 |
{ sun_nio_ch_sctp_SctpStdSocketOption_SCTP_EXPLICIT_COMPLETE, IPPROTO_SCTP, SCTP_EXPLICIT_EOR }, |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
473 |
{ sun_nio_ch_sctp_SctpStdSocketOption_SCTP_FRAGMENT_INTERLEAVE, IPPROTO_SCTP, SCTP_FRAGMENT_INTERLEAVE }, |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
474 |
{ sun_nio_ch_sctp_SctpStdSocketOption_SCTP_NODELAY, IPPROTO_SCTP, SCTP_NODELAY }, |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
475 |
{ sun_nio_ch_sctp_SctpStdSocketOption_SO_SNDBUF, SOL_SOCKET, SO_SNDBUF }, |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
476 |
{ sun_nio_ch_sctp_SctpStdSocketOption_SO_RCVBUF, SOL_SOCKET, SO_RCVBUF }, |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
477 |
{ sun_nio_ch_sctp_SctpStdSocketOption_SO_LINGER, SOL_SOCKET, SO_LINGER } }; |
2542 | 478 |
|
479 |
int i; |
|
480 |
for (i=0; i<(int)(sizeof(opts) / sizeof(opts[0])); i++) { |
|
481 |
if (cmd == opts[i].cmd) { |
|
482 |
*level = opts[i].level; |
|
483 |
*optname = opts[i].optname; |
|
484 |
return 0; |
|
485 |
} |
|
486 |
} |
|
487 |
||
488 |
/* not found */ |
|
489 |
return -1; |
|
490 |
} |
|
491 |
||
492 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
493 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 494 |
* Method: setIntOption0 |
495 |
* Signature: (III)V |
|
496 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
497 |
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_setIntOption0 |
2542 | 498 |
(JNIEnv *env, jclass klass, jint fd, jint opt, int arg) { |
499 |
int klevel, kopt; |
|
500 |
int result; |
|
501 |
struct linger linger; |
|
502 |
void *parg; |
|
503 |
int arglen; |
|
504 |
||
505 |
if (mapSocketOption(opt, &klevel, &kopt) < 0) { |
|
506 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
507 |
"Unsupported socket option"); |
|
508 |
return; |
|
509 |
} |
|
510 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
511 |
if (opt == sun_nio_ch_sctp_SctpStdSocketOption_SO_LINGER) { |
2542 | 512 |
parg = (void *)&linger; |
513 |
arglen = sizeof(linger); |
|
514 |
if (arg >= 0) { |
|
515 |
linger.l_onoff = 1; |
|
516 |
linger.l_linger = arg; |
|
517 |
} else { |
|
518 |
linger.l_onoff = 0; |
|
519 |
linger.l_linger = 0; |
|
520 |
} |
|
521 |
} else { |
|
522 |
parg = (void *)&arg; |
|
523 |
arglen = sizeof(arg); |
|
524 |
} |
|
525 |
||
4675
68f287672813
6916922: (sctp) SO_RCVBUF & SO_SNDBUF returns twice the value set
chegar
parents:
4669
diff
changeset
|
526 |
if (NET_SetSockOpt(fd, klevel, kopt, parg, arglen) < 0) { |
2542 | 527 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
528 |
"sun_nio_ch_sctp_SctpNet.setIntOption0"); |
2542 | 529 |
} |
530 |
} |
|
531 |
||
532 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
533 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 534 |
* Method: getIntOption0 |
535 |
* Signature: (II)I |
|
536 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
537 |
JNIEXPORT int JNICALL Java_sun_nio_ch_sctp_SctpNet_getIntOption0 |
2542 | 538 |
(JNIEnv *env, jclass klass, jint fd, jint opt) { |
539 |
int klevel, kopt; |
|
540 |
int result; |
|
541 |
struct linger linger; |
|
542 |
void *arg; |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
543 |
int arglen; |
2542 | 544 |
|
545 |
if (mapSocketOption(opt, &klevel, &kopt) < 0) { |
|
546 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
547 |
"Unsupported socket option"); |
|
548 |
return -1; |
|
549 |
} |
|
550 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
551 |
if (opt == sun_nio_ch_sctp_SctpStdSocketOption_SO_LINGER) { |
2542 | 552 |
arg = (void *)&linger; |
553 |
arglen = sizeof(linger); |
|
554 |
} else { |
|
555 |
arg = (void *)&result; |
|
556 |
arglen = sizeof(result); |
|
557 |
} |
|
558 |
||
4675
68f287672813
6916922: (sctp) SO_RCVBUF & SO_SNDBUF returns twice the value set
chegar
parents:
4669
diff
changeset
|
559 |
if (NET_GetSockOpt(fd, klevel, kopt, arg, &arglen) < 0) { |
2542 | 560 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
561 |
"sun.nio.ch.Net.getIntOption"); |
|
562 |
return -1; |
|
563 |
} |
|
564 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
565 |
if (opt == sun_nio_ch_sctp_SctpStdSocketOption_SO_LINGER) |
2542 | 566 |
return linger.l_onoff ? linger.l_linger : -1; |
567 |
else |
|
568 |
return result; |
|
569 |
} |
|
570 |
||
571 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
572 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 573 |
* Method: getPrimAddrOption0 |
574 |
* Signature: (II)Ljava/net/SocketAddress; |
|
575 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
576 |
JNIEXPORT jobject JNICALL Java_sun_nio_ch_sctp_SctpNet_getPrimAddrOption0 |
2542 | 577 |
(JNIEnv *env, jclass klass, jint fd, jint assocId) { |
578 |
struct sctp_setprim prim; |
|
579 |
unsigned int prim_len = sizeof(prim); |
|
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
580 |
struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr; |
2542 | 581 |
|
582 |
prim.ssp_assoc_id = assocId; |
|
583 |
||
584 |
if (getsockopt(fd, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &prim, &prim_len) < 0) { |
|
585 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
586 |
"sun.nio.ch.SctpNet.getPrimAddrOption0"); |
|
587 |
return NULL; |
|
588 |
} |
|
589 |
||
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
590 |
return SockAddrToInetSocketAddress(env, sap); |
2542 | 591 |
} |
592 |
||
593 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
594 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 595 |
* Method: setPrimAddrOption0 |
596 |
* Signature: (IILjava/net/InetAddress;I)V |
|
597 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
598 |
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_setPrimAddrOption0 |
2542 | 599 |
(JNIEnv *env, jclass klass, jint fd, jint assocId, jobject iaObj, jint port) { |
600 |
struct sctp_setprim prim; |
|
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
601 |
struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr; |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
602 |
int sap_len; |
2542 | 603 |
|
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
604 |
if (NET_InetAddressToSockaddr(env, iaObj, port, sap, |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
605 |
&sap_len, JNI_TRUE) != 0) { |
2542 | 606 |
return; |
607 |
} |
|
608 |
||
609 |
prim.ssp_assoc_id = assocId; |
|
610 |
||
611 |
if (setsockopt(fd, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &prim, sizeof(prim)) < 0) { |
|
612 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
613 |
"sun.nio.ch.SctpNet.setPrimAddrOption0"); |
|
614 |
} |
|
615 |
} |
|
616 |
||
617 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
618 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 619 |
* Method: setPeerPrimAddrOption0 |
620 |
* Signature: (IILjava/net/InetAddress;I)V |
|
621 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
622 |
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_setPeerPrimAddrOption0 |
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
6850
diff
changeset
|
623 |
(JNIEnv *env, jclass klass, jint fd, jint assocId, |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
6850
diff
changeset
|
624 |
jobject iaObj, jint port, jboolean preferIPv6) { |
2542 | 625 |
struct sctp_setpeerprim prim; |
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
6850
diff
changeset
|
626 |
struct sockaddr* sap = (struct sockaddr*)&prim.sspp_addr; |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
6850
diff
changeset
|
627 |
int sap_len; |
2542 | 628 |
|
7545
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
6850
diff
changeset
|
629 |
if (NET_InetAddressToSockaddr(env, iaObj, port, sap, |
409091945418
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents:
6850
diff
changeset
|
630 |
&sap_len, preferIPv6) != 0) { |
2542 | 631 |
return; |
632 |
} |
|
633 |
||
634 |
prim.sspp_assoc_id = assocId; |
|
635 |
||
636 |
if (setsockopt(fd, IPPROTO_SCTP, SCTP_SET_PEER_PRIMARY_ADDR, &prim, |
|
637 |
sizeof(prim)) < 0) { |
|
638 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
639 |
"sun.nio.ch.SctpNet.setPeerPrimAddrOption0"); |
|
640 |
} |
|
641 |
} |
|
642 |
||
643 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
644 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 645 |
* Method: getInitMsgOption0 |
646 |
* Signature: (I[I)V |
|
647 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
648 |
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_getInitMsgOption0 |
2542 | 649 |
(JNIEnv *env, jclass klass, jint fd, jintArray retVal) { |
650 |
struct sctp_initmsg sctp_initmsg; |
|
651 |
unsigned int sim_len = sizeof(sctp_initmsg); |
|
652 |
int vals[2]; |
|
653 |
||
654 |
if (getsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &sctp_initmsg, |
|
655 |
&sim_len) < 0) { |
|
656 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
657 |
"sun.nio.ch.SctpNet.getInitMsgOption0"); |
|
658 |
return; |
|
659 |
} |
|
660 |
||
661 |
vals[0] = sctp_initmsg.sinit_max_instreams; |
|
662 |
vals[1] = sctp_initmsg.sinit_num_ostreams; |
|
663 |
(*env)->SetIntArrayRegion(env, retVal, 0, 2, vals); |
|
664 |
} |
|
665 |
||
666 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
667 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 668 |
* Method: setInitMsgOption0 |
669 |
* Signature: (III)V |
|
670 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
671 |
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_setInitMsgOption0 |
2542 | 672 |
(JNIEnv *env, jclass klass, jint fd, jint inArg, jint outArg) { |
673 |
struct sctp_initmsg sctp_initmsg; |
|
674 |
||
675 |
sctp_initmsg.sinit_max_instreams = (unsigned int)inArg; |
|
676 |
sctp_initmsg.sinit_num_ostreams = (unsigned int)outArg; |
|
677 |
sctp_initmsg.sinit_max_attempts = 0; // default |
|
678 |
sctp_initmsg.sinit_max_init_timeo = 0; // default |
|
679 |
||
680 |
if (setsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &sctp_initmsg, |
|
681 |
sizeof(sctp_initmsg)) < 0) { |
|
682 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
683 |
"sun.nio.ch.SctpNet.setInitMsgOption0"); |
|
684 |
} |
|
685 |
} |
|
686 |
||
687 |
/* |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
688 |
* Class: sun_nio_ch_sctp_SctpNet |
2542 | 689 |
* Method: shutdown0 |
690 |
* Signature: (II)V |
|
691 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
692 |
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_shutdown0 |
2542 | 693 |
(JNIEnv *env, jclass klass, jint fd, jint assocId) { |
694 |
int rv; |
|
695 |
struct msghdr msg[1]; |
|
696 |
struct iovec iov[1]; |
|
697 |
int cbuf_size = CMSG_SPACE(sizeof (struct sctp_sndrcvinfo)); |
|
698 |
char cbuf[CMSG_SPACE(sizeof (struct sctp_sndrcvinfo))]; |
|
699 |
struct cmsghdr* cmsg; |
|
700 |
struct sctp_sndrcvinfo *sri; |
|
701 |
||
702 |
/* SctpSocketChannel */ |
|
703 |
if (assocId < 0) { |
|
704 |
shutdown(fd, SHUT_WR); |
|
705 |
return; |
|
706 |
} |
|
707 |
||
708 |
memset(msg, 0, sizeof (*msg)); |
|
709 |
memset(cbuf, 0, cbuf_size); |
|
710 |
msg->msg_name = NULL; |
|
711 |
msg->msg_namelen = 0; |
|
712 |
iov->iov_base = NULL; |
|
713 |
iov->iov_len = 0; |
|
714 |
msg->msg_iov = iov; |
|
715 |
msg->msg_iovlen = 1; |
|
716 |
msg->msg_control = cbuf; |
|
717 |
msg->msg_controllen = cbuf_size; |
|
718 |
msg->msg_flags = 0; |
|
719 |
||
720 |
cmsg = CMSG_FIRSTHDR(msg); |
|
721 |
cmsg->cmsg_level = IPPROTO_SCTP; |
|
722 |
cmsg->cmsg_type = SCTP_SNDRCV; |
|
723 |
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); |
|
724 |
||
725 |
/* Initialize the payload: */ |
|
726 |
sri = (struct sctp_sndrcvinfo*) CMSG_DATA(cmsg); |
|
727 |
memset(sri, 0, sizeof (*sri)); |
|
728 |
||
729 |
if (assocId > 0) { |
|
730 |
sri->sinfo_assoc_id = assocId; |
|
731 |
} |
|
732 |
||
733 |
sri->sinfo_flags = sri->sinfo_flags | SCTP_EOF; |
|
734 |
||
735 |
/* Sum of the length of all control messages in the buffer. */ |
|
736 |
msg->msg_controllen = cmsg->cmsg_len; |
|
737 |
||
738 |
if ((rv = sendmsg(fd, msg, 0)) < 0) { |
|
739 |
handleSocketError(env, errno); |
|
740 |
} |
|
741 |
} |
|
742 |
||
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
743 |
/* |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
744 |
* Class: sun_nio_ch_sctp_SctpNet |
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
745 |
* Method: branch |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
746 |
* Signature: (II)I |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
747 |
*/ |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
7668
diff
changeset
|
748 |
JNIEXPORT int JNICALL Java_sun_nio_ch_sctp_SctpNet_branch0 |
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
749 |
(JNIEnv *env, jclass klass, jint fd, jint assocId) { |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
750 |
int newfd = 0; |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
751 |
if ((newfd = nio_sctp_peeloff(fd, assocId)) < 0) { |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
752 |
handleSocketError(env, errno); |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
753 |
} |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
754 |
|
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
755 |
return newfd; |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
756 |
} |