309 (JNIEnv* env, jobject resultContainerObj, struct sctp_paddr_change* spc) {
310 int event = 0;
311 jobject addressObj, resultObj;
312 unsigned int state = spc->spc_state;
313
314 switch (state) {
315 case SCTP_ADDR_AVAILABLE :
316 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_AVAILABLE;
317 break;
318 case SCTP_ADDR_UNREACHABLE :
319 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_UNREACHABLE;
320 break;
321 case SCTP_ADDR_REMOVED :
322 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_REMOVED;
323 break;
324 case SCTP_ADDR_ADDED :
325 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_ADDED;
326 break;
327 case SCTP_ADDR_MADE_PRIM :
328 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_MADE_PRIM;
329 #ifdef __linux__ /* Solaris currently doesn't support SCTP_ADDR_CONFIRMED */
330 break;
331 case SCTP_ADDR_CONFIRMED :
332 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_CONFIRMED;
333 #endif /* __linux__ */
334 }
335
336 addressObj = SockAddrToInetSocketAddress(env, (struct sockaddr*)&spc->spc_aaddr);
337 CHECK_NULL(addressObj);
338
339 /* create PeerAddressChanged */
340 resultObj = (*env)->NewObject(env, spc_class, spc_ctrID, spc->spc_assoc_id,
341 addressObj, event);
342 CHECK_NULL(resultObj);
343 (*env)->SetObjectField(env, resultContainerObj, src_valueID, resultObj);
344 (*env)->SetIntField(env, resultContainerObj, src_typeID,
345 sun_nio_ch_sctp_ResultContainer_PEER_ADDRESS_CHANGED);
346 }
347
348 void handleUninteresting
349 (union sctp_notification *snp) {
350 //fprintf(stdout,"\nNative: handleUninterestingNotification: Receive notification type [%u]", snp->sn_header.sn_type);
351 }
352
462 if (!(msg->msg_flags & MSG_EOR) && length < SCTP_NOTIFICATION_SIZE) {
463 char* newBuf;
464 int rvSAVE = rv;
465
466 if ((newBuf = malloc(SCTP_NOTIFICATION_SIZE)) == NULL) {
467 JNU_ThrowOutOfMemoryError(env, "Out of native heap space.");
468 return -1;
469 }
470 allocated = JNI_TRUE;
471
472 memcpy(newBuf, addr, rv);
473 iov->iov_base = newBuf + rv;
474 iov->iov_len = SCTP_NOTIFICATION_SIZE - rv;
475 if ((rv = recvmsg(fd, msg, flags)) < 0) {
476 handleSocketError(env, errno);
477 return 0;
478 }
479 bufp = newBuf;
480 rv += rvSAVE;
481 }
482 #ifdef __sparc
483 else if ((intptr_t)addr & 0x3) {
484 /* the given buffer is not 4 byte aligned */
485 char* newBuf;
486 if ((newBuf = malloc(SCTP_NOTIFICATION_SIZE)) == NULL) {
487 JNU_ThrowOutOfMemoryError(env, "Out of native heap space.");
488 return -1;
489 }
490 allocated = JNI_TRUE;
491
492 memcpy(newBuf, addr, rv);
493 bufp = newBuf;
494 }
495 #endif
496 snp = (union sctp_notification *) bufp;
497 if (handleNotification(env, fd, resultContainerObj, snp, rv,
498 (msg->msg_flags & MSG_EOR),
499 &sa.sa) == JNI_TRUE) {
500 /* We have received a notification that is of interest
501 to the Java API. The appropriate notification will be
502 set in the result container. */
503 if (allocated == JNI_TRUE) {
504 free(bufp);
505 }
506 return 0;
507 }
508
509 if (allocated == JNI_TRUE) {
510 free(bufp);
511 }
512
513 // set iov back to addr, and reset msg_controllen
514 iov->iov_base = addr;
515 iov->iov_len = length;
|
309 (JNIEnv* env, jobject resultContainerObj, struct sctp_paddr_change* spc) {
310 int event = 0;
311 jobject addressObj, resultObj;
312 unsigned int state = spc->spc_state;
313
314 switch (state) {
315 case SCTP_ADDR_AVAILABLE :
316 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_AVAILABLE;
317 break;
318 case SCTP_ADDR_UNREACHABLE :
319 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_UNREACHABLE;
320 break;
321 case SCTP_ADDR_REMOVED :
322 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_REMOVED;
323 break;
324 case SCTP_ADDR_ADDED :
325 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_ADDED;
326 break;
327 case SCTP_ADDR_MADE_PRIM :
328 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_MADE_PRIM;
329 break;
330 #ifdef __linux__
331 case SCTP_ADDR_CONFIRMED :
332 event = sun_nio_ch_sctp_PeerAddrChange_SCTP_ADDR_CONFIRMED;
333 break;
334 #endif /* __linux__ */
335 }
336
337 addressObj = SockAddrToInetSocketAddress(env, (struct sockaddr*)&spc->spc_aaddr);
338 CHECK_NULL(addressObj);
339
340 /* create PeerAddressChanged */
341 resultObj = (*env)->NewObject(env, spc_class, spc_ctrID, spc->spc_assoc_id,
342 addressObj, event);
343 CHECK_NULL(resultObj);
344 (*env)->SetObjectField(env, resultContainerObj, src_valueID, resultObj);
345 (*env)->SetIntField(env, resultContainerObj, src_typeID,
346 sun_nio_ch_sctp_ResultContainer_PEER_ADDRESS_CHANGED);
347 }
348
349 void handleUninteresting
350 (union sctp_notification *snp) {
351 //fprintf(stdout,"\nNative: handleUninterestingNotification: Receive notification type [%u]", snp->sn_header.sn_type);
352 }
353
463 if (!(msg->msg_flags & MSG_EOR) && length < SCTP_NOTIFICATION_SIZE) {
464 char* newBuf;
465 int rvSAVE = rv;
466
467 if ((newBuf = malloc(SCTP_NOTIFICATION_SIZE)) == NULL) {
468 JNU_ThrowOutOfMemoryError(env, "Out of native heap space.");
469 return -1;
470 }
471 allocated = JNI_TRUE;
472
473 memcpy(newBuf, addr, rv);
474 iov->iov_base = newBuf + rv;
475 iov->iov_len = SCTP_NOTIFICATION_SIZE - rv;
476 if ((rv = recvmsg(fd, msg, flags)) < 0) {
477 handleSocketError(env, errno);
478 return 0;
479 }
480 bufp = newBuf;
481 rv += rvSAVE;
482 }
483 snp = (union sctp_notification *) bufp;
484 if (handleNotification(env, fd, resultContainerObj, snp, rv,
485 (msg->msg_flags & MSG_EOR),
486 &sa.sa) == JNI_TRUE) {
487 /* We have received a notification that is of interest
488 to the Java API. The appropriate notification will be
489 set in the result container. */
490 if (allocated == JNI_TRUE) {
491 free(bufp);
492 }
493 return 0;
494 }
495
496 if (allocated == JNI_TRUE) {
497 free(bufp);
498 }
499
500 // set iov back to addr, and reset msg_controllen
501 iov->iov_base = addr;
502 iov->iov_len = length;
|