Skip to content

Commit

Permalink
Fix problem with poll() on AIX.
Browse files Browse the repository at this point in the history
Its seems that unlike Linux, Solaris and Windows AIX has a somewhat
other idea in what flags it needs in the events field of the poll
structure. This patch makes poll() work on AIX and should also keep it
working on the other platforms.
  • Loading branch information
Marco van Wieringen committed Oct 27, 2013
1 parent 5a83d4d commit e001706
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
16 changes: 14 additions & 2 deletions src/lib/bnet_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ void bnet_thread_server(dlist *addr_list, int max_clients, alist *sockfds,
char buf[128];
#ifdef HAVE_POLL
nfds_t nfds;
int events;
struct pollfd *pfds;
#endif

Expand Down Expand Up @@ -235,9 +236,20 @@ void bnet_thread_server(dlist *addr_list, int max_clients, alist *sockfds,
memset(pfds, 0, sizeof(struct pollfd) * nfds);

nfds = 0;
events = POLLIN;
#if defined(POLLRDNORM)
events |= POLLRDNORM;
#endif
#if defined(POLLRDBAND)
events |= POLLRDBAND;
#endif
#if defined(POLLPRI)
events |= POLLPRI;
#endif

foreach_alist(fd_ptr, sockfds) {
pfds[nfds].fd = fd_ptr->fd;
pfds[nfds].events |= POLL_IN;
pfds[nfds].events = events;
nfds++;
}
#endif
Expand Down Expand Up @@ -285,7 +297,7 @@ void bnet_thread_server(dlist *addr_list, int max_clients, alist *sockfds,

cnt = 0;
foreach_alist(fd_ptr, sockfds) {
if (pfds[cnt++].revents & POLLIN) {
if (pfds[cnt++].revents & events) {
#endif
/*
* Got a connection, now accept it.
Expand Down
29 changes: 25 additions & 4 deletions src/lib/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,22 @@
int wait_for_readable_fd(int fd, int msec, bool ignore_interupts)
{
struct pollfd pfds[1];
int events;

events = POLLIN;
#if defined(POLLRDNORM)
events |= POLLRDNORM;
#endif
#if defined(POLLRDBAND)
events |= POLLRDBAND;
#endif
#if defined(POLLPRI)
events |= POLLPRI;
#endif

memset(pfds, 0, sizeof(pfds));
pfds[0].fd = fd;
pfds[0].events |= POLLIN;
pfds[0].events = events;

for ( ;; ) {
switch(poll(pfds, 1, msec)) {
Expand All @@ -56,7 +68,7 @@ int wait_for_readable_fd(int fd, int msec, bool ignore_interupts)
}
return -1; /* error return */
default:
if (pfds[0].revents & POLLIN) {
if (pfds[0].revents & events) {
return 1;
} else {
return 0;
Expand All @@ -73,10 +85,19 @@ int wait_for_readable_fd(int fd, int msec, bool ignore_interupts)
int wait_for_writable_fd(int fd, int msec, bool ignore_interupts)
{
struct pollfd pfds[1];
int events;

events = POLLOUT;
#if defined(POLLWRNORM)
events |= POLLWRNORM;
#endif
#if defined POLLWRBAND
events |= POLLWRBAND;
#endif

memset(pfds, 0, sizeof(pfds));
pfds[0].fd = fd;
pfds[0].events |= POLLOUT;
pfds[0].events = events;

for ( ;; ) {
switch(poll(pfds, 1, msec)) {
Expand All @@ -88,7 +109,7 @@ int wait_for_writable_fd(int fd, int msec, bool ignore_interupts)
}
return -1; /* error return */
default:
if (pfds[0].revents & POLLOUT) {
if (pfds[0].revents & events) {
return 1;
} else {
return 0;
Expand Down

0 comments on commit e001706

Please sign in to comment.