From: Anders W. <and...@er...> - 2013-10-31 13:25:10
|
contrib/plmc/plmcd/plmcd.c | 18 ++++++-------- osaf/libs/agents/saf/plma/plma_mds.c | 7 +---- osaf/services/saf/plmsv/plms/hpi_intf/plms_hrb.c | 28 +++++++---------------- 3 files changed, 19 insertions(+), 34 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/contrib/plmc/plmcd/plmcd.c b/contrib/plmc/plmcd/plmcd.c --- a/contrib/plmc/plmcd/plmcd.c +++ b/contrib/plmc/plmcd/plmcd.c @@ -43,6 +43,7 @@ #include <pthread.h> #include <libgen.h> #include <limits.h> +#include <poll.h> #include <netinet/in.h> #include <netinet/tcp.h> @@ -373,8 +374,7 @@ int process_cmd(char *msg) */ int nbconnect(struct sockaddr_in *sin) { - fd_set wset; - struct timeval tv; + struct pollfd wset; socklen_t len; int flags, ret, opt; @@ -393,20 +393,18 @@ int nbconnect(struct sockaddr_in *sin) ret = connect(sockd, (struct sockaddr *)sin, sizeof(struct sockaddr_in)); if (ret < 0) { if (errno == EINPROGRESS) { - /* select on the fd until we get a connection, timeout, or error */ + /* poll the fd until we get a connection, timeout, or error */ while(1) { - tv.tv_sec = PLMC_TCP_TIMEOUT_SECS; - tv.tv_usec = 0; - FD_ZERO(&wset); - FD_SET(sockd, &wset); + wset.fd = sockd; + wset.events = POLLOUT; - ret = select(sockd + 1, NULL, &wset, NULL, &tv); + ret = poll(&wset, 1, PLMC_TCP_TIMEOUT_SECS * 1000); if (ret < 0 && errno != EINTR) { - syslog(LOG_ERR, "Error select: %m"); + syslog(LOG_ERR, "Error poll: %m"); return -1; } else if (ret > 0) { - // Socket selected for write + // Socket polled for write len = sizeof(int); if (getsockopt(sockd, SOL_SOCKET, SO_ERROR, (void*)(&opt), &len) < 0) { syslog(LOG_ERR, "Error getsockopt: %m"); diff --git a/osaf/libs/agents/saf/plma/plma_mds.c b/osaf/libs/agents/saf/plma/plma_mds.c --- a/osaf/libs/agents/saf/plma/plma_mds.c +++ b/osaf/libs/agents/saf/plma/plma_mds.c @@ -24,6 +24,7 @@ *****************************************************************************/ #include "plma.h" +#include "osaf_poll.h" MDS_CLIENT_MSG_FORMAT_VER plma_plms_msg_fmt_table[PLMA_WRT_PLMS_SUBPART_VER_RANGE] = { 1 }; @@ -334,8 +335,6 @@ done: ***************************************************************************/ void plma_sync_with_plms() { - NCS_SEL_OBJ_SET set; - uint32_t timeout = 3000; PLMA_CB *cb = plma_ctrlblk; TRACE_ENTER(); @@ -353,9 +352,7 @@ void plma_sync_with_plms() m_NCS_UNLOCK(&cb->cb_lock, NCS_LOCK_WRITE); /** Await indication from MDS saying PLMS is up */ - m_NCS_SEL_OBJ_ZERO(&set); - m_NCS_SEL_OBJ_SET(cb->sel_obj, &set); - m_NCS_SEL_OBJ_SELECT(cb->sel_obj, &set, 0, 0, &timeout); + osaf_poll_one_fd(m_GET_FD_FROM_SEL_OBJ(cb->sel_obj), 30000); /* Destroy the sync - object */ m_NCS_LOCK(&cb->cb_lock, NCS_LOCK_WRITE); diff --git a/osaf/services/saf/plmsv/plms/hpi_intf/plms_hrb.c b/osaf/services/saf/plmsv/plms/hpi_intf/plms_hrb.c --- a/osaf/services/saf/plmsv/plms/hpi_intf/plms_hrb.c +++ b/osaf/services/saf/plmsv/plms/hpi_intf/plms_hrb.c @@ -38,6 +38,7 @@ #include "plms_hrb.h" #include "plms_hsm.h" #include "plms_evt.h" +#include "osaf_poll.h" static PLMS_HRB_CB _hrb_cb; PLMS_HRB_CB *hrb_cb = &_hrb_cb; @@ -201,13 +202,9 @@ static void *plms_hrb(void) PLMS_HRB_CB *cb = hrb_cb; PLMS_HPI_REQ *hpi_req = NULL; NCS_SEL_OBJ mbx_fd = m_NCS_IPC_GET_SEL_OBJ(&cb->mbx); - NCS_SEL_OBJ_SET sel_obj; TRACE_ENTER(); - m_NCS_SEL_OBJ_ZERO(&sel_obj); - m_NCS_SEL_OBJ_SET(mbx_fd,&sel_obj); - /* Wait on condition variable for the HA role from PLMS main thread */ pthread_mutex_lock(&hrb_ha_state.mutex); if(hrb_ha_state.state != SA_AMF_HA_ACTIVE){ @@ -216,27 +213,20 @@ static void *plms_hrb(void) } pthread_mutex_unlock(&hrb_ha_state.mutex); - while (m_NCS_SEL_OBJ_SELECT(mbx_fd,&sel_obj,0,0,0) != -1){ + while (osaf_poll_one_fd(m_GET_FD_FROM_SEL_OBJ(mbx_fd), -1) != -1) { /* process the Mail box */ - if (m_NCS_SEL_OBJ_ISSET(mbx_fd,&sel_obj)){ - /* Process messages delivered on mailbox */ - while(NULL != (hpi_req = + /* Process messages delivered on mailbox */ + while(NULL != (hpi_req = (PLMS_HPI_REQ *)m_NCS_IPC_NON_BLK_RECEIVE(&cb->mbx,hpi_req))){ - /*Process the received message*/ - hrb_process_hpi_req(hpi_req); + /*Process the received message*/ + hrb_process_hpi_req(hpi_req); - if(hpi_req->entity_path) - free(hpi_req->entity_path); - free(hpi_req); - } - - + if(hpi_req->entity_path) + free(hpi_req->entity_path); + free(hpi_req); } - /* do the fd set for the select obj */ - m_NCS_SEL_OBJ_SET(mbx_fd,&sel_obj); - if(hrb_ha_state.state != SA_AMF_HA_ACTIVE){ /* Wait on condition variable for the HA role from PLMS main thread */ |