java/ais_api_impl_native/Makefile.am | 1 +
java/ais_api_impl_native/j_ais_amf_libHandle.c | 191 +---------------------
java/ais_api_impl_native/j_ais_clm_libHandle.c | 192 +----------------------
java/ais_api_impl_native/j_ais_libHandle.c | 206 +++++-------------------
java/ais_api_impl_native/j_ais_socketUtil.c | 40 ++--
java/ais_api_impl_native/j_utils.c | 37 ----
java/ais_api_impl_native/j_utils.h | 4 -
7 files changed, 85 insertions(+), 586 deletions(-)
The select() function cannot handle file descriptors larger than 1023. To
avoid this limitation, we replace all usages of select() with poll().
diff --git a/java/ais_api_impl_native/Makefile.am
b/java/ais_api_impl_native/Makefile.am
--- a/java/ais_api_impl_native/Makefile.am
+++ b/java/ais_api_impl_native/Makefile.am
@@ -43,6 +43,7 @@ noinst_HEADERS = \
libjava_ais_api_native_la_CPPFLAGS = \
-I$(top_srcdir)/osaf/libs/saf/include \
+ -I$(top_srcdir)/osaf/libs/core/common/include \
-I $(JAVA_HOME)/include \
-I $(JAVA_HOME)/include/linux \
-DSA_CLM_B01
diff --git a/java/ais_api_impl_native/j_ais_amf_libHandle.c
b/java/ais_api_impl_native/j_ais_amf_libHandle.c
--- a/java/ais_api_impl_native/j_ais_amf_libHandle.c
+++ b/java/ais_api_impl_native/j_ais_amf_libHandle.c
@@ -31,13 +31,13 @@
#include "j_utilsPrint.h"
#include <errno.h>
-#include <sys/select.h>
#include <saAmf.h>
#include <jni.h>
#include "j_utils.h"
#include "j_ais.h"
#include "j_ais_amf.h"
#include "jni_ais_amf.h"
+#include "osaf_poll.h"
/**************************************************************************
* Constants
@@ -815,122 +815,6 @@ JNIEXPORT void JNICALL Java_org_opensaf_
}
/**************************************************************************
- * FUNCTION: Java_org_opensaf_ais_amf_AmfHandleImpl_checkSelectionObject
- * TYPE: native method
- * Class: ais_amf_AmfLHandle
- * Method: checkSelectionObject
- * Signature: (J)Z
- *************************************************************************/
-/*
-JNIEXPORT jboolean JNICALL
Java_org_opensaf_ais_amf_AmfHandleImpl_checkSelectionObject(
- JNIEnv* jniEnv,
- jobject thisAmfHandle,
- jlong timeout )
-{
-
-
- // VARIABLES
- // ais
- SaSelectionObjectT _saSelectionObject;
- // linux
- fd_set _readFDs;
- struct timeval _lxTimeout;
- int _selectStatus;
-
- // BODY
-
- assert( thisAmfHandle != NULL );
- // TODO assert for timeout
- _TRACE2( "NATIVE: Executing
Java_org_opensaf_ais_amf_AmfHandleImpl_checkSelectionObject(...)\n" );
-
- // get selection object
- _saSelectionObject = (SaSelectionObjectT) (*jniEnv)->GetLongField(
- jniEnv,
- thisAmfHandle,
-
FID_selectionObject );
- // call select(2)
- FD_ZERO( &_readFDs );
- FD_SET( _saSelectionObject, &_readFDs );
- U_convertTimeout( &_lxTimeout, timeout );
-
- _TRACE2( "NATIVE: timout is { %ld seconds, %ld microseconds }\n",
_lxTimeout.tv_sec, _lxTimeout.tv_usec );
-
- _selectStatus = select( (_saSelectionObject + 1 ),
- &_readFDs,
- NULL,
- NULL,
- &_lxTimeout );
-
- _TRACE2( "NATIVE: select(...) has returned with %d...\n", _selectStatus );
-
-
- // error handling
- if( _selectStatus == -1 ){
- switch( errno ){
- case EBADF: // invalid file descriptor
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EBADF): invalid file
descriptor\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINTR: // non blocked signal caught
-
- _TRACE2( "NATIVE ERROR : select(EINTR): non blocked signal
caught\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINVAL: // n is negative or the value within timeout is
invalid
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EINVAL): n is negative or the
value within timeout is invalid\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case ENOMEM: // select was unable to allocate memory for internal
tables
-
- _TRACE2( "NATIVE ERROR : select(ENOMEM): select was unable to
allocate memory for internal tables\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisNoMemoryException",
- AIS_ERR_NO_MEMORY_MSG );
- break;
- default:
- // this should not happen here!
-
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- }
- return JNI_FALSE; // EXIT POINT!!! return value is in fact ignored
- }
- if( _selectStatus == 1 ){
-
- _TRACE2( "NATIVE:
Java_org_opensaf_ais_amf_AmfHandleImpl_checkSelectionObject() returning true\n"
);
-
- return JNI_TRUE;
- }
- else{
-
- _TRACE2( "NATIVE:
Java_org_opensaf_ais_amf_AmfHandleImpl_checkSelectionObject() returning
false\n" );
-
- return JNI_FALSE;
- }
-
-}*/
-
-/**************************************************************************
* FUNCTION: Java_org_opensaf_ais_amf_AmfHandleImpl_invokeSaAmfDispatch
* TYPE: native method
* Class: ais_amf_AmfHandle
@@ -1036,8 +920,8 @@ JNIEXPORT void JNICALL Java_org_opensaf_
SaAisErrorT _saStatus;
SaSelectionObjectT _saSelectionObject;
// linux
- fd_set _readFDs;
- int _selectStatus;
+ struct pollfd _readFDs;
+ unsigned _pollStatus;
// BODY
@@ -1054,71 +938,16 @@ JNIEXPORT void JNICALL Java_org_opensaf_
thisAmfHandle,
FID_selectionObject );
// wait until there is a pending callback
- // call select(2)
- FD_ZERO( &_readFDs );
- FD_SET( _saSelectionObject, &_readFDs );
- _selectStatus = select( ( _saSelectionObject + 1 ),
- &_readFDs,
- NULL,
- NULL,
- NULL );
+ // call osaf_poll()
+ _readFDs.fd = _saSelectionObject;
+ _readFDs.events = POLLIN;
+ _pollStatus = osaf_poll(&_readFDs, 1, -1);
- _TRACE2( "NATIVE: select(...) has returned with %d...\n", _selectStatus );
+ _TRACE2( "NATIVE: osaf_poll(...) has returned with %u...\n", _pollStatus );
// error handling
- if( _selectStatus == -1 ){
- switch( errno ){
- case EBADF: // invalid file descriptor
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EBADF): invalid file
descriptor\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINTR: // non blocked signal caught
-
- _TRACE2( "NATIVE ERROR : select(EINTR): non blocked signal
caught\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINVAL: // n is negative or the value within timeout is
invalid
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EINVAL): n is negative or the
value within timeout is invalid\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case ENOMEM: // select was unable to allocate memory for internal
tables
-
- _TRACE2( "NATIVE ERROR : select(ENOMEM): select was unable to
allocate memory for internal tables\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisNoMemoryException",
- AIS_ERR_NO_MEMORY_MSG );
- break;
- default:
- // this should not happen here!
-
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- }
- return; // EXIT POINT!!!
- }
- if( _selectStatus != 1 ){
-
- _TRACE2( "NATIVE ERROR : unexpected select return value!\n" );
+ if (_pollStatus != 1) {
+ _TRACE2( "NATIVE ERROR : unexpected osaf_poll return value!\n"
);
JNU_throwNewByName( jniEnv,
"org/saforum/ais/AisLibraryException",
diff --git a/java/ais_api_impl_native/j_ais_clm_libHandle.c
b/java/ais_api_impl_native/j_ais_clm_libHandle.c
--- a/java/ais_api_impl_native/j_ais_clm_libHandle.c
+++ b/java/ais_api_impl_native/j_ais_clm_libHandle.c
@@ -28,13 +28,13 @@
#include <assert.h>
#include "j_utilsPrint.h"
#include <errno.h>
-#include <sys/select.h>
#include <saClm.h>
#include <jni.h>
#include "j_utils.h"
#include "j_ais.h"
#include "j_ais_clm.h"
#include "jni_ais_clm.h" // not really needed, but good for syntax checking!
+#include "osaf_poll.h"
/**************************************************************************
* Constants
@@ -641,123 +641,6 @@ JNIEXPORT void JNICALL Java_org_opensaf_
}
/**************************************************************************
- * FUNCTION: Java_org_opensaf_ais_clm_ClmHandleImpl_checkSelectionObject
- * TYPE: native method
- * Class: ais_clm_ClmHandle
- * Method: checkSelectionObject
- * Signature: (J)Z
- *************************************************************************/
-/*
- * MODIFICATION: removed (to be tested)
-JNIEXPORT jboolean JNICALL
Java_org_opensaf_ais_clm_ClmHandleImpl_checkSelectionObject(
- JNIEnv* jniEnv,
- jobject thisClmHandle,
- jlong timeout )
-{
-
- // VARIABLES
- // ais
- SaSelectionObjectT _saSelectionObject;
- // linux
- fd_set _readFDs;
- struct timeval _lxTimeout;
- int _selectStatus;
-
- // BODY
-
- assert( thisClmHandle != NULL );
- // TODO assert for timeout
- _TRACE2( "NATIVE: Executing
Java_org_opensaf_ais_clm_ClmHandleImpl_checkSelectionObject(...)\n" );
-
- // get selection object
- _saSelectionObject = (SaSelectionObjectT) (*jniEnv)->GetLongField(
- jniEnv,
- thisClmHandle,
-
FID_selectionObject );
- // call select(2)
- FD_ZERO( &_readFDs );
- FD_SET( _saSelectionObject, &_readFDs );
- U_convertTimeout( &_lxTimeout, timeout );
-
- _TRACE2( "NATIVE: timout is { %ld seconds, %ld microseconds }\n",
_lxTimeout.tv_sec, _lxTimeout.tv_usec );
-
- _selectStatus = select( (_saSelectionObject + 1 ),
- &_readFDs,
- NULL,
- NULL,
- &_lxTimeout );
-
- _TRACE2( "NATIVE: select(...) has returned with %d...\n", _selectStatus );
-
-
- // error handling
- if( _selectStatus == -1 ){
- switch( errno ){
- case EBADF: // invalid file descriptor
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EBADF): invalid file
descriptor\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINTR: // non blocked signal caught
-
- _TRACE2( "NATIVE ERROR : select(EINTR): non blocked signal
caught\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINVAL: // n is negative or the value within timeout is
invalid
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EINVAL): n is negative or the
value within timeout is invalid\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case ENOMEM: // select was unable to allocate memory for internal
tables
-
- _TRACE2( "NATIVE ERROR : select(ENOMEM): select was unable to
allocate memory for internal tables\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisNoMemoryException",
- AIS_ERR_NO_MEMORY_MSG );
- break;
- default:
- // this should not happen here!
-
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- }
- return JNI_FALSE; // EXIT POINT!!! return value is in fact ignored
- }
- if( _selectStatus == 1 ){
-
- _TRACE2( "NATIVE:
Java_org_opensaf_ais_clm_ClmHandleImpl_checkSelectionObject() returning true\n"
);
-
- return JNI_TRUE;
- }
- else{
-
- _TRACE2( "NATIVE:
Java_org_opensaf_ais_clm_ClmHandleImpl_checkSelectionObject() returning
false\n" );
-
- return JNI_FALSE;
- }
-}
-*/
-
-
-/**************************************************************************
* FUNCTION: Java_org_opensaf_ais_clm_ClmHandleImpl_invokeSaClmDispatch
* TYPE: native method
* Class: ais_clm_ClmHandle
@@ -821,8 +704,8 @@ JNIEXPORT void JNICALL Java_org_opensaf_
SaAisErrorT _saStatus;
SaSelectionObjectT _saSelectionObject;
// linux
- fd_set _readFDs;
- int _selectStatus;
+ struct pollfd _readFDs;
+ unsigned _pollStatus;
// BODY
@@ -843,71 +726,16 @@ JNIEXPORT void JNICALL Java_org_opensaf_
_TRACE2(" NATIVE: _saSelectionObject %d\n", _saSelectionObject );
// wait until there is a pending callback
- // call select(2)
- FD_ZERO( &_readFDs );
- FD_SET( _saSelectionObject, &_readFDs );
- _selectStatus = select( ( _saSelectionObject + 1 ),
- &_readFDs,
- NULL,
- NULL,
- NULL );
+ // call osaf_poll()
+ _readFDs.fd = _saSelectionObject;
+ _readFDs.events = POLLIN;
+ _pollStatus = osaf_poll(&_readFDs, 1, -1);
- _TRACE2( "NATIVE: select(...) has returned with %d...\n", _selectStatus );
+ _TRACE2( "NATIVE: osaf_poll(...) has returned with %u...\n", _pollStatus );
// error handling
- if( _selectStatus == -1 ){
- switch( errno ){
- case EBADF: // invalid file descriptor
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EBADF): invalid file
descriptor\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINTR: // non blocked signal caught
-
- _TRACE2( "NATIVE ERROR : select(EINTR): non blocked signal
caught\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINVAL: // n is negative or the value within timeout is
invalid
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EINVAL): n is negative or the
value within timeout is invalid\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case ENOMEM: // select was unable to allocate memory for internal
tables
-
- _TRACE2( "NATIVE ERROR : select(ENOMEM): select was unable to
allocate memory for internal tables\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisNoMemoryException",
- AIS_ERR_NO_MEMORY_MSG );
- break;
- default:
- // this should not happen here!
-
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- }
- return; // EXIT POINT!!!
- }
- if( _selectStatus != 1 ){
-
- _TRACE2( "NATIVE ERROR : unexpected select return value!\n" );
+ if (_pollStatus != 1) {
+ _TRACE2( "NATIVE ERROR : unexpected osaf_poll return value!\n"
);
JNU_throwNewByName( jniEnv,
"org/saforum/ais/AisLibraryException",
diff --git a/java/ais_api_impl_native/j_ais_libHandle.c
b/java/ais_api_impl_native/j_ais_libHandle.c
--- a/java/ais_api_impl_native/j_ais_libHandle.c
+++ b/java/ais_api_impl_native/j_ais_libHandle.c
@@ -29,11 +29,12 @@
#include <stdlib.h>
#include "j_utilsPrint.h"
#include <errno.h>
-#include <sys/select.h>
#include <jni.h>
#include "j_utils.h"
#include "j_ais.h"
#include "jni_ais.h"
+#include "osaf_poll.h"
+#include "osaf_time.h"
/**************************************************************************
* Constants
@@ -76,7 +77,7 @@ static jboolean JNU_Handle_initIDs_FromC
static jint JNU_invokeSelect(
JNIEnv* jniEnv,
jobjectArray libraryHandleArray,
- struct timeval* lxTimeout_Ptr );
+ struct timespec* lxTimeout_Ptr );
/**************************************************************************
* Function definitions
@@ -176,9 +177,9 @@ JNIEXPORT jboolean JNICALL Java_org_open
// ais
SaSelectionObjectT _saSelectionObject;
// linux
- fd_set _readFDs;
- struct timeval _lxTimeout;
- int _selectStatus;
+ struct pollfd _readFDs;
+ struct timespec _lxTimeout;
+ unsigned _pollStatus;
// BODY
assert( thisLibraryHandle != NULL );
@@ -190,74 +191,22 @@ JNIEXPORT jboolean JNICALL Java_org_open
thisLibraryHandle,
FID_selectionObject );
- // call select(2)
- FD_ZERO( &_readFDs );
- FD_SET( _saSelectionObject, &_readFDs );
- U_convertTimeout( &_lxTimeout, timeout );
+ // call osaf_ppoll()
+ _readFDs.fd = _saSelectionObject;
+ _readFDs.events = POLLIN;
+ osaf_nanos_to_timespec(timeout >= 0 ? timeout : 0, &_lxTimeout);
- _TRACE2( "NATIVE: timout is { %ld seconds, %ld microseconds }\n",
_lxTimeout.tv_sec, _lxTimeout.tv_usec );
+ _TRACE2( "NATIVE: timout is { %ld seconds, %ld nanoseconds }\n",
_lxTimeout.tv_sec, _lxTimeout.tv_nsec );
- _selectStatus = select( (_saSelectionObject + 1 ),
- &_readFDs,
- NULL,
- NULL,
- &_lxTimeout );
+ _pollStatus = osaf_ppoll(&_readFDs,
+ 1,
+ &_lxTimeout,
+ NULL);
- _TRACE2( "NATIVE: select(...) has returned with %d...\n", _selectStatus );
+ _TRACE2( "NATIVE: osaf_ppoll(...) has returned with %u...\n", _pollStatus
);
- // error handling
- if( _selectStatus == -1 ){
- switch( errno ){
- case EBADF: // invalid file descriptor
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EBADF): invalid file
descriptor\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINTR: // non blocked signal caught
-
- _TRACE2( "NATIVE ERROR : select(EINTR): non blocked signal
caught\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINVAL: // n is negative or the value within timeout is
invalid
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EINVAL): n is negative or the
value within timeout is invalid\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case ENOMEM: // select was unable to allocate memory for internal
tables
-
- _TRACE2( "NATIVE ERROR : select(ENOMEM): select was unable to
allocate memory for internal tables\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisNoMemoryException",
- AIS_ERR_NO_MEMORY_MSG );
- break;
- default:
- // this should not happen here!
-
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- }
- return JNI_FALSE; // EXIT POINT!!! return value is in fact ignored
- }
- if( _selectStatus == 1 ){
+ if (_pollStatus == 1) {
_TRACE2( "NATIVE:
Java_org_opensaf_ais_HandleImpl_checkSelectionObject() returning true\n" );
@@ -317,7 +266,7 @@ JNIEXPORT jint JNICALL Java_org_opensaf_
// VARIABLES
// ais
// linux
- struct timeval _lxTimeout;
+ struct timespec _lxTimeout;
// BODY
@@ -327,7 +276,7 @@ JNIEXPORT jint JNICALL Java_org_opensaf_
_TRACE2( "NATIVE: Executing
Java_org_opensaf_ais_HandleImpl_s_1invokeSelect___3JJ(...)\n" );
// convert timeout
- U_convertTimeout( &_lxTimeout, timeout );
+ osaf_nanos_to_timespec(timeout >= 0 ? timeout : 0, &_lxTimeout);
// invoke select
return JNU_invokeSelect( jniEnv,
@@ -348,7 +297,7 @@ JNIEXPORT jint JNICALL Java_org_opensaf_
static jint JNU_invokeSelect(
JNIEnv* jniEnv,
jlongArray selectionObjectArray,
- struct timeval* lxTimeoutPtr )
+ struct timespec* lxTimeoutPtr )
{
// VARIABLES
// JNI
@@ -356,16 +305,13 @@ static jint JNU_invokeSelect(
unsigned int _idx;
// ais
SaSelectionObjectT _saSelectionObjectArray[J_AIS_LIBHANDLE_SELECT_MAX];
- SaSelectionObjectT _saSelectionObjectMax;
// linux
- fd_set _readFDs;
- int _selectStatus;
+ struct pollfd* _readFDs;
+ unsigned _pollStatus;
// BODY
_TRACE2( "NATIVE: Executing JNU_invokeSelect(...)\n" );
- FD_ZERO( &_readFDs );
- _saSelectionObjectMax = 0;
// copy native selection objects from the Java array to a native array
_len = (*jniEnv)->GetArrayLength( jniEnv, selectionObjectArray );
@@ -388,94 +334,47 @@ static jint JNU_invokeSelect(
(jsize) 0,
_len,
(jlong*) _saSelectionObjectArray );
- // call select(2)
+ // call osaf_ppoll()
+ _readFDs = malloc(_len * sizeof(struct pollfd));
+ if (_readFDs == NULL) {
+ _TRACE2( "NATIVE ERROR : unable to allocate memory for osaf_ppoll()\n"
);
+ JNU_throwNewByName(jniEnv,
+ "org/saforum/ais/AisNoMemoryException",
+ AIS_ERR_NO_MEMORY_MSG);
+ return JNI_FALSE; // EXIT POINT!!! return value is in fact ignored
+ }
+
for( _idx = 0; _idx < _len; _idx++ ){
// get selection object
- _TRACE2( "NATIVE: %d. selection object is: %lu\n", _idx, (unsigned
long) _saSelectionObjectArray[_idx] );
+ _TRACE2( "NATIVE: %u. selection object is: %lu\n", _idx, (unsigned
long) _saSelectionObjectArray[_idx] );
- FD_SET( _saSelectionObjectArray[_idx], &_readFDs );
- if( _saSelectionObjectArray[_idx] > _saSelectionObjectMax ){
- _saSelectionObjectMax = _saSelectionObjectArray[_idx];
- }
+ _readFDs[_idx].fd = _saSelectionObjectArray[_idx];
+ _readFDs[_idx].events = POLLIN;
}
- _TRACE2( "NATIVE: nfds is: %lu\n", ( ( (unsigned long)
_saSelectionObjectMax ) + 1 ) );
- _TRACE2( "NATIVE: timout is { %ld seconds, %ld microseconds }\n",
lxTimeoutPtr->tv_sec, lxTimeoutPtr->tv_usec );
+ _TRACE2( "NATIVE: nfds is: %lu\n", (unsigned long) _len);
+ _TRACE2( "NATIVE: timout is { %ld seconds, %ld nanoseconds }\n",
lxTimeoutPtr->tv_sec, lxTimeoutPtr->tv_nsec );
- _selectStatus = select( (_saSelectionObjectMax + 1 ),
- &_readFDs,
- NULL,
- NULL,
- lxTimeoutPtr );
+ _pollStatus = osaf_ppoll(_readFDs, _len, lxTimeoutPtr, NULL);
- _TRACE2( "NATIVE: select(...) has returned with %d...\n", _selectStatus );
+ _TRACE2( "NATIVE: osaf_ppoll(...) has returned with %u...\n", _pollStatus
);
- // error handling
- if( _selectStatus == -1 ){
- switch( errno ){
- case EBADF: // invalid file descriptor
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EBADF): invalid file
descriptor\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINTR: // non blocked signal caught
-
- _TRACE2( "NATIVE ERROR : select(EINTR): non blocked signal
caught\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case EINVAL: // n is negative or the value within timeout is
invalid
-
- // this should not happen here!
- _TRACE2( "NATIVE ERROR : select(EINVAL): n is negative or the
value within timeout is invalid\n" );
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- case ENOMEM: // select was unable to allocate memory for internal
tables
-
- _TRACE2( "NATIVE ERROR : select(ENOMEM): select was unable to
allocate memory for internal tables\n" );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisNoMemoryException",
- AIS_ERR_NO_MEMORY_MSG );
- break;
- default:
- // this should not happen here!
-
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- break;
- }
- return JNI_FALSE; // EXIT POINT!!! return value is in fact ignored
- }
- if( _selectStatus == 0 ){
+ if (_pollStatus == 0) {
_TRACE2( "NATIVE: JNU_invokeSelect() returning 0\n" );
+ free(_readFDs);
return 0; // EXIT POINT!!!
}
- if( _selectStatus > 0 ){
+
// mark unselected selection objects
for( _idx = 0; _idx < _len; _idx++ ){
- if( ! FD_ISSET( _saSelectionObjectArray[_idx], &_readFDs ) ){
+ if (_readFDs[_idx].revents == 0) {
_saSelectionObjectArray[_idx] = 0xFFFFFFFFFFFFFFFFULL;
}
- _TRACE2( "NATIVE: %d. selection object is: %lu\n", _idx, (unsigned
long) _saSelectionObjectArray[_idx] );
+ _TRACE2( "NATIVE: %u. selection object is: %lu\n", _idx, (unsigned
long) _saSelectionObjectArray[_idx] );
}
(*jniEnv)->SetLongArrayRegion( jniEnv,
@@ -484,21 +383,10 @@ static jint JNU_invokeSelect(
_len,
(jlong*) _saSelectionObjectArray );
+ _TRACE2( "NATIVE: JNU_invokeSelect() returning %u\n", _pollStatus );
- _TRACE2( "NATIVE: JNU_invokeSelect() returning %d\n", _selectStatus );
-
- return _selectStatus; // EXIT POINT!!!
- }
- // All legal casesof select return calues covered by now, so:
- // this should not happen here!
-
- assert( JNI_FALSE );
-
- JNU_throwNewByName( jniEnv,
- "org/saforum/ais/AisLibraryException",
- AIS_ERR_LIBRARY_MSG );
- return 0;
-
+ free(_readFDs);
+ return _pollStatus; // EXIT POINT!!!
}
diff --git a/java/ais_api_impl_native/j_ais_socketUtil.c
b/java/ais_api_impl_native/j_ais_socketUtil.c
--- a/java/ais_api_impl_native/j_ais_socketUtil.c
+++ b/java/ais_api_impl_native/j_ais_socketUtil.c
@@ -15,15 +15,16 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <jni.h>
#include <sys/socket.h>
#include <sys/types.h>
-#include <sys/select.h>
#include <assert.h>
#include "j_utilsPrint.h"
#include "j_utils.h"
#include "jni_ais.h"
+#include "osaf_poll.h"
/**
* Opens a socket pair and returns the two descriptors.
@@ -118,11 +119,11 @@ JNIEXPORT void JNICALL Java_org_opensaf_
}
/**
- * Calls select() on the given socket descriptors and returns an array of the
modified ones.
+ * Calls poll() on the given socket descriptors and returns an array of the
modified ones.
* In case of any error, it returns NULL.
- * @param sockets The socket descriptors on whom we call select().
+ * @param sockets The socket descriptors on whom we call poll().
* @param socketSize Size of the array of socket descriptors.
- * @return An array of sockets returned by select().
+ * @return An array of sockets returned by poll().
*/
JNIEXPORT jintArray JNICALL
Java_org_opensaf_ais_SelectionObjectMediator_00024Worker_doSelect(
JNIEnv *jniEnv, jobject object, jintArray sockets, jint
socketSize) {
@@ -132,38 +133,31 @@ JNIEXPORT jintArray JNICALL Java_org_ope
_TRACE2("NATIVE: Executing
Java_org_opensaf_ais_SelectionObjectMediator_00024Worker_doSelect\n");
- int* fds = (*jniEnv)->GetIntArrayElements(jniEnv, sockets, 0);
+ struct pollfd* rfds = malloc(socketSize * sizeof(struct pollfd));
+ if (rfds == NULL) return NULL;
- fd_set rfds;
- fd_set rfds_copy;
- FD_ZERO(&rfds);
+ int* fds = (*jniEnv)->GetIntArrayElements(jniEnv, sockets, 0);
int i;
- int maxfd = 0;
for (i = 0; i < socketSize; i++) {
- FD_SET(fds[i], &rfds);
- if (maxfd < fds[i]) maxfd = fds[i];
+ rfds[i].fd = fds[i];
+ rfds[i].events = POLLIN;
}
- rfds_copy = rfds;
-
- int numFds = select(maxfd + 1, &rfds, NULL, NULL, NULL);
- if (numFds < 1) {
- perror("select()");
- fflush(stderr);
- } else {
+ unsigned numFds = osaf_poll(rfds, socketSize, -1);
+ if (numFds > 0) {
selectedSockets = (*jniEnv)->NewIntArray(jniEnv, numFds);
- int a = 0;
- for (i = 0; i < socketSize; i++) {
- if (FD_ISSET(fds[i], &rfds)) {
+ unsigned a = 0;
+ for (i = 0; i < socketSize && a < numFds; i++) {
+ if (rfds[i].revents != 0) {
(*jniEnv)->SetIntArrayRegion(jniEnv,
selectedSockets, a, 1, &fds[i]);
a++;
}
}
}
-
+ free(rfds);
_TRACE2("NATIVE: Finishing
Java_org_opensaf_ais_SelectionObjectMediator_00024Worker_doSelect\n");
- return selectedSockets;
+ return selectedSockets;
}
diff --git a/java/ais_api_impl_native/j_utils.c
b/java/ais_api_impl_native/j_utils.c
--- a/java/ais_api_impl_native/j_utils.c
+++ b/java/ais_api_impl_native/j_utils.c
@@ -29,7 +29,6 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
-#include <sys/select.h>
#include <jni.h>
#include <saAis.h>
#include <saClm.h>
@@ -788,39 +787,3 @@ jclass JNU_GetGlobalClassRef( JNIEnv* jn
return _globalCls;
}
-/**************************************************************************
- * FUNCTION: U_convertTimeout
- * TYPE: internal function
- * OVERVIEW: converts the timeout value specified in nanoseconds to
- * POSIX struct timeval.
- * INTERFACE:
- * parameters: TODO
- * returns: none
- * NOTE:
- *************************************************************************/
-void U_convertTimeout(
- struct timeval* to_timeout,
- const jlong from_timeout )
-{
- // BODY
-#ifndef NDEBUG
- // _TRACE2( "NATIVE: Executing U_convertTimeout(..., %ld )\n", (long)
from_timeout );
-#endif // NDEBUG
- // TODO types checking! negative values
- if( from_timeout < SA_TIME_ONE_MICROSECOND ){
- // no timout
- to_timeout->tv_sec = 0;
- to_timeout->tv_usec = 0;
- return; // EXIT POINT!!!
- }
- if( from_timeout < SA_TIME_ONE_SECOND ){
- // subsecond timout
- to_timeout->tv_sec = 0;
- to_timeout->tv_usec = from_timeout / SA_TIME_ONE_MICROSECOND;
- return; // EXIT POINT!!!
- }
- to_timeout->tv_sec = from_timeout / SA_TIME_ONE_SECOND;
- to_timeout->tv_usec = ( from_timeout % SA_TIME_ONE_SECOND ) /
SA_TIME_ONE_MICROSECOND;
- return;
-}
-
diff --git a/java/ais_api_impl_native/j_utils.h
b/java/ais_api_impl_native/j_utils.h
--- a/java/ais_api_impl_native/j_utils.h
+++ b/java/ais_api_impl_native/j_utils.h
@@ -22,7 +22,6 @@
*************************************************************************/
#include <jni.h>
-#include <sys/select.h>
#include <saAis.h>
#include <saClm.h>
#include <saCkpt.h>
@@ -93,9 +92,6 @@ extern jint JNU_GetEnvForCallback(
jclass JNU_GetGlobalClassRef(
JNIEnv* jniEnv,
const char* className );
-extern void U_convertTimeout(
- struct timeval* to_timeout,
- const jlong from_timeout );
#endif //J_UTILS_H_
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel