Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace select with poll in nopoll #36

Open
wants to merge 3 commits into
base: nopoll_yocto
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -336,6 +353,10 @@ $vasprintf_status

$have_64bit_support

$have_epoll

$have_poll

$ssl_sslv23_header

$ssl_sslv3_header
Expand Down
61 changes: 30 additions & 31 deletions src/nopoll_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@

typedef struct _noPollSelect {
noPollCtx * ctx;
fd_set set;
struct pollfd * fd_table;
int length;
int max_fds;
} noPollSelect;

/**
Expand All @@ -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;
}
Expand All @@ -70,12 +66,13 @@ 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variables with double underscores are generally reserved by libc as private namespace.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numerous nopoll modules violate this rule, with numerous function names, parameter names, and variable names that start with double underscores.
So the question for us would be how to deal with software we didn't write that has already been written to a standard we don't agree with.
In this specific case, I thought it was best to just conform to the naming convention already being used in this module, nopoll_io.c.

{
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;
Expand All @@ -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;
Expand All @@ -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))
Expand All @@ -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;
}
Expand All @@ -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; i<select->length; i++)
if (fds == fd_table[i].fd)
return (nopoll_bool) (fd_table[i].revents & POLLIN);
return nopoll_false;
}


Expand Down