From fb341f1285f8b98c708c9309538489251d0f1907 Mon Sep 17 00:00:00 2001 From: Bill Williams Date: Tue, 9 Jul 2019 14:30:30 -0700 Subject: [PATCH 1/3] replace select with poll --- src/nopoll_decl.h | 3 ++- src/nopoll_io.c | 59 +++++++++++++++++++++++------------------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/nopoll_decl.h b/src/nopoll_decl.h index 0c7d12b..780da60 100644 --- a/src/nopoll_decl.h +++ b/src/nopoll_decl.h @@ -216,7 +216,8 @@ #include #include #include -#include +/* #include */ +#define NOPOLL_HAVE_POLL 1 #include #include #include diff --git a/src/nopoll_io.c b/src/nopoll_io.c index eb067f9..87c015c 100644 --- a/src/nopoll_io.c +++ b/src/nopoll_io.c @@ -40,9 +40,8 @@ typedef struct _noPollSelect { noPollCtx * ctx; - fd_set set; + struct pollfd * fd_table; int length; - int max_fds; } noPollSelect; /** @@ -57,9 +56,6 @@ noPollPtr nopoll_io_wait_select_create (noPollCtx * ctx) /* set default behaviour expected for the set */ select->ctx = ctx; - - /* clear the set */ - FD_ZERO (&(select->set)); return select; } @@ -72,10 +68,11 @@ noPollPtr nopoll_io_wait_select_create (noPollCtx * ctx) */ void nopoll_io_wait_select_destroy (noPollCtx * ctx, noPollPtr fd_group) { - fd_set * __fd_set = (fd_set *) fd_group; + noPollSelect * select = (noPollSelect *) __fd_group; /* release memory allocated */ - nopoll_free (__fd_set); + nopoll_free (select->fd_table); + nopoll_free (select); /* nothing more to do */ return; @@ -92,8 +89,9 @@ void nopoll_io_wait_select_clear (noPollCtx * ctx, noPollPtr __fd_group) noPollSelect * select = (noPollSelect *) __fd_group; /* clear the fd set */ + nopoll_free (select->fd_table); + select->fd_table = NULL; select->length = 0; - FD_ZERO (&(select->set)); /* nothing more to do */ return; @@ -112,13 +110,10 @@ void nopoll_io_wait_select_clear (noPollCtx * ctx, noPollPtr __fd_group) int nopoll_io_wait_select_wait (noPollCtx * ctx, noPollPtr __fd_group) { int result = -1; - struct timeval tv; noPollSelect * _select = (noPollSelect *) __fd_group; /* init wait */ - tv.tv_sec = 0; - tv.tv_usec = 500000; - result = select (_select->max_fds + 1, &(_select->set), NULL, NULL, &tv); + result = poll (_select->fd_table, _select->length, 500); /* check result */ if ((result == NOPOLL_SOCKET_ERROR) && (errno == NOPOLL_EINTR)) @@ -138,30 +133,29 @@ int nopoll_io_wait_select_wait (noPollCtx * ctx, noPollPtr __fd_group) nopoll_bool nopoll_io_wait_select_add_to (int fds, noPollCtx * ctx, noPollConn * conn, - noPollPtr __fd_set) + noPollPtr __fd_group) { - noPollSelect * select = (noPollSelect *) __fd_set; + noPollSelect * select = (noPollSelect *) __fd_group; + struct pollfd * fd_table; + struct pollfd * poll_fd; - if (fds < 0 || fds >= FD_SETSIZE) { + if (fds < 0) { nopoll_log (ctx, NOPOLL_LEVEL_CRITICAL, "received a non valid socket (%d), unable to add to the set", fds); return nopoll_false; } - if ((select->length - 1) > FD_SETSIZE) { - nopoll_log (ctx, NOPOLL_LEVEL_CRITICAL, - "Unable to add requested socket (%d), reached max FD_SETSIZE=%d (select->length=%d)", fds, FD_SETSIZE, select->length); - return nopoll_false; - } /* end if */ - - /* set the value */ - FD_SET (fds, &(select->set)); /* update length */ select->length++; - /* update max fds */ - if (fds > select->max_fds) - select->max_fds = fds; + /* set the value */ + select->fd_table = nopoll_realloc (select->fd_table, + select->length * sizeof(struct pollfd)); + fd_table = select->fd_table; + poll_fd = &fd_table[select->length-1]; + poll_fd->fd = fds; + poll_fd->events = POLLIN; + poll_fd->revents = 0; return nopoll_true; } @@ -179,17 +173,22 @@ nopoll_bool nopoll_io_wait_select_add_to (int fds, */ nopoll_bool nopoll_io_wait_select_is_set (noPollCtx * ctx, int fds, - noPollPtr __fd_set) + noPollPtr __fd_group) { - noPollSelect * select = (noPollSelect *) __fd_set; + noPollSelect * select = (noPollSelect *) __fd_group; + struct pollfd * fd_table = select->fd_table; + int i; - if (fds < 0 || fds >= FD_SETSIZE) { + if (fds < 0) { nopoll_log (ctx, NOPOLL_LEVEL_CRITICAL, "received a non valid socket (%d), unable to test in the set", fds); return nopoll_false; } - return FD_ISSET (fds, &(select->set)); + for (i=0; ilength; i++) + if (fds == fd_table[i].fd) + return (nopoll_bool) (fd_table[i].revents & POLLIN); + return nopoll_false; } From f761cd83fabffee5d1f0e99eef5c0c971e888a8f Mon Sep 17 00:00:00 2001 From: Bill Williams Date: Tue, 9 Jul 2019 17:07:51 -0700 Subject: [PATCH 2/3] fix parameter name in nopoll_io_wait_select_destroy --- src/nopoll_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nopoll_io.c b/src/nopoll_io.c index 87c015c..1a326ca 100644 --- a/src/nopoll_io.c +++ b/src/nopoll_io.c @@ -66,7 +66,7 @@ noPollPtr nopoll_io_wait_select_create (noPollCtx * ctx) * * @param fd_group The fd group to be deallocated. */ -void nopoll_io_wait_select_destroy (noPollCtx * ctx, noPollPtr fd_group) +void nopoll_io_wait_select_destroy (noPollCtx * ctx, noPollPtr __fd_group) { noPollSelect * select = (noPollSelect *) __fd_group; From e9b3a607e62c17f95abc2355e648c535f6c75b6e Mon Sep 17 00:00:00 2001 From: Bill Williams Date: Thu, 11 Jul 2019 13:53:55 -0700 Subject: [PATCH 3/3] update configure to define support for poll --- configure.ac | 21 +++++++++++++++++++++ src/nopoll_decl.h | 3 +-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index f6b69da..485a15a 100644 --- a/configure.ac +++ b/configure.ac @@ -86,6 +86,23 @@ int main() AM_CONDITIONAL(ENABLE_EPOLL_SUPPORT, test "x$enable_cv_epoll" = "xyes") dnl select the best I/O platform + +have_epoll="" +if test x$enable_cv_epoll = xyes; then + export have_epoll="/** + * @brief Indicates where we have support for epoll. + */ +#define NOPOLL_HAVE_EPOLL (1)" +fi + +have_poll="" +if test x$enable_poll = xyes; then + export have_poll="/** + * @brief Indicates where we have support for poll. + */ +#define NOPOLL_HAVE_POLL (1)" +fi + if test x$enable_cv_epoll = xyes ; then default_platform="epoll" elif test x$enable_poll = xyes ; then @@ -336,6 +353,10 @@ $vasprintf_status $have_64bit_support +$have_epoll + +$have_poll + $ssl_sslv23_header $ssl_sslv3_header diff --git a/src/nopoll_decl.h b/src/nopoll_decl.h index 780da60..0c7d12b 100644 --- a/src/nopoll_decl.h +++ b/src/nopoll_decl.h @@ -216,8 +216,7 @@ #include #include #include -/* #include */ -#define NOPOLL_HAVE_POLL 1 +#include #include #include #include