46 JNIEXPORT jint JNICALL JNI_OnLoad |
46 JNIEXPORT jint JNICALL JNI_OnLoad |
47 (JavaVM *vm, void *reserved) { |
47 (JavaVM *vm, void *reserved) { |
48 return JNI_VERSION_1_2; |
48 return JNI_VERSION_1_2; |
49 } |
49 } |
50 |
50 |
|
51 static int preCloseFD = -1; /* File descriptor to which we dup other fd's |
|
52 before closing them for real */ |
|
53 |
51 /** |
54 /** |
52 * Loads the native sctp library that contains the socket extension |
55 * Loads the native sctp library that contains the socket extension |
53 * functions, as well as locating the individual functions. |
56 * functions, as well as locating the individual functions. |
54 * There will be a pending exception if this method returns false. |
57 * There will be a pending exception if this method returns false. |
55 */ |
58 */ |
103 return JNI_FALSE; |
106 return JNI_FALSE; |
104 } |
107 } |
105 |
108 |
106 funcsLoaded = JNI_TRUE; |
109 funcsLoaded = JNI_TRUE; |
107 return JNI_TRUE; |
110 return JNI_TRUE; |
|
111 } |
|
112 |
|
113 /* |
|
114 * Class: sun_nio_ch_SctpNet |
|
115 * Method: init |
|
116 * Signature: ()V |
|
117 */ |
|
118 JNIEXPORT void JNICALL |
|
119 Java_sun_nio_ch_SctpNet_init |
|
120 (JNIEnv *env, jclass cl) { |
|
121 int sp[2]; |
|
122 if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) < 0) { |
|
123 JNU_ThrowIOExceptionWithLastError(env, "socketpair failed"); |
|
124 return; |
|
125 } |
|
126 preCloseFD = sp[0]; |
|
127 close(sp[1]); |
108 } |
128 } |
109 |
129 |
110 /* |
130 /* |
111 * Class: sun_nio_ch_SctpNet |
131 * Class: sun_nio_ch_SctpNet |
112 * Method: socket0 |
132 * Method: socket0 |
180 SCTP_BINDX_REM_ADDR) != 0) { |
200 SCTP_BINDX_REM_ADDR) != 0) { |
181 handleSocketError(env, errno); |
201 handleSocketError(env, errno); |
182 } |
202 } |
183 |
203 |
184 free(sap); |
204 free(sap); |
|
205 } |
|
206 |
|
207 /* |
|
208 * Class: sun_nio_ch_SctpNet |
|
209 * Method: listen0 |
|
210 * Signature: (II)V |
|
211 */ |
|
212 JNIEXPORT void JNICALL |
|
213 Java_sun_nio_ch_SctpNet_listen0 |
|
214 (JNIEnv *env, jclass cl, jint fd, jint backlog) { |
|
215 if (listen(fd, backlog) < 0) |
|
216 handleSocketError(env, errno); |
|
217 } |
|
218 |
|
219 /* |
|
220 * Class: sun_nio_ch_SctpNet |
|
221 * Method: connect0 |
|
222 * Signature: (ILjava/net/InetAddress;I)I |
|
223 */ |
|
224 JNIEXPORT jint JNICALL |
|
225 Java_sun_nio_ch_SctpNet_connect0 |
|
226 (JNIEnv *env, jclass clazz, int fd, jobject iao, jint port) { |
|
227 SOCKADDR sa; |
|
228 int sa_len = SOCKADDR_LEN; |
|
229 int rv; |
|
230 |
|
231 if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *) &sa, |
|
232 &sa_len, JNI_TRUE) != 0) { |
|
233 return IOS_THROWN; |
|
234 } |
|
235 |
|
236 rv = connect(fd, (struct sockaddr *)&sa, sa_len); |
|
237 if (rv != 0) { |
|
238 if (errno == EINPROGRESS) { |
|
239 return IOS_UNAVAILABLE; |
|
240 } else if (errno == EINTR) { |
|
241 return IOS_INTERRUPTED; |
|
242 } |
|
243 return handleSocketError(env, errno); |
|
244 } |
|
245 return 1; |
|
246 } |
|
247 |
|
248 /* |
|
249 * Class: sun_nio_ch_SctpNet |
|
250 * Method: close0 |
|
251 * Signature: (I)V |
|
252 */ |
|
253 JNIEXPORT void JNICALL |
|
254 Java_sun_nio_ch_SctpNet_close0 |
|
255 (JNIEnv *env, jclass clazz, jint fd) { |
|
256 if (fd != -1) { |
|
257 int rv = close(fd); |
|
258 if (rv < 0) |
|
259 JNU_ThrowIOExceptionWithLastError(env, "Close failed"); |
|
260 } |
|
261 } |
|
262 |
|
263 /* |
|
264 * Class: sun_nio_ch_SctpNet |
|
265 * Method: preClose0 |
|
266 * Signature: (I)V |
|
267 */ |
|
268 JNIEXPORT void JNICALL |
|
269 Java_sun_nio_ch_SctpNet_preClose0 |
|
270 (JNIEnv *env, jclass clazz, jint fd) { |
|
271 if (preCloseFD >= 0) { |
|
272 if (dup2(preCloseFD, fd) < 0) |
|
273 JNU_ThrowIOExceptionWithLastError(env, "dup2 failed"); |
|
274 } |
185 } |
275 } |
186 |
276 |
187 void initializeISA |
277 void initializeISA |
188 (JNIEnv* env) { |
278 (JNIEnv* env) { |
189 if (isaCls == 0) { |
279 if (isaCls == 0) { |