author | chegar |
Mon, 11 Jan 2010 16:04:05 +0000 | |
changeset 4669 | 11d1dbd3598d |
parent 3072 | a801b122142f |
child 4675 | 68f287672813 |
permissions | -rw-r--r-- |
2542 | 1 |
/* |
2 |
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
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" |
|
37 |
#include "sun_nio_ch_SctpNet.h" |
|
38 |
#include "sun_nio_ch_SctpStdSocketOption.h" |
|
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 |
||
113 |
/* |
|
114 |
* Class: sun_nio_ch_SctpNet |
|
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
115 |
* Method: init |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
116 |
* Signature: ()V |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
117 |
*/ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
118 |
JNIEXPORT void JNICALL |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
119 |
Java_sun_nio_ch_SctpNet_init |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
120 |
(JNIEnv *env, jclass cl) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
121 |
int sp[2]; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
122 |
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
|
123 |
JNU_ThrowIOExceptionWithLastError(env, "socketpair failed"); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
124 |
return; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
125 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
126 |
preCloseFD = sp[0]; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
127 |
close(sp[1]); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
128 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
129 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
130 |
/* |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
131 |
* Class: sun_nio_ch_SctpNet |
2542 | 132 |
* Method: socket0 |
133 |
* Signature: (Z)I |
|
134 |
*/ |
|
135 |
JNIEXPORT jint JNICALL Java_sun_nio_ch_SctpNet_socket0 |
|
136 |
(JNIEnv *env, jclass klass, jboolean oneToOne) { |
|
137 |
int fd; |
|
138 |
struct sctp_event_subscribe event; |
|
139 |
||
140 |
/* Try to load the socket API extension functions */ |
|
141 |
if (!funcsLoaded && !loadSocketExtensionFuncs(env)) { |
|
142 |
return 0; |
|
143 |
} |
|
144 |
||
145 |
fd = socket(ipv6_available() ? AF_INET6 : AF_INET, |
|
146 |
(oneToOne ? SOCK_STREAM : SOCK_SEQPACKET), IPPROTO_SCTP); |
|
147 |
||
148 |
if (fd < 0) { |
|
149 |
return handleSocketError(env, errno); |
|
150 |
} |
|
151 |
||
152 |
/* Enable events */ |
|
153 |
memset(&event, 0, sizeof(event)); |
|
154 |
event.sctp_data_io_event = 1; |
|
155 |
event.sctp_association_event = 1; |
|
156 |
event.sctp_address_event = 1; |
|
157 |
event.sctp_send_failure_event = 1; |
|
158 |
//event.sctp_peer_error_event = 1; |
|
159 |
event.sctp_shutdown_event = 1; |
|
160 |
//event.sctp_partial_delivery_event = 1; |
|
161 |
//event.sctp_adaptation_layer_event = 1; |
|
162 |
if (setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(event)) != 0) { |
|
163 |
handleSocketError(env, errno); |
|
164 |
} |
|
165 |
return fd; |
|
166 |
} |
|
167 |
||
168 |
/* |
|
169 |
* Class: sun_nio_ch_SctpNet |
|
170 |
* Method: bindx |
|
171 |
* Signature: (I[Ljava/net/InetAddress;IIZ)V |
|
172 |
*/ |
|
173 |
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_bindx |
|
174 |
(JNIEnv *env, jclass klass, jint fd, jobjectArray addrs, jint port, |
|
175 |
jint addrsLength, jboolean add, jboolean preferIPv6) { |
|
176 |
SOCKADDR *sap, *tmpSap; |
|
177 |
int i, sa_len = sizeof(SOCKADDR); |
|
178 |
jobject ia; |
|
179 |
||
180 |
if (addrsLength < 1) |
|
181 |
return; |
|
182 |
||
183 |
if ((sap = calloc(addrsLength, sa_len)) == NULL) { |
|
184 |
JNU_ThrowOutOfMemoryError(env, "heap allocation failure"); |
|
185 |
return; |
|
186 |
} |
|
187 |
||
188 |
tmpSap = sap; |
|
189 |
for (i=0; i<addrsLength; i++) { |
|
190 |
ia = (*env)->GetObjectArrayElement(env, addrs, i); |
|
191 |
if (NET_InetAddressToSockaddr(env, ia, port, (struct sockaddr*)tmpSap, |
|
192 |
&sa_len, preferIPv6) != 0) { |
|
193 |
free(sap); |
|
194 |
return; |
|
195 |
} |
|
196 |
tmpSap++; |
|
197 |
} |
|
198 |
||
199 |
if (nio_sctp_bindx(fd, (void*)sap, addrsLength, add ? SCTP_BINDX_ADD_ADDR : |
|
200 |
SCTP_BINDX_REM_ADDR) != 0) { |
|
201 |
handleSocketError(env, errno); |
|
202 |
} |
|
203 |
||
204 |
free(sap); |
|
205 |
} |
|
206 |
||
4669
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
207 |
/* |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
208 |
* Class: sun_nio_ch_SctpNet |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
209 |
* Method: listen0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
210 |
* Signature: (II)V |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
211 |
*/ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
212 |
JNIEXPORT void JNICALL |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
213 |
Java_sun_nio_ch_SctpNet_listen0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
214 |
(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
|
215 |
if (listen(fd, backlog) < 0) |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
216 |
handleSocketError(env, errno); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
217 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
218 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
219 |
/* |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
220 |
* Class: sun_nio_ch_SctpNet |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
221 |
* Method: connect0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
222 |
* Signature: (ILjava/net/InetAddress;I)I |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
223 |
*/ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
224 |
JNIEXPORT jint JNICALL |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
225 |
Java_sun_nio_ch_SctpNet_connect0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
226 |
(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
|
227 |
SOCKADDR sa; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
228 |
int sa_len = SOCKADDR_LEN; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
229 |
int rv; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
230 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
231 |
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
|
232 |
&sa_len, JNI_TRUE) != 0) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
233 |
return IOS_THROWN; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
234 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
235 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
236 |
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
|
237 |
if (rv != 0) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
238 |
if (errno == EINPROGRESS) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
239 |
return IOS_UNAVAILABLE; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
240 |
} else if (errno == EINTR) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
241 |
return IOS_INTERRUPTED; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
242 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
243 |
return handleSocketError(env, errno); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
244 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
245 |
return 1; |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
246 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
247 |
|
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 |
* Class: sun_nio_ch_SctpNet |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
250 |
* Method: close0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
251 |
* Signature: (I)V |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
252 |
*/ |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
253 |
JNIEXPORT void JNICALL |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
254 |
Java_sun_nio_ch_SctpNet_close0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
255 |
(JNIEnv *env, jclass clazz, jint fd) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
256 |
if (fd != -1) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
257 |
int rv = close(fd); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
258 |
if (rv < 0) |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
259 |
JNU_ThrowIOExceptionWithLastError(env, "Close failed"); |
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 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
262 |
|
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
263 |
/* |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
264 |
* Class: sun_nio_ch_SctpNet |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
265 |
* Method: preClose0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
266 |
* Signature: (I)V |
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 |
JNIEXPORT void JNICALL |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
269 |
Java_sun_nio_ch_SctpNet_preClose0 |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
270 |
(JNIEnv *env, jclass clazz, jint fd) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
271 |
if (preCloseFD >= 0) { |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
272 |
if (dup2(preCloseFD, fd) < 0) |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
273 |
JNU_ThrowIOExceptionWithLastError(env, "dup2 failed"); |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
274 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
275 |
} |
11d1dbd3598d
6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents:
3072
diff
changeset
|
276 |
|
2542 | 277 |
void initializeISA |
278 |
(JNIEnv* env) { |
|
279 |
if (isaCls == 0) { |
|
280 |
jclass c = (*env)->FindClass(env, "java/net/InetSocketAddress"); |
|
281 |
CHECK_NULL(c); |
|
282 |
isaCls = (*env)->NewGlobalRef(env, c); |
|
283 |
CHECK_NULL(isaCls); |
|
284 |
(*env)->DeleteLocalRef(env, c); |
|
285 |
isaCtrID = (*env)->GetMethodID(env, isaCls, "<init>", |
|
286 |
"(Ljava/net/InetAddress;I)V"); |
|
287 |
} |
|
288 |
} |
|
289 |
||
290 |
jobject SockAddrToInetSocketAddress |
|
291 |
(JNIEnv *env, struct sockaddr* sap) { |
|
292 |
int port = 0; |
|
293 |
||
294 |
jobject ia = NET_SockaddrToInetAddress(env, sap, &port); |
|
295 |
if (ia == NULL) |
|
296 |
return NULL; |
|
297 |
||
298 |
if (isaCls == 0) { |
|
299 |
initializeISA(env); |
|
300 |
CHECK_NULL_RETURN(isaCls, NULL); |
|
301 |
} |
|
302 |
||
303 |
return (*env)->NewObject(env, isaCls, isaCtrID, ia, port); |
|
304 |
} |
|
305 |
||
306 |
/* |
|
307 |
* Class: sun_nio_ch_SctpNet |
|
308 |
* Method: getLocalAddresses0 |
|
309 |
* Signature: (I)[Ljava/net/SocketAddress; |
|
310 |
*/ |
|
311 |
JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_SctpNet_getLocalAddresses0 |
|
312 |
(JNIEnv *env, jclass klass, jint fd) { |
|
313 |
void *addr_buf, *laddr; |
|
314 |
struct sockaddr* sap; |
|
315 |
int i, addrCount; |
|
316 |
jobjectArray isaa; |
|
317 |
||
318 |
#ifdef __solaris__ |
|
319 |
if ((addrCount = nio_sctp_getladdrs(fd, 0, (void **)&addr_buf)) == -1) { |
|
320 |
#else /* __linux__ */ |
|
321 |
if ((addrCount = nio_sctp_getladdrs(fd, 0, (struct sockaddr **)&addr_buf)) == -1) { |
|
322 |
#endif |
|
323 |
handleSocketError(env, errno); |
|
324 |
return NULL; |
|
325 |
} |
|
326 |
||
327 |
if (addrCount < 1) |
|
328 |
return NULL; |
|
329 |
||
330 |
if (isaCls == 0) { |
|
331 |
initializeISA(env); |
|
332 |
CHECK_NULL_RETURN(isaCls, NULL); |
|
333 |
} |
|
334 |
||
335 |
isaa = (*env)->NewObjectArray(env, addrCount, isaCls, NULL); |
|
336 |
if (isaa == NULL) { |
|
337 |
nio_sctp_freeladdrs(addr_buf); |
|
338 |
return NULL; |
|
339 |
} |
|
340 |
||
341 |
laddr = addr_buf; |
|
342 |
for (i=0; i<addrCount; i++) { |
|
343 |
int port = 0; |
|
344 |
jobject isa = NULL, ia; |
|
345 |
sap = (struct sockaddr*)addr_buf; |
|
346 |
ia = NET_SockaddrToInetAddress(env, sap, &port); |
|
347 |
if (ia != NULL) |
|
348 |
isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port); |
|
349 |
if (isa != NULL) |
|
350 |
(*env)->SetObjectArrayElement(env, isaa, i, isa); |
|
351 |
||
352 |
if (sap->sa_family == AF_INET) |
|
353 |
addr_buf = ((struct sockaddr_in*)addr_buf) + 1; |
|
354 |
else |
|
355 |
addr_buf = ((struct sockaddr_in6*)addr_buf) + 1; |
|
356 |
} |
|
357 |
||
358 |
nio_sctp_freeladdrs(laddr); |
|
359 |
return isaa; |
|
360 |
} |
|
361 |
||
362 |
jobjectArray getRemoteAddresses |
|
363 |
(JNIEnv *env, jint fd, sctp_assoc_t id) { |
|
364 |
void *addr_buf, *paddr; |
|
365 |
struct sockaddr* sap; |
|
366 |
int i, addrCount; |
|
367 |
jobjectArray isaa; |
|
368 |
||
369 |
#if __solaris__ |
|
370 |
if ((addrCount = nio_sctp_getpaddrs(fd, id, (void **)&addr_buf)) == -1) { |
|
371 |
#else /* __linux__ */ |
|
372 |
if ((addrCount = nio_sctp_getpaddrs(fd, id, (struct sockaddr**)&addr_buf)) == -1) { |
|
373 |
#endif |
|
374 |
handleSocketError(env, errno); |
|
375 |
return NULL; |
|
376 |
} |
|
377 |
||
378 |
if (addrCount < 1) |
|
379 |
return NULL; |
|
380 |
||
381 |
if (isaCls == 0) { |
|
382 |
initializeISA(env); |
|
383 |
CHECK_NULL_RETURN(isaCls, NULL); |
|
384 |
} |
|
385 |
||
386 |
isaa = (*env)->NewObjectArray(env, addrCount, isaCls, NULL); |
|
387 |
if (isaa == NULL) { |
|
388 |
nio_sctp_freepaddrs(addr_buf); |
|
389 |
return NULL; |
|
390 |
} |
|
391 |
||
392 |
paddr = addr_buf; |
|
393 |
for (i=0; i<addrCount; i++) { |
|
394 |
jobject ia, isa = NULL; |
|
395 |
int port; |
|
396 |
sap = (struct sockaddr*)addr_buf; |
|
397 |
ia = NET_SockaddrToInetAddress(env, sap, &port); |
|
398 |
if (ia != NULL) |
|
399 |
isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port); |
|
400 |
if (isa != NULL) |
|
401 |
(*env)->SetObjectArrayElement(env, isaa, i, isa); |
|
402 |
||
403 |
if (sap->sa_family == AF_INET) |
|
404 |
addr_buf = ((struct sockaddr_in*)addr_buf) + 1; |
|
405 |
else |
|
406 |
addr_buf = ((struct sockaddr_in6*)addr_buf) + 1; |
|
407 |
} |
|
408 |
||
409 |
nio_sctp_freepaddrs(paddr); |
|
410 |
||
411 |
return isaa; |
|
412 |
} |
|
413 |
||
414 |
/* |
|
415 |
* Class: sun_nio_ch_SctpNet |
|
416 |
* Method: getRemoteAddresses0 |
|
417 |
* Signature: (II)[Ljava/net/SocketAddress; |
|
418 |
*/ |
|
419 |
JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_SctpNet_getRemoteAddresses0 |
|
420 |
(JNIEnv *env, jclass klass, jint fd, jint assocId) { |
|
421 |
return getRemoteAddresses(env, fd, assocId); |
|
422 |
} |
|
423 |
||
424 |
/* Map the Java level option to the native level */ |
|
425 |
int mapSocketOption |
|
426 |
(jint cmd, int *level, int *optname) { |
|
427 |
static struct { |
|
428 |
jint cmd; |
|
429 |
int level; |
|
430 |
int optname; |
|
431 |
} const opts[] = { |
|
432 |
{ sun_nio_ch_SctpStdSocketOption_SCTP_DISABLE_FRAGMENTS, IPPROTO_SCTP, SCTP_DISABLE_FRAGMENTS }, |
|
433 |
{ sun_nio_ch_SctpStdSocketOption_SCTP_EXPLICIT_COMPLETE, IPPROTO_SCTP, SCTP_EXPLICIT_EOR }, |
|
434 |
{ sun_nio_ch_SctpStdSocketOption_SCTP_FRAGMENT_INTERLEAVE, IPPROTO_SCTP, SCTP_FRAGMENT_INTERLEAVE }, |
|
435 |
{ sun_nio_ch_SctpStdSocketOption_SCTP_NODELAY, IPPROTO_SCTP, SCTP_NODELAY }, |
|
436 |
{ sun_nio_ch_SctpStdSocketOption_SO_SNDBUF, SOL_SOCKET, SO_SNDBUF }, |
|
437 |
{ sun_nio_ch_SctpStdSocketOption_SO_RCVBUF, SOL_SOCKET, SO_RCVBUF }, |
|
438 |
{ sun_nio_ch_SctpStdSocketOption_SO_LINGER, SOL_SOCKET, SO_LINGER } }; |
|
439 |
||
440 |
int i; |
|
441 |
for (i=0; i<(int)(sizeof(opts) / sizeof(opts[0])); i++) { |
|
442 |
if (cmd == opts[i].cmd) { |
|
443 |
*level = opts[i].level; |
|
444 |
*optname = opts[i].optname; |
|
445 |
return 0; |
|
446 |
} |
|
447 |
} |
|
448 |
||
449 |
/* not found */ |
|
450 |
return -1; |
|
451 |
} |
|
452 |
||
453 |
/* |
|
454 |
* Class: sun_nio_ch_SctpNet |
|
455 |
* Method: setIntOption0 |
|
456 |
* Signature: (III)V |
|
457 |
*/ |
|
458 |
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setIntOption0 |
|
459 |
(JNIEnv *env, jclass klass, jint fd, jint opt, int arg) { |
|
460 |
int klevel, kopt; |
|
461 |
int result; |
|
462 |
struct linger linger; |
|
463 |
void *parg; |
|
464 |
int arglen; |
|
465 |
||
466 |
if (mapSocketOption(opt, &klevel, &kopt) < 0) { |
|
467 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
468 |
"Unsupported socket option"); |
|
469 |
return; |
|
470 |
} |
|
471 |
||
472 |
if (opt == sun_nio_ch_SctpStdSocketOption_SO_LINGER) { |
|
473 |
parg = (void *)&linger; |
|
474 |
arglen = sizeof(linger); |
|
475 |
if (arg >= 0) { |
|
476 |
linger.l_onoff = 1; |
|
477 |
linger.l_linger = arg; |
|
478 |
} else { |
|
479 |
linger.l_onoff = 0; |
|
480 |
linger.l_linger = 0; |
|
481 |
} |
|
482 |
} else { |
|
483 |
parg = (void *)&arg; |
|
484 |
arglen = sizeof(arg); |
|
485 |
} |
|
486 |
||
487 |
if (setsockopt(fd, klevel, kopt, parg, arglen) < 0) { |
|
488 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
489 |
"sun_nio_ch_SctpNet.setIntOption0"); |
|
490 |
} |
|
491 |
} |
|
492 |
||
493 |
/* |
|
494 |
* Class: sun_nio_ch_SctpNet |
|
495 |
* Method: getIntOption0 |
|
496 |
* Signature: (II)I |
|
497 |
*/ |
|
498 |
JNIEXPORT int JNICALL Java_sun_nio_ch_SctpNet_getIntOption0 |
|
499 |
(JNIEnv *env, jclass klass, jint fd, jint opt) { |
|
500 |
int klevel, kopt; |
|
501 |
int result; |
|
502 |
struct linger linger; |
|
503 |
void *arg; |
|
504 |
unsigned int arglen; |
|
505 |
||
506 |
if (mapSocketOption(opt, &klevel, &kopt) < 0) { |
|
507 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
508 |
"Unsupported socket option"); |
|
509 |
return -1; |
|
510 |
} |
|
511 |
||
512 |
if (opt == sun_nio_ch_SctpStdSocketOption_SO_LINGER) { |
|
513 |
arg = (void *)&linger; |
|
514 |
arglen = sizeof(linger); |
|
515 |
} else { |
|
516 |
arg = (void *)&result; |
|
517 |
arglen = sizeof(result); |
|
518 |
} |
|
519 |
||
520 |
if (getsockopt(fd, klevel, kopt, arg, &arglen) < 0) { |
|
521 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
522 |
"sun.nio.ch.Net.getIntOption"); |
|
523 |
return -1; |
|
524 |
} |
|
525 |
||
526 |
if (opt == sun_nio_ch_SctpStdSocketOption_SO_LINGER) |
|
527 |
return linger.l_onoff ? linger.l_linger : -1; |
|
528 |
else |
|
529 |
return result; |
|
530 |
} |
|
531 |
||
532 |
/* |
|
533 |
* Class: sun_nio_ch_SctpNet |
|
534 |
* Method: getPrimAddrOption0 |
|
535 |
* Signature: (II)Ljava/net/SocketAddress; |
|
536 |
*/ |
|
537 |
JNIEXPORT jobject JNICALL Java_sun_nio_ch_SctpNet_getPrimAddrOption0 |
|
538 |
(JNIEnv *env, jclass klass, jint fd, jint assocId) { |
|
539 |
struct sctp_setprim prim; |
|
540 |
unsigned int prim_len = sizeof(prim); |
|
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
541 |
struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr; |
2542 | 542 |
|
543 |
prim.ssp_assoc_id = assocId; |
|
544 |
||
545 |
if (getsockopt(fd, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &prim, &prim_len) < 0) { |
|
546 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
547 |
"sun.nio.ch.SctpNet.getPrimAddrOption0"); |
|
548 |
return NULL; |
|
549 |
} |
|
550 |
||
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
551 |
return SockAddrToInetSocketAddress(env, sap); |
2542 | 552 |
} |
553 |
||
554 |
/* |
|
555 |
* Class: sun_nio_ch_SctpNet |
|
556 |
* Method: setPrimAddrOption0 |
|
557 |
* Signature: (IILjava/net/InetAddress;I)V |
|
558 |
*/ |
|
559 |
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setPrimAddrOption0 |
|
560 |
(JNIEnv *env, jclass klass, jint fd, jint assocId, jobject iaObj, jint port) { |
|
561 |
struct sctp_setprim prim; |
|
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
562 |
struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr; |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
563 |
int sap_len; |
2542 | 564 |
|
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
565 |
if (NET_InetAddressToSockaddr(env, iaObj, port, sap, |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
566 |
&sap_len, JNI_TRUE) != 0) { |
2542 | 567 |
return; |
568 |
} |
|
569 |
||
570 |
prim.ssp_assoc_id = assocId; |
|
571 |
||
572 |
if (setsockopt(fd, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &prim, sizeof(prim)) < 0) { |
|
573 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
574 |
"sun.nio.ch.SctpNet.setPrimAddrOption0"); |
|
575 |
} |
|
576 |
} |
|
577 |
||
578 |
/* |
|
579 |
* Class: sun_nio_ch_SctpNet |
|
580 |
* Method: setPeerPrimAddrOption0 |
|
581 |
* Signature: (IILjava/net/InetAddress;I)V |
|
582 |
*/ |
|
583 |
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setPeerPrimAddrOption0 |
|
584 |
(JNIEnv *env, jclass klass, jint fd, jint assocId, jobject iaObj, jint port) { |
|
585 |
struct sctp_setpeerprim prim; |
|
586 |
struct sockaddr_storage ss; |
|
587 |
int ss_len = sizeof(ss); |
|
588 |
||
589 |
if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&ss, |
|
590 |
&ss_len, JNI_TRUE) != 0) { |
|
591 |
return; |
|
592 |
} |
|
593 |
||
594 |
prim.sspp_assoc_id = assocId; |
|
595 |
prim.sspp_addr = ss; |
|
596 |
||
597 |
if (setsockopt(fd, IPPROTO_SCTP, SCTP_SET_PEER_PRIMARY_ADDR, &prim, |
|
598 |
sizeof(prim)) < 0) { |
|
599 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
600 |
"sun.nio.ch.SctpNet.setPeerPrimAddrOption0"); |
|
601 |
} |
|
602 |
} |
|
603 |
||
604 |
/* |
|
605 |
* Class: sun_nio_ch_SctpNet |
|
606 |
* Method: getInitMsgOption0 |
|
607 |
* Signature: (I[I)V |
|
608 |
*/ |
|
609 |
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_getInitMsgOption0 |
|
610 |
(JNIEnv *env, jclass klass, jint fd, jintArray retVal) { |
|
611 |
struct sctp_initmsg sctp_initmsg; |
|
612 |
unsigned int sim_len = sizeof(sctp_initmsg); |
|
613 |
int vals[2]; |
|
614 |
||
615 |
if (getsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &sctp_initmsg, |
|
616 |
&sim_len) < 0) { |
|
617 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
618 |
"sun.nio.ch.SctpNet.getInitMsgOption0"); |
|
619 |
return; |
|
620 |
} |
|
621 |
||
622 |
vals[0] = sctp_initmsg.sinit_max_instreams; |
|
623 |
vals[1] = sctp_initmsg.sinit_num_ostreams; |
|
624 |
(*env)->SetIntArrayRegion(env, retVal, 0, 2, vals); |
|
625 |
} |
|
626 |
||
627 |
/* |
|
628 |
* Class: sun_nio_ch_SctpNet |
|
629 |
* Method: setInitMsgOption0 |
|
630 |
* Signature: (III)V |
|
631 |
*/ |
|
632 |
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setInitMsgOption0 |
|
633 |
(JNIEnv *env, jclass klass, jint fd, jint inArg, jint outArg) { |
|
634 |
struct sctp_initmsg sctp_initmsg; |
|
635 |
||
636 |
sctp_initmsg.sinit_max_instreams = (unsigned int)inArg; |
|
637 |
sctp_initmsg.sinit_num_ostreams = (unsigned int)outArg; |
|
638 |
sctp_initmsg.sinit_max_attempts = 0; // default |
|
639 |
sctp_initmsg.sinit_max_init_timeo = 0; // default |
|
640 |
||
641 |
if (setsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &sctp_initmsg, |
|
642 |
sizeof(sctp_initmsg)) < 0) { |
|
643 |
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", |
|
644 |
"sun.nio.ch.SctpNet.setInitMsgOption0"); |
|
645 |
} |
|
646 |
} |
|
647 |
||
648 |
/* |
|
649 |
* Class: sun_nio_ch_SctpNet |
|
650 |
* Method: shutdown0 |
|
651 |
* Signature: (II)V |
|
652 |
*/ |
|
653 |
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_shutdown0 |
|
654 |
(JNIEnv *env, jclass klass, jint fd, jint assocId) { |
|
655 |
int rv; |
|
656 |
struct msghdr msg[1]; |
|
657 |
struct iovec iov[1]; |
|
658 |
int cbuf_size = CMSG_SPACE(sizeof (struct sctp_sndrcvinfo)); |
|
659 |
char cbuf[CMSG_SPACE(sizeof (struct sctp_sndrcvinfo))]; |
|
660 |
struct cmsghdr* cmsg; |
|
661 |
struct sctp_sndrcvinfo *sri; |
|
662 |
||
663 |
/* SctpSocketChannel */ |
|
664 |
if (assocId < 0) { |
|
665 |
shutdown(fd, SHUT_WR); |
|
666 |
return; |
|
667 |
} |
|
668 |
||
669 |
memset(msg, 0, sizeof (*msg)); |
|
670 |
memset(cbuf, 0, cbuf_size); |
|
671 |
msg->msg_name = NULL; |
|
672 |
msg->msg_namelen = 0; |
|
673 |
iov->iov_base = NULL; |
|
674 |
iov->iov_len = 0; |
|
675 |
msg->msg_iov = iov; |
|
676 |
msg->msg_iovlen = 1; |
|
677 |
msg->msg_control = cbuf; |
|
678 |
msg->msg_controllen = cbuf_size; |
|
679 |
msg->msg_flags = 0; |
|
680 |
||
681 |
cmsg = CMSG_FIRSTHDR(msg); |
|
682 |
cmsg->cmsg_level = IPPROTO_SCTP; |
|
683 |
cmsg->cmsg_type = SCTP_SNDRCV; |
|
684 |
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); |
|
685 |
||
686 |
/* Initialize the payload: */ |
|
687 |
sri = (struct sctp_sndrcvinfo*) CMSG_DATA(cmsg); |
|
688 |
memset(sri, 0, sizeof (*sri)); |
|
689 |
||
690 |
if (assocId > 0) { |
|
691 |
sri->sinfo_assoc_id = assocId; |
|
692 |
} |
|
693 |
||
694 |
sri->sinfo_flags = sri->sinfo_flags | SCTP_EOF; |
|
695 |
||
696 |
/* Sum of the length of all control messages in the buffer. */ |
|
697 |
msg->msg_controllen = cmsg->cmsg_len; |
|
698 |
||
699 |
if ((rv = sendmsg(fd, msg, 0)) < 0) { |
|
700 |
handleSocketError(env, errno); |
|
701 |
} |
|
702 |
} |
|
703 |
||
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
704 |
/* |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
705 |
* Class: sun_nio_ch_SctpNet |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
706 |
* Method: branch |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
707 |
* Signature: (II)I |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
708 |
*/ |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
709 |
JNIEXPORT int JNICALL Java_sun_nio_ch_SctpNet_branch0 |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
710 |
(JNIEnv *env, jclass klass, jint fd, jint assocId) { |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
711 |
int newfd = 0; |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
712 |
if ((newfd = nio_sctp_peeloff(fd, assocId)) < 0) { |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
713 |
handleSocketError(env, errno); |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
714 |
} |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
715 |
|
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
716 |
return newfd; |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
717 |
} |