50 |
|
|
51 |
#include "target_native.h" |
#include "target_native.h" |
52 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
53 |
#include "target_native_network.h" |
#include "target_native_network.h" |
54 |
#endif /* WITHOUT_NETWORK */ |
#endif /* WITHOUT_NETWORK */ |
55 |
|
|
56 |
#include "gnu_java_net_PlainDatagramSocketImpl.h" |
#include "gnu_java_net_PlainDatagramSocketImpl.h" |
67 |
* Creates a new datagram socket |
* Creates a new datagram socket |
68 |
*/ |
*/ |
69 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
70 |
Java_gnu_java_net_PlainDatagramSocketImpl_create(JNIEnv *env, jobject obj) |
Java_gnu_java_net_PlainDatagramSocketImpl_create (JNIEnv * env, jobject obj) |
71 |
{ |
{ |
72 |
assert(env!=NULL); |
assert (env != NULL); |
73 |
assert((*env)!=NULL); |
assert ((*env) != NULL); |
74 |
|
|
75 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
76 |
_javanet_create(env, obj, 0); |
_javanet_create (env, obj, 0); |
77 |
#else /* not WITHOUT_NETWORK */ |
#else /* not WITHOUT_NETWORK */ |
78 |
#endif /* not WITHOUT_NETWORK */ |
#endif /* not WITHOUT_NETWORK */ |
79 |
} |
} |
84 |
* Close the socket. |
* Close the socket. |
85 |
*/ |
*/ |
86 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
87 |
Java_gnu_java_net_PlainDatagramSocketImpl_close(JNIEnv *env, jobject obj) |
Java_gnu_java_net_PlainDatagramSocketImpl_close (JNIEnv * env, jobject obj) |
88 |
{ |
{ |
89 |
assert(env!=NULL); |
assert (env != NULL); |
90 |
assert((*env)!=NULL); |
assert ((*env) != NULL); |
91 |
|
|
92 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
93 |
_javanet_close(env, obj, 0); |
_javanet_close (env, obj, 0); |
94 |
#else /* not WITHOUT_NETWORK */ |
#else /* not WITHOUT_NETWORK */ |
95 |
#endif /* not WITHOUT_NETWORK */ |
#endif /* not WITHOUT_NETWORK */ |
96 |
} |
} |
103 |
* variables. |
* variables. |
104 |
*/ |
*/ |
105 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
106 |
Java_gnu_java_net_PlainDatagramSocketImpl_bind(JNIEnv *env, jobject obj, |
Java_gnu_java_net_PlainDatagramSocketImpl_bind (JNIEnv * env, jobject obj, |
107 |
jint port, jobject addr) |
jint port, jobject addr) |
108 |
{ |
{ |
109 |
assert(env!=NULL); |
assert (env != NULL); |
110 |
assert((*env)!=NULL); |
assert ((*env) != NULL); |
111 |
|
|
112 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
113 |
_javanet_bind(env, obj, addr, port, 0); |
_javanet_bind (env, obj, addr, port, 0); |
114 |
#else /* not WITHOUT_NETWORK */ |
#else /* not WITHOUT_NETWORK */ |
115 |
#endif /* not WITHOUT_NETWORK */ |
#endif /* not WITHOUT_NETWORK */ |
116 |
} |
} |
121 |
* This method sets the specified option for a socket |
* This method sets the specified option for a socket |
122 |
*/ |
*/ |
123 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
124 |
Java_gnu_java_net_PlainDatagramSocketImpl_setOption(JNIEnv *env, jobject obj, |
Java_gnu_java_net_PlainDatagramSocketImpl_setOption (JNIEnv * env, |
125 |
jint option_id, jobject val) |
jobject obj, |
126 |
|
jint option_id, |
127 |
|
jobject val) |
128 |
{ |
{ |
129 |
assert(env!=NULL); |
assert (env != NULL); |
130 |
assert((*env)!=NULL); |
assert ((*env) != NULL); |
131 |
|
|
132 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
133 |
_javanet_set_option(env, obj, option_id, val); |
_javanet_set_option (env, obj, option_id, val); |
134 |
#else /* not WITHOUT_NETWORK */ |
#else /* not WITHOUT_NETWORK */ |
135 |
#endif /* not WITHOUT_NETWORK */ |
#endif /* not WITHOUT_NETWORK */ |
136 |
} |
} |
141 |
* This method sets the specified option for a socket |
* This method sets the specified option for a socket |
142 |
*/ |
*/ |
143 |
JNIEXPORT jobject JNICALL |
JNIEXPORT jobject JNICALL |
144 |
Java_gnu_java_net_PlainDatagramSocketImpl_getOption(JNIEnv *env, jobject obj, |
Java_gnu_java_net_PlainDatagramSocketImpl_getOption (JNIEnv * env, |
145 |
jint option_id) |
jobject obj, |
146 |
|
jint option_id) |
147 |
{ |
{ |
148 |
assert(env!=NULL); |
assert (env != NULL); |
149 |
assert((*env)!=NULL); |
assert ((*env) != NULL); |
150 |
|
|
151 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
152 |
return(_javanet_get_option(env, obj, option_id)); |
return (_javanet_get_option (env, obj, option_id)); |
153 |
#else /* not WITHOUT_NETWORK */ |
#else /* not WITHOUT_NETWORK */ |
154 |
return NULL; |
return NULL; |
155 |
#endif /* not WITHOUT_NETWORK */ |
#endif /* not WITHOUT_NETWORK */ |
161 |
* Reads a buffer from a remote host |
* Reads a buffer from a remote host |
162 |
*/ |
*/ |
163 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
164 |
Java_gnu_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject obj, |
Java_gnu_java_net_PlainDatagramSocketImpl_receive0 (JNIEnv * env, jobject obj, |
165 |
jobject packet) |
jobject packet) |
166 |
{ |
{ |
167 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
168 |
int addr, port, bytes_read; |
int addr, port, bytes_read; |
169 |
unsigned int maxlen, offset; |
unsigned int maxlen, offset; |
170 |
jclass cls, addr_cls; |
jclass cls, addr_cls; |
171 |
jfieldID fid; |
jfieldID fid; |
172 |
jmethodID mid; |
jmethodID mid; |
173 |
jarray arr; |
jarray arr; |
174 |
unsigned char octets[4]; |
unsigned char octets[4]; |
175 |
char ip_str[16]; |
char ip_str[16]; |
176 |
jobject ip_str_obj, addr_obj; |
jobject ip_str_obj, addr_obj; |
177 |
|
|
178 |
assert(env!=NULL); |
assert (env != NULL); |
179 |
assert((*env)!=NULL); |
assert ((*env) != NULL); |
180 |
|
|
181 |
addr = 0; |
addr = 0; |
182 |
port = 0; |
port = 0; |
183 |
maxlen = 0; |
maxlen = 0; |
184 |
offset = 0; |
offset = 0; |
185 |
bytes_read = 0; |
bytes_read = 0; |
186 |
|
|
187 |
if(packet == NULL) |
if (packet == NULL) |
188 |
{ |
{ |
189 |
JCL_ThrowException(env, "java/lang/NullPointerException", "Null datagram packet"); |
JCL_ThrowException (env, "java/lang/NullPointerException", |
190 |
|
"Null datagram packet"); |
191 |
return; |
return; |
192 |
} |
} |
193 |
|
|
194 |
/* Get the buffer from the packet */ |
/* Get the buffer from the packet */ |
195 |
cls = (*env)->GetObjectClass(env, packet); |
cls = (*env)->GetObjectClass (env, packet); |
196 |
if (cls == NULL) |
if (cls == NULL) |
197 |
{ |
{ |
198 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error"); |
199 |
return; |
return; |
200 |
} |
} |
201 |
|
|
202 |
mid = (*env)->GetMethodID(env, cls, "getData", "()[B"); |
mid = (*env)->GetMethodID (env, cls, "getData", "()[B"); |
203 |
if (mid == NULL) |
if (mid == NULL) |
204 |
{ |
{ |
205 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: getData"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: getData"); |
206 |
return; |
return; |
207 |
} |
} |
208 |
|
|
209 |
arr = (*env)->CallObjectMethod(env, packet, mid); |
arr = (*env)->CallObjectMethod (env, packet, mid); |
210 |
if ((arr == NULL) || (*env)->ExceptionOccurred(env)) |
if ((arr == NULL) || (*env)->ExceptionOccurred (env)) |
211 |
{ |
{ |
212 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call getData"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: call getData"); |
213 |
return; |
return; |
214 |
} |
} |
215 |
|
|
216 |
/* Now get the offset from the packet */ |
/* Now get the offset from the packet */ |
217 |
mid = (*env)->GetMethodID(env, cls, "getOffset", "()I"); |
mid = (*env)->GetMethodID (env, cls, "getOffset", "()I"); |
218 |
if (mid == NULL) |
if (mid == NULL) |
219 |
{ |
{ |
220 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: getOffset"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: getOffset"); |
221 |
return; |
return; |
222 |
} |
} |
223 |
|
|
224 |
offset = (*env)->CallIntMethod(env, packet, mid); |
offset = (*env)->CallIntMethod (env, packet, mid); |
225 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
226 |
{ |
{ |
227 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call getOffset"); |
JCL_ThrowException (env, IO_EXCEPTION, |
228 |
|
"Internal error: call getOffset"); |
229 |
return; |
return; |
230 |
} |
} |
231 |
|
|
232 |
DBG("PlainDatagramSocketImpl.receive(): Got the offset\n"); |
DBG ("PlainDatagramSocketImpl.receive(): Got the offset\n"); |
233 |
|
|
234 |
/* Now get the maximal available length from the packet */ |
/* Now get the maximal available length from the packet */ |
235 |
fid = (*env)->GetFieldID(env, cls, "maxlen", "I"); |
fid = (*env)->GetFieldID (env, cls, "maxlen", "I"); |
236 |
if (fid == NULL) |
if (fid == NULL) |
237 |
{ |
{ |
238 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: maxlen"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: maxlen"); |
239 |
return; |
return; |
240 |
} |
} |
241 |
|
|
242 |
maxlen = (*env)->GetIntField (env, packet, fid); |
maxlen = (*env)->GetIntField (env, packet, fid); |
243 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
244 |
{ |
{ |
245 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call length"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: call length"); |
246 |
return; |
return; |
247 |
} |
} |
248 |
|
|
249 |
/* Receive the packet */ |
/* Receive the packet */ |
250 |
/* should we try some sort of validation on the length? */ |
/* should we try some sort of validation on the length? */ |
251 |
bytes_read = _javanet_recvfrom(env, obj, arr, offset, maxlen, &addr, &port); |
bytes_read = |
252 |
if ((bytes_read == -1) || (*env)->ExceptionOccurred(env)) |
_javanet_recvfrom (env, obj, arr, offset, maxlen, &addr, &port); |
253 |
|
if ((bytes_read == -1) || (*env)->ExceptionOccurred (env)) |
254 |
{ |
{ |
255 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: receive"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: receive"); |
256 |
return; |
return; |
257 |
} |
} |
258 |
|
|
259 |
DBG("PlainDatagramSocketImpl.receive(): Received packet\n"); |
DBG ("PlainDatagramSocketImpl.receive(): Received packet\n"); |
260 |
|
|
261 |
/* Store the address */ |
/* Store the address */ |
262 |
TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES(addr, |
TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES (addr, |
263 |
octets[0], |
octets[0], |
264 |
octets[1], |
octets[1], |
265 |
octets[2], |
octets[2], octets[3]); |
266 |
octets[3] |
sprintf (ip_str, "%d.%d.%d.%d", octets[0], octets[1], octets[2], octets[3]); |
267 |
); |
ip_str_obj = (*env)->NewStringUTF (env, ip_str); |
|
sprintf(ip_str, "%d.%d.%d.%d", |
|
|
octets[0], |
|
|
octets[1], |
|
|
octets[2], |
|
|
octets[3] |
|
|
); |
|
|
ip_str_obj = (*env)->NewStringUTF(env, ip_str); |
|
268 |
if (ip_str_obj == NULL) |
if (ip_str_obj == NULL) |
269 |
{ |
{ |
270 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: new string"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: new string"); |
271 |
return; |
return; |
272 |
} |
} |
273 |
|
|
274 |
addr_cls = (*env)->FindClass(env, "java/net/InetAddress"); |
addr_cls = (*env)->FindClass (env, "java/net/InetAddress"); |
275 |
if (addr_cls == NULL) |
if (addr_cls == NULL) |
276 |
{ |
{ |
277 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: InetAddress class"); |
JCL_ThrowException (env, IO_EXCEPTION, |
278 |
|
"Internal error: InetAddress class"); |
279 |
return; |
return; |
280 |
} |
} |
281 |
DBG("PlainDatagramSocketImpl.receive(): Found InetAddress class\n"); |
DBG ("PlainDatagramSocketImpl.receive(): Found InetAddress class\n"); |
282 |
|
|
283 |
mid = (*env)->GetStaticMethodID(env, addr_cls, "getByName", |
mid = (*env)->GetStaticMethodID (env, addr_cls, "getByName", |
284 |
"(Ljava/lang/String;)Ljava/net/InetAddress;"); |
"(Ljava/lang/String;)Ljava/net/InetAddress;"); |
285 |
if (mid == NULL) |
if (mid == NULL) |
286 |
{ |
{ |
287 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal Error"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal Error"); |
288 |
return; |
return; |
289 |
} |
} |
290 |
DBG("PlainDatagramSocketImpl.receive(): Found InetAddress.getByName method\n"); |
DBG |
291 |
|
("PlainDatagramSocketImpl.receive(): Found InetAddress.getByName method\n"); |
292 |
|
|
293 |
addr_obj = (*env)->CallStaticObjectMethod(env, addr_cls, mid, ip_str_obj); |
addr_obj = (*env)->CallStaticObjectMethod (env, addr_cls, mid, ip_str_obj); |
294 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
295 |
{ |
{ |
296 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call getByName"); |
JCL_ThrowException (env, IO_EXCEPTION, |
297 |
|
"Internal error: call getByName"); |
298 |
return; |
return; |
299 |
} |
} |
300 |
|
|
301 |
mid = (*env)->GetMethodID(env, cls, "setAddress", |
mid = (*env)->GetMethodID (env, cls, "setAddress", |
302 |
"(Ljava/net/InetAddress;)V"); |
"(Ljava/net/InetAddress;)V"); |
303 |
if (mid == NULL) |
if (mid == NULL) |
304 |
{ |
{ |
305 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: setAddress"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: setAddress"); |
306 |
return; |
return; |
307 |
} |
} |
308 |
|
|
309 |
(*env)->CallVoidMethod(env, packet, mid, addr_obj); |
(*env)->CallVoidMethod (env, packet, mid, addr_obj); |
310 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
311 |
{ |
{ |
312 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call setAddress"); |
JCL_ThrowException (env, IO_EXCEPTION, |
313 |
|
"Internal error: call setAddress"); |
314 |
return; |
return; |
315 |
} |
} |
316 |
|
|
317 |
DBG("PlainDatagramSocketImpl.receive(): Stored the address\n"); |
DBG ("PlainDatagramSocketImpl.receive(): Stored the address\n"); |
318 |
|
|
319 |
/* Store the port */ |
/* Store the port */ |
320 |
mid = (*env)->GetMethodID(env, cls, "setPort", "(I)V"); |
mid = (*env)->GetMethodID (env, cls, "setPort", "(I)V"); |
321 |
if (mid == NULL) |
if (mid == NULL) |
322 |
{ |
{ |
323 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: setPort"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: setPort"); |
324 |
return; |
return; |
325 |
} |
} |
326 |
|
|
327 |
(*env)->CallVoidMethod(env, packet, mid, port); |
(*env)->CallVoidMethod (env, packet, mid, port); |
328 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
329 |
{ |
{ |
330 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call setPort"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: call setPort"); |
331 |
return; |
return; |
332 |
} |
} |
333 |
|
|
334 |
DBG("PlainDatagramSocketImpl.receive(): Stored the port\n"); |
DBG ("PlainDatagramSocketImpl.receive(): Stored the port\n"); |
335 |
|
|
336 |
/* Store back the length */ |
/* Store back the length */ |
337 |
fid = (*env)->GetFieldID(env, cls, "length", "I"); |
fid = (*env)->GetFieldID (env, cls, "length", "I"); |
338 |
if (fid == NULL) |
if (fid == NULL) |
339 |
{ |
{ |
340 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: length"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: length"); |
341 |
return; |
return; |
342 |
} |
} |
343 |
|
|
344 |
(*env)->SetIntField (env, packet, fid, bytes_read); |
(*env)->SetIntField (env, packet, fid, bytes_read); |
345 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
346 |
{ |
{ |
347 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call length"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: call length"); |
348 |
return; |
return; |
349 |
} |
} |
350 |
|
|
351 |
DBG("PlainDatagramSocketImpl.receive(): Stored the length\n"); |
DBG ("PlainDatagramSocketImpl.receive(): Stored the length\n"); |
352 |
#else /* not WITHOUT_NETWORK */ |
#else /* not WITHOUT_NETWORK */ |
353 |
#endif /* not WITHOUT_NETWORK */ |
#endif /* not WITHOUT_NETWORK */ |
354 |
} |
} |
359 |
* Writes a buffer to the remote host |
* Writes a buffer to the remote host |
360 |
*/ |
*/ |
361 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
362 |
Java_gnu_java_net_PlainDatagramSocketImpl_sendto(JNIEnv *env, jobject obj, |
Java_gnu_java_net_PlainDatagramSocketImpl_sendto (JNIEnv * env, jobject obj, |
363 |
jobject addr, jint port, jarray buf, |
jobject addr, jint port, |
364 |
jint offset, jint len) |
jarray buf, jint offset, |
365 |
|
jint len) |
366 |
{ |
{ |
367 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
368 |
jint netAddress; |
jint netAddress; |
369 |
|
|
370 |
assert(env!=NULL); |
assert (env != NULL); |
371 |
assert((*env)!=NULL); |
assert ((*env) != NULL); |
372 |
|
|
373 |
netAddress = _javanet_get_netaddr(env, addr); |
netAddress = _javanet_get_netaddr (env, addr); |
374 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
375 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: get network address"); return; } |
{ |
376 |
|
JCL_ThrowException (env, IO_EXCEPTION, |
377 |
|
"Internal error: get network address"); |
378 |
|
return; |
379 |
|
} |
380 |
|
|
381 |
DBG("PlainDatagramSocketImpl.sendto(): have addr\n"); |
DBG ("PlainDatagramSocketImpl.sendto(): have addr\n"); |
382 |
|
|
383 |
_javanet_sendto(env, obj, buf, offset, len, netAddress, port); |
_javanet_sendto (env, obj, buf, offset, len, netAddress, port); |
384 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
385 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: send data"); return; } |
{ |
386 |
|
JCL_ThrowException (env, IO_EXCEPTION, "Internal error: send data"); |
387 |
|
return; |
388 |
|
} |
389 |
|
|
390 |
DBG("PlainDatagramSocketImpl.sendto(): finished\n"); |
DBG ("PlainDatagramSocketImpl.sendto(): finished\n"); |
391 |
#else /* not WITHOUT_NETWORK */ |
#else /* not WITHOUT_NETWORK */ |
392 |
#endif /* not WITHOUT_NETWORK */ |
#endif /* not WITHOUT_NETWORK */ |
393 |
} |
} |
398 |
* Joins a multicast group |
* Joins a multicast group |
399 |
*/ |
*/ |
400 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
401 |
Java_gnu_java_net_PlainDatagramSocketImpl_join(JNIEnv *env, jobject obj, |
Java_gnu_java_net_PlainDatagramSocketImpl_join (JNIEnv * env, jobject obj, |
402 |
jobject addr) |
jobject addr) |
403 |
{ |
{ |
404 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
405 |
jint netAddress; |
jint netAddress; |
406 |
int fd; |
int fd; |
407 |
int result; |
int result; |
408 |
|
|
409 |
assert(env!=NULL); |
assert (env != NULL); |
410 |
assert((*env)!=NULL); |
assert ((*env) != NULL); |
411 |
|
|
412 |
netAddress = _javanet_get_netaddr(env, addr); |
netAddress = _javanet_get_netaddr (env, addr); |
413 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
414 |
{ |
{ |
415 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error"); |
416 |
return; |
return; |
417 |
} |
} |
418 |
|
|
419 |
fd = _javanet_get_int_field(env, obj, "native_fd"); |
fd = _javanet_get_int_field (env, obj, "native_fd"); |
420 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
421 |
{ |
{ |
422 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error"); |
423 |
return; |
return; |
424 |
} |
} |
425 |
|
|
426 |
DBG("PlainDatagramSocketImpl.join(): have native fd\n"); |
DBG ("PlainDatagramSocketImpl.join(): have native fd\n"); |
427 |
|
|
428 |
TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP(fd,netAddress,result); |
TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP (fd, netAddress, |
429 |
|
result); |
430 |
|
|
431 |
if (result != TARGET_NATIVE_OK) |
if (result != TARGET_NATIVE_OK) |
432 |
{ |
{ |
433 |
JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING()); |
JCL_ThrowException (env, IO_EXCEPTION, |
434 |
|
TARGET_NATIVE_LAST_ERROR_STRING ()); |
435 |
return; |
return; |
436 |
} |
} |
437 |
|
|
438 |
DBG("PlainDatagramSocketImpl.join(): finished\n"); |
DBG ("PlainDatagramSocketImpl.join(): finished\n"); |
439 |
#else /* not WITHOUT_NETWORK */ |
#else /* not WITHOUT_NETWORK */ |
440 |
#endif /* not WITHOUT_NETWORK */ |
#endif /* not WITHOUT_NETWORK */ |
441 |
} |
} |
446 |
* Leaves a multicast group |
* Leaves a multicast group |
447 |
*/ |
*/ |
448 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
449 |
Java_gnu_java_net_PlainDatagramSocketImpl_leave(JNIEnv *env, jobject obj, |
Java_gnu_java_net_PlainDatagramSocketImpl_leave (JNIEnv * env, jobject obj, |
450 |
jobject addr) |
jobject addr) |
451 |
{ |
{ |
452 |
#ifndef WITHOUT_NETWORK |
#ifndef WITHOUT_NETWORK |
453 |
jint netAddress; |
jint netAddress; |
454 |
int fd; |
int fd; |
455 |
int result; |
int result; |
456 |
|
|
457 |
assert(env!=NULL); |
assert (env != NULL); |
458 |
assert((*env)!=NULL); |
assert ((*env) != NULL); |
459 |
|
|
460 |
netAddress = _javanet_get_netaddr(env, addr); |
netAddress = _javanet_get_netaddr (env, addr); |
461 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
462 |
{ |
{ |
463 |
JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); |
JCL_ThrowException (env, IO_EXCEPTION, "Internal error"); |
464 |
return; |
return; |
465 |
} |
} |
466 |
|
|
467 |
fd = _javanet_get_int_field(env, obj, "native_fd"); |
fd = _javanet_get_int_field (env, obj, "native_fd"); |
468 |
if ((*env)->ExceptionOccurred(env)) |
if ((*env)->ExceptionOccurred (env)) |
469 |
{ JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } |
{ |
470 |
|
JCL_ThrowException (env, IO_EXCEPTION, "Internal error"); |
471 |
|
return; |
472 |
|
} |
473 |
|
|
474 |
DBG("PlainDatagramSocketImpl.leave(): have native fd\n"); |
DBG ("PlainDatagramSocketImpl.leave(): have native fd\n"); |
475 |
|
|
476 |
TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_DROP_MEMBERSHIP(fd,netAddress,result); |
TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_DROP_MEMBERSHIP (fd, netAddress, |
477 |
if (result!=TARGET_NATIVE_OK) |
result); |
478 |
|
if (result != TARGET_NATIVE_OK) |
479 |
{ |
{ |
480 |
JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING()); |
JCL_ThrowException (env, IO_EXCEPTION, |
481 |
|
TARGET_NATIVE_LAST_ERROR_STRING ()); |
482 |
return; |
return; |
483 |
} |
} |
484 |
|
|
485 |
DBG("PlainDatagramSocketImpl.leave(): finished\n"); |
DBG ("PlainDatagramSocketImpl.leave(): finished\n"); |
486 |
#else /* not WITHOUT_NETWORK */ |
#else /* not WITHOUT_NETWORK */ |
487 |
#endif /* not WITHOUT_NETWORK */ |
#endif /* not WITHOUT_NETWORK */ |
488 |
} |
} |
|
|
|