osaf/libs/core/include/ncs_osprm.h |  142 +-------------------------
 osaf/libs/core/include/os_defs.h   |    1 -
 osaf/libs/core/leap/os_defs.c      |  203 +-----------------------------------
 osaf/libs/core/leap/sysf_ipc.c     |    9 +-
 osaf/libs/core/leap/sysf_tmr.c     |   68 ++----------
 5 files changed, 23 insertions(+), 400 deletions(-)


The select() function cannot handle file descriptors larger than 1023. To avoid
this limitation, we replace all usages of select() with poll().

The following APIs were based on select() and have been removed from BASE:

m_SET_FD_IN_SEL_OBJ()
m_GET_HIGHER_SEL_OBJ()
ncs_sel_obj_select()
m_NCS_SEL_OBJ_SELECT()
ncs_sel_obj_poll_single_obj()
m_NCS_SEL_OBJ_POLL_SINGLE_OBJ()
m_NCS_SEL_OBJ_ZERO()
m_NCS_SEL_OBJ_SET()
m_NCS_SEL_OBJ_ISSET()
m_NCS_SEL_OBJ_CLR()
NCS_SEL_OBJ_SET

diff --git a/osaf/libs/core/include/ncs_osprm.h 
b/osaf/libs/core/include/ncs_osprm.h
--- a/osaf/libs/core/include/ncs_osprm.h
+++ b/osaf/libs/core/include/ncs_osprm.h
@@ -29,7 +29,6 @@
 #define NCS_OSPRM_H
 
 #include <stdlib.h>
-#include <sys/select.h>
 #include "logtrace.h"
 #include "ncsgl_defs.h"
 
@@ -635,27 +634,10 @@ uint32_t ncs_os_posix_mq(NCS_OS_POSIX_MQ
                         in future if we wish to change the data-type of
                         NCS_SEL_OBJ, without effecting user code)
 
-  m_SET_FD_IN_SEL_OBJ:  This API is provided for the purpose of mixing
-                        FDs generated by means external to these primitives
-                        with selection-objects generated by these primitives.
-                        Such a mixing of FDs and selection-objects is only
-                        useful while making a m_NCS_SEL_OBJ_SELECT call.
-
-  m_GET_HIGHER_SEL_OBJ: This API returns the "higher" selection-object (in a
-                        sense that is meaningful for the m_NCS_SEL_OBJ_SELECT
-                        call.) It is required in determining the highest
-                        selection-object that needs to be provided for
-                        an m_NCS_SEL_OBJ_SELECT call.
 \****************************************************************************/
 #define m_GET_FD_FROM_SEL_OBJ(sel_obj)           \
             (sel_obj.rmv_obj)
 
-#define m_SET_FD_IN_SEL_OBJ(fd, sel_obj)         \
-            (sel_obj.raise_obj=-1,sel_obj.rmv_obj=fd)
-
-#define m_GET_HIGHER_SEL_OBJ(sel_obj1, sel_obj2) \
-            ((sel_obj1).rmv_obj > (sel_obj2).rmv_obj? (sel_obj1):(sel_obj2))
-
 /****************************************************************************\
 
    ncs_sel_obj_create:  Returns a selection-object pair. It internally may 
@@ -670,7 +652,7 @@ uint32_t ncs_os_posix_mq(NCS_OS_POSIX_MQ
     o_sel_obj   :       A selection-object which can be used to pass
                         indications from one task to another. It contains
                         a POSIX style file-descriptor on which a 
-                        POSIX select() can be invoked. 
+                       POSIX poll() can be invoked.
 
                         (This is an OUT argument and is set to a valid value
                         if the return value is success)
@@ -803,128 +785,6 @@ uint32_t ncs_os_posix_mq(NCS_OS_POSIX_MQ
 #define     m_NCS_SEL_OBJ_RMV_IND(sel_obj, noblock_flag, rmv_only_one_flag)\
             ncs_sel_obj_rmv_ind(sel_obj, noblock_flag,  rmv_only_one_flag)
 
-/****************************************************************************\ 
-   ncs_sel_obj_select:  Identical to POSIX select except for the data types
-                        of the argument and return values
-
-  RETURN VALUE  :       Identical to POSIX select
-                        -1 = in case of an error 
-                        0  = if select() returns due to timeout
-                        n  = No. of objects set in the bitmasks.
-
-  ARGUMENTS     :       
-   
-      highest_sel_obj:  Highest selection-object present in the 
-                        sel-obj-sets provided (viz. io_readfds,
-                        io_writefds, io_exceptfds)
-
-                        NOTE : POSIX select() API expects highest-fd 
-                        plus 1. But this API is happy even with a
-                        highest-fd.
-
-                        (Highest selection-object should be determined
-                        using the m_GET_HIGHER_SEL_OBJ() macro)
-      
-      io_readfds:       Similar to "readfds" in a POSIX select call
-      io_writefds:      Similar to "writefds" in a POSIX select call
-      io_exceptfds:     Similar to "exceptfds" in a POSIX select call
-                              
-      io_timeout:       Similar to "timeout " in a POSIX select call. But
-                        instead of a "struct timeval" it is a timeout
-                        in multiples of 10-milliseconds (can be
-                        called centisecond units?) ('io_timeout" will
-                        return time elapsed since m_NCS_SEL_OBJ_SELECT
-                        invocation, if supported by underlying Operating
-                        System, for example Linux)
-  
-   NOTES        :       The io_*fds provided to this call NEED-NOT necessarily 
-                        be created by m_NCS_SEL_OBJ_CREATE only. They could
-                        contain objects created by POSIX APIs (viz. open,
-                        etc.) too.
-
-\***************************************************************************/
-/* Select is returnig uint32_t it should be int */
-
-       int ncs_sel_obj_select(NCS_SEL_OBJ highest_sel_obj,
-                              NCS_SEL_OBJ_SET *io_readfds,
-                              NCS_SEL_OBJ_SET *io_writefds, NCS_SEL_OBJ_SET 
*io_exceptfds, uint32_t *io_timeout);
-#define     m_NCS_SEL_OBJ_SELECT(m, r, w, e, t)\
-            ncs_sel_obj_select(m, r, w, e, t)
-
-/****************************************************************************\ 
-   ncs_sel_obj_poll_single_obj:  Invokes poll() over a single NCS_SEL_OBJ. 
-                         Looks for POLLIN event. 
-
-  RETURN VALUE  :       -1 = If call interrupt with (errno != EINTR)
-                        0  = If poll() times out, before POLLIN is received.
-                        1  = If POLLIN is received
-
-  ARGUMENTS     :       
-
-      sel_obj   :       The selection object that needs to be polled.
-   
-      io_timeout:       Maximum time to block (in-out variable). 
-                        It has the following usage
-
-                        NULL => Infinite timeout
-
-                        non-NULL => maximum time to block. This is an
-                                    in/out variable. On return from function
-                                    call, this argument will containing the
-                                    remaining time.
-  
-   NOTES        :       This function can be invoked on a greater range
-                        of "fds" than that accepted by select(). 
-
-\***************************************************************************/
-       int32_t ncs_sel_obj_poll_single_obj(NCS_SEL_OBJ sel_obj, uint32_t 
*io_timeout);
-#define     m_NCS_SEL_OBJ_POLL_SINGLE_OBJ(obj, io_timeout)\
-            ncs_sel_obj_poll_single_obj(obj, io_timeout)
-
-/****************************************************************************\ 
-   The following macros are currently based on the macros defined for use with
-   POSIX 'select()' and have identical semantics.
-\****************************************************************************/
-static inline void m_NCS_SEL_OBJ_ZERO(NCS_SEL_OBJ_SET* o_sel_obj_set)
-{
-       FD_ZERO(o_sel_obj_set);
-}
-
-static inline void m_NCS_SEL_OBJ_SET(NCS_SEL_OBJ i_sel_obj,
-       NCS_SEL_OBJ_SET* io_sel_obj_set)
-{
-       if (i_sel_obj.rmv_obj >= 0 && i_sel_obj.rmv_obj < FD_SETSIZE) {
-               FD_SET(i_sel_obj.rmv_obj, io_sel_obj_set);
-       } else {
-               LOG_ER("Process terminated due to file descriptor %d outside "
-                       "supported range [0, 1024)", i_sel_obj.rmv_obj);
-               abort();
-       }
-}
-
-static inline int m_NCS_SEL_OBJ_ISSET(NCS_SEL_OBJ i_sel_obj,
-       const NCS_SEL_OBJ_SET* i_sel_obj_set)
-{
-       if (i_sel_obj.rmv_obj >= 0 && i_sel_obj.rmv_obj < FD_SETSIZE) {
-               return FD_ISSET(i_sel_obj.rmv_obj, i_sel_obj_set);
-       } else {
-               LOG_ER("Process terminated due to file descriptor %d outside "
-                       "supported range [0, 1024)", i_sel_obj.rmv_obj);
-               abort();
-       }
-}
-
-static inline void m_NCS_SEL_OBJ_CLR(NCS_SEL_OBJ i_sel_obj,
-       NCS_SEL_OBJ_SET* io_sel_obj_set)
-{
-       if (i_sel_obj.rmv_obj >= 0 && i_sel_obj.rmv_obj < FD_SETSIZE) {
-               FD_CLR(i_sel_obj.rmv_obj, io_sel_obj_set);
-       } else {
-               LOG_ER("Process terminated due to file descriptor %d outside "
-                       "supported range [0, 1024)", i_sel_obj.rmv_obj);
-               abort();
-       }
-}
 
 /****************************************************************************\
  * E N D      :  S E L E C T I O N - O B J E C T    P R I M I T I V E S     *
diff --git a/osaf/libs/core/include/os_defs.h b/osaf/libs/core/include/os_defs.h
--- a/osaf/libs/core/include/os_defs.h
+++ b/osaf/libs/core/include/os_defs.h
@@ -201,7 +201,6 @@ typedef struct ncs_sel_obj {
        int raise_obj;
        int rmv_obj;
 } NCS_SEL_OBJ;
-typedef fd_set NCS_SEL_OBJ_SET;
 
 #ifdef  __cplusplus
 }
diff --git a/osaf/libs/core/leap/os_defs.c b/osaf/libs/core/leap/os_defs.c
--- a/osaf/libs/core/leap/os_defs.c
+++ b/osaf/libs/core/leap/os_defs.c
@@ -38,8 +38,6 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
-#include <sys/poll.h>
-#include <poll.h>
 #include <time.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -54,6 +52,7 @@
 #include "ncssysf_lck.h"
 #include "ncssysf_def.h"
 #include "osaf_utility.h"
+#include "osaf_time.h"
 
 NCS_OS_LOCK gl_ncs_atomic_mtx;
 #ifndef NDEBUG
@@ -130,45 +129,6 @@ int64_t ncs_os_time_ms(void)
        return retval;
 }
 
-/***************************************************************************
- *
- * unsigned int
- * ncs_os_task( NCS_OS_task *, NCS_OS_TASK_REQUEST )
- *
- * Description:
- *   This routine handles all operating system Task requests.
- *
- * Synopsis:
- *
- * Call Arguments:
- *    task    ............... pointer to a NCS_OS_TASK
- *    request ............... action request
- *
- * Returns:
- *   Returns NCSCC_RC_SUCCESS if successful, otherwise NCSCC_RC_FAILURE.
- *
- * Notes:
- *
- **************************************************************************/
-
-static
-unsigned int ncs_linux_sleep(unsigned int ms_delay)
-{
-       struct timeval tv;
-       tv.tv_sec = ms_delay / 1000;
-
-       tv.tv_usec = ((ms_delay % 1000) * 1000);
-
-       while (select(0, 0, 0, 0, &tv) != 0)
-               if (errno == EINTR)
-                       continue;
-               else
-                       return (NCSCC_RC_FAILURE);
-
-       return (NCSCC_RC_SUCCESS);
-
-}
-
 unsigned int ncs_os_task(NCS_OS_TASK *task, NCS_OS_TASK_REQUEST request)
 {
        switch (request) {
@@ -334,8 +294,11 @@ unsigned int ncs_os_task(NCS_OS_TASK *ta
                break;
 
        case NCS_OS_TASK_SLEEP:
-               if (NCSCC_RC_SUCCESS != 
ncs_linux_sleep(task->info.sleep.i_delay_in_ms)) {
-                       return NCSCC_RC_FAILURE;
+               {
+                       struct timespec ts;
+                       osaf_millis_to_timespec(task->info.sleep.i_delay_in_ms,
+                               &ts);
+                       osaf_nanosleep(&ts);
                }
                break;
 
@@ -1083,7 +1046,7 @@ uint32_t ncs_os_process_execute_timed(NC
  *
  * Description:
  *   These primitives implement creation and manipulation routines for
- *   objects on which POSIX select() could be done.  The term 
+ *   objects on which POSIX poll() could be done.  The term
  *   "selection-objects" will be used to denote these objects.
  *
  *   These primitives make use "fd"s generated by "socket()" invocation as
@@ -1096,18 +1059,6 @@ uint32_t ncs_os_process_execute_timed(NC
  *      m_NCS_SEL_OBJ_DESTROY  =>   ncs_sel_obj_destroy()
  *      m_NCS_SEL_OBJ_IND      =>   ncs_sel_obj_ind()
  *      m_NCS_SEL_OBJ_RMV_IND  =>   ncs_sel_obj_rmv_ind()
- *      m_NCS_SEL_OBJ_SELECT   =>   ncs_sel_obj_select()
- *      m_NCS_SEL_OBJ_POLL_SINGLE_OBJ =>   ncs_sel_obj_poll_single_obj()
- *
- *   The following macros are an important part of the "ncs_sel_obj_*"
- *   primitive set but Operating System provided macros have been used
- *   for this. Therefore, they do not have a corresponding function
- *   implemented in this file. 
- *      m_NCS_SEL_OBJ_ZERO     =>   based on FD_ZERO
- *      m_NCS_SEL_OBJ_SET      =>   based on FD_SET
- *      m_NCS_SEL_OBJ_CLR      =>   based on FD_CLR
- *      m_NCS_SEL_OBJ_ISSET    =>   based on FD_ISSET
- *
  *
  ****************************************************************************/
 #define MAX_INDS_AT_A_TIME 10
@@ -1342,146 +1293,6 @@ int ncs_sel_obj_rmv_ind(NCS_SEL_OBJ i_in
        }                       /* End of infinite loop */
 }
 
-int ncs_sel_obj_select(NCS_SEL_OBJ highest_sel_obj,
-                      NCS_SEL_OBJ_SET *rfds, NCS_SEL_OBJ_SET *wfds, 
NCS_SEL_OBJ_SET *efds, uint32_t *timeout_in_10ms)
-{
-       struct timeval tmout_in_tv = { 0, 0 };
-       struct timeval *p_tmout_in_tv;
-       int rc;
-       uint32_t rem10ms = 0, old_rem10ms = 0;
-       NCS_SEL_OBJ_SET save_rfds, save_wfds, save_efds;
-
-       FD_ZERO(&save_rfds);
-       FD_ZERO(&save_wfds);
-       FD_ZERO(&save_efds);
-
-       if (timeout_in_10ms != NULL) {
-               old_rem10ms = *timeout_in_10ms;
-       }
-       if (rfds)
-               save_rfds = *rfds;
-       if (wfds)
-               save_wfds = *wfds;
-       if (efds)
-               save_efds = *efds;
-
-       do {
-               if (rfds)
-                       *rfds = save_rfds;
-               if (wfds)
-                       *wfds = save_wfds;
-               if (efds)
-                       *efds = save_efds;
-
-               /* STEP: Calculate time to make to select() */
-               if (timeout_in_10ms != NULL) {
-                       tmout_in_tv.tv_sec = old_rem10ms / 100;
-                       tmout_in_tv.tv_usec = ((old_rem10ms) % 100) * 10000;
-                       p_tmout_in_tv = &tmout_in_tv;
-               } else
-                       p_tmout_in_tv = NULL;
-
-               rc = select(highest_sel_obj.rmv_obj + 1, rfds, wfds, efds, 
p_tmout_in_tv);
-
-               if (timeout_in_10ms != NULL) {
-                       rem10ms = (tmout_in_tv.tv_sec * 100);
-                       rem10ms += ((tmout_in_tv.tv_usec + 5000) / 10000);
-
-                       if (old_rem10ms < rem10ms) {
-                               /* STEP: Gadbad ho gaya */
-                               rem10ms = old_rem10ms / 10;
-                               if (rem10ms == 0) {
-                                       rc = 0; /* TIMEOUT */
-                                       break;
-                               }
-                       }
-                       old_rem10ms = rem10ms;
-               }
-
-       } while ((rc == -1) && (errno == EINTR));
-
-       if (timeout_in_10ms != NULL) {
-               /* Convert <sec,usec> to 10ms units (call it centiseconds=cs, 
say)
-                * tv_usec is rouded off to closest 10ms(=1cs) multiple. 
-                * (Eg.:94999us ~ 9cs and 95000us ~ 10cs)
-                */
-               *timeout_in_10ms = rem10ms;
-               *timeout_in_10ms = rem10ms;
-       }
-       return rc;
-}
-
-int32_t ncs_sel_obj_poll_single_obj(NCS_SEL_OBJ sel_obj, uint32_t 
*timeout_in_10ms)
-{
-       struct pollfd pfd;      /* Poll struct for user's fd      */
-       int poll_wait_time_in_ms;       /* Total wait time req. by caller */
-       struct timespec poll_start_time;        /* Time when poll() is first 
called */
-
-       /* Working variables */
-       struct timespec curr_time;      /* current time */
-       long long diff_time_in_ms;      /* time diff in ms */
-       int pollres;            /* poll() return code */
-       int poll_wait_left_in_ms;       /* Wait time left in "ms" */
-       int save_errno;         /* errno of poll() call */
-
-       /* STEP: Setup poll struct */
-       pfd.fd = sel_obj.rmv_obj;
-       pfd.events = POLLIN;
-       pfd.revents = 0;
-
-       /* STEP: Record start time and determine total wait time  */
-       clock_gettime(CLOCK_REALTIME, &poll_start_time);
-       if ((timeout_in_10ms == NULL) || ((*timeout_in_10ms) < 0)) {
-               /* User wants infinite wait */
-               poll_wait_time_in_ms = -1;      /* -ve value = infinite wait 
for POLL */
-       } else {
-               poll_wait_time_in_ms = 10 * (*timeout_in_10ms);
-       }
-       poll_wait_left_in_ms = poll_wait_time_in_ms;
-
-       /* STEP: Start wait loop */
-       while (1) {
-               pollres = poll(&pfd, 1, poll_wait_left_in_ms);
-
-               /* Save errno immediately to avoid side-effects */
-               save_errno = errno;
-
-               /* Calculate wait time remaining */
-               if (poll_wait_time_in_ms > 0) {
-                       clock_gettime(CLOCK_REALTIME, &curr_time);
-                       diff_time_in_ms =
-                           ((curr_time.tv_sec) * (1000L) + curr_time.tv_nsec / 
(1000 * 1000)) -
-                           ((poll_start_time.tv_sec) * (1000L) + 
poll_start_time.tv_nsec / (1000 * 1000));
-                       poll_wait_left_in_ms = poll_wait_time_in_ms - 
diff_time_in_ms;
-                       if (poll_wait_left_in_ms < 0)
-                               poll_wait_left_in_ms = 0;
-
-                       /* Update in/out variable */
-                       *timeout_in_10ms = poll_wait_left_in_ms / 10;
-               }
-
-               if ((pollres >= 0) || (save_errno != EINTR)) {
-
-                       if ((pollres == 1) && ((pfd.revents == (POLLIN | 
POLLHUP)))) {
-                               /* we reach here when one fd is closed */
-                               return -1;
-                       }
-
-                       assert((pollres == 0) ||
-                              ((pollres == 1) && (pfd.revents == POLLIN)) ||
-                              ((pollres == -1) && (save_errno != EINTR)));
-
-                       return pollres;
-               }
-
-               if (poll_wait_left_in_ms == 0) {
-                       /* We reach here only as a rare coincidence */
-                       assert((pollres == -1) && (save_errno == EINTR));
-                       return 0;       /* TIMEOUT : Rare coincidence  EINTR + 
TIMEOUT */
-               }
-       }                       /* while(1) */
-}
-
 FILE *ncs_os_fopen(const char *fpath, const char *fmode)
 {
        FILE *fp = NULL;
diff --git a/osaf/libs/core/leap/sysf_ipc.c b/osaf/libs/core/leap/sysf_ipc.c
--- a/osaf/libs/core/leap/sysf_ipc.c
+++ b/osaf/libs/core/leap/sysf_ipc.c
@@ -49,6 +49,7 @@
 #include "ncssysf_def.h"
 #include "usrbuf.h"
 #include "ncssysf_mem.h"
+#include "osaf_poll.h"
 
 static NCS_IPC_MSG *ncs_ipc_recv_common(SYSF_MBX *mbx, bool block);
 static uint32_t ipc_enqueue_ind_processing(NCS_IPC *ncs_ipc, unsigned int 
queue_number);
@@ -314,7 +315,6 @@ static NCS_IPC_MSG *ncs_ipc_recv_common(
        unsigned int active_queue;
        int inds_rmvd;
        NCS_SEL_OBJ mbx_obj;
-       NCS_SEL_OBJ_SET obj_set;
 
        if ((NULL == NCS_INT32_TO_PTR_CAST(mbx)) || (NULL == 
NCS_INT32_TO_PTR_CAST(*mbx)))
                return NULL;
@@ -329,10 +329,7 @@ static NCS_IPC_MSG *ncs_ipc_recv_common(
                        return NULL;
 
                if (block == true) {
-                       m_NCS_SEL_OBJ_ZERO(&obj_set);
-                       m_NCS_SEL_OBJ_SET(mbx_obj, &obj_set);
-
-                       if (m_NCS_SEL_OBJ_SELECT(mbx_obj, &obj_set, NULL, NULL, 
NULL) != 1) {
+                       if (osaf_poll_one_fd(m_GET_FD_FROM_SEL_OBJ(mbx_obj), 
-1) != 1) {
                                ncshm_give_hdl((uint32_t)*mbx);
                                return NULL;
                        }
@@ -350,7 +347,7 @@ static NCS_IPC_MSG *ncs_ipc_recv_common(
                if (ncs_ipc->msg_count == 0) {
                        /* 
                           We may reach here due to the following reasons.
-                          Blocking case: Between the select() and m_NCS_LOCK() 
calls above, 
+                          Blocking case: Between the osaf_poll_one_fd() and 
m_NCS_LOCK() calls above,
                           some thread detached from this mail-box, making this 
mailbox empty.
                           In such a case by the time we reach here, all 
indications
                           must have been removed.
diff --git a/osaf/libs/core/leap/sysf_tmr.c b/osaf/libs/core/leap/sysf_tmr.c
--- a/osaf/libs/core/leap/sysf_tmr.c
+++ b/osaf/libs/core/leap/sysf_tmr.c
@@ -39,6 +39,8 @@
 #include "ncssysf_tsk.h"
 #include "ncspatricia.h"
 #include "ncssysf_mem.h"
+#include "osaf_time.h"
+#include "osaf_poll.h"
 
 #include <stdlib.h>
 #include <sched.h>
@@ -307,37 +309,6 @@ static bool sysfTmrExpiry(SYSF_TMR_PAT_N
        return false;
 }
 
-static uint32_t ncs_tmr_select_intr_process(struct timeval *tv, struct
-                                        timespec *ts_current, uint64_t 
next_delay)
-{
-       uint64_t tmr_restart = 0;
-       uint64_t time_left = 0;
-       struct timespec ts_curr = *ts_current;
-       struct timespec ts_eint = { 0, 0 };
-
-       tv->tv_sec = tv->tv_usec = 0;
-
-       if (next_delay == 0) {
-               tv->tv_sec = 0xffffff;
-               tv->tv_usec = 0;
-               return NCSCC_RC_SUCCESS;
-       }
-
-       if (clock_gettime(CLOCK_MONOTONIC, &ts_eint)) {
-               perror("clock_gettime with MONOTONIC Failed \n");
-               return NCSCC_RC_FAILURE;
-       } else {
-               tmr_restart = TIMESPEC_DIFF_IN_NS(ts_eint, ts_curr);
-               time_left = ((next_delay * 1000000LL * 
NCS_MILLISECONDS_PER_TICK) - (tmr_restart));
-               if (time_left > 0) {
-                       tv->tv_sec = time_left / 1000000000LL;
-                       tv->tv_usec = ((time_left % 1000000000LL) / 1000);
-               }
-       }
-
-       return NCSCC_RC_SUCCESS;
-}
-
 static uint32_t ncs_tmr_engine(struct timeval *tv, uint64_t *next_delay)
 {
        uint64_t next_expiry = 0;
@@ -418,20 +389,15 @@ static uint32_t ncs_tmr_engine(struct ti
 static uint32_t ncs_tmr_wait(void)
 {
 
-       int rc = 0;
+       unsigned rc;
        int inds_rmvd;
-       int save_errno = 0;
 
        uint64_t next_delay = 0;
 
-       NCS_SEL_OBJ mbx_fd = gl_tcb.sel_obj;
-       NCS_SEL_OBJ highest_sel_obj;
-       NCS_SEL_OBJ_SET all_sel_obj;
        struct timeval tv = { 0xffffff, 0 };
        struct timespec ts_current = { 0, 0 };
-
-       m_NCS_SEL_OBJ_ZERO(&all_sel_obj);
-       highest_sel_obj = mbx_fd;
+       struct timespec ts;
+       struct pollfd set;
 
        if (clock_gettime(CLOCK_MONOTONIC, &ts_start)) {
                perror("clock_gettime with MONOTONIC Failed \n");
@@ -441,24 +407,15 @@ static uint32_t ncs_tmr_wait(void)
        ts_current = ts_start;
 
        while (true) {
- select_sleep:
-               m_NCS_SEL_OBJ_SET(mbx_fd, &all_sel_obj);
-               rc = select(highest_sel_obj.rmv_obj + 1, &all_sel_obj, NULL, 
NULL, &tv);
-               save_errno = errno;
+               set.fd = m_GET_FD_FROM_SEL_OBJ(gl_tcb.sel_obj);
+               set.events = POLLIN;
+               osaf_timeval_to_timespec(&tv, &ts);
+               rc = osaf_ppoll(&set, 1, next_delay != 0 ? &ts : NULL, NULL);
                m_NCS_LOCK(&gl_tcb.safe.enter_lock, NCS_LOCK_WRITE);
 
-               if (rc < 0) {
-                       if (save_errno != EINTR)
-                               assert(0);
+               if (rc == 1) {
+                       if (set.revents != POLLIN) osaf_abort(set.revents);
 
-                       if (ncs_tmr_select_intr_process(&tv, &ts_current, 
next_delay) == NCSCC_RC_SUCCESS) {
-                               m_NCS_UNLOCK(&gl_tcb.safe.enter_lock, 
NCS_LOCK_WRITE);
-                               goto select_sleep;
-                       } else {
-                               m_NCS_UNLOCK(&gl_tcb.safe.enter_lock, 
NCS_LOCK_WRITE);
-                               return NCSCC_RC_FAILURE;
-                       }
-               } else if (rc == 1) {
                        /* if select returned because of indication on sel_obj 
from sysfTmrDestroy */
                        if (tmr_destroying == true) {
                                /* Raise An indication */
@@ -588,7 +545,6 @@ bool sysfTmrDestroy(void)
 {
        SYSF_TMR *tmr;
        SYSF_TMR *free_tmr;
-       uint32_t timeout = 2000;        /* 20seconds */
        SYSF_TMR_PAT_NODE *tmp = NULL;
 
        /* There is only ever one timer per instance */
@@ -612,7 +568,7 @@ bool sysfTmrDestroy(void)
        m_NCS_UNLOCK(&gl_tcb.safe.enter_lock, NCS_LOCK_WRITE);  /* critical 
region END */
 
        /* Wait on Poll object */
-       m_NCS_SEL_OBJ_POLL_SINGLE_OBJ(tmr_destroy_syn_obj, &timeout);
+       osaf_poll_one_fd(m_GET_FD_FROM_SEL_OBJ(tmr_destroy_syn_obj), 20000);
 
        m_NCS_LOCK(&gl_tcb.safe.enter_lock, NCS_LOCK_WRITE);
        tmr = &gl_tcb.safe.dmy_keep;

------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to