diff options
author | rofl0r <rofl0r@users.noreply.github.com> | 2020-09-15 20:01:01 +0100 |
---|---|---|
committer | rofl0r <rofl0r@users.noreply.github.com> | 2020-09-15 23:12:00 +0100 |
commit | bd92446184fe692e0ceda700945c588ae56cc6cd (patch) | |
tree | 56aa6396de2c6ae88f96d9bf5cb71369caa89031 | |
parent | 10cdee3bc55274d7f6278cdd0c66edacb5b520a5 (diff) |
use poll() where available
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/mypoll.c | 14 | ||||
-rw-r--r-- | src/mypoll.h | 11 |
3 files changed, 20 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac index 7de6087..cf2f19c 100644 --- a/configure.ac +++ b/configure.ac @@ -141,7 +141,7 @@ AC_HEADER_STDC AC_HEADER_TIME AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([sys/ioctl.h alloca.h memory.h malloc.h sysexits.h \ - values.h]) + values.h poll.h]) dnl Checks for libary functions AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK diff --git a/src/mypoll.c b/src/mypoll.c index 0e06805..495e2c3 100644 --- a/src/mypoll.c +++ b/src/mypoll.c @@ -1,8 +1,14 @@ #include "mypoll.h" -#define MYPOLL_READ (1<<1) -#define MYPOLL_WRITE (1<<2) - +#ifdef HAVE_POLL_H +int mypoll(pollfd_struct* fds, int nfds, int timeout) { + int i, ret; + for(i=0; i<nfds; ++i) if(!fds[i].events) fds[i].fd=~fds[i].fd; + ret = poll(fds, nfds, timeout <= 0 ? timeout : timeout*1000); + for(i=0; i<nfds; ++i) if(!fds[i].events) fds[i].fd=~fds[i].fd; + return ret; +} +#else int mypoll(pollfd_struct* fds, int nfds, int timeout) { fd_set rset, wset, *r=0, *w=0; int i, ret, maxfd=-1; @@ -39,4 +45,4 @@ int mypoll(pollfd_struct* fds, int nfds, int timeout) { } return ret; } - +#endif diff --git a/src/mypoll.h b/src/mypoll.h index 114c0f8..a336680 100644 --- a/src/mypoll.h +++ b/src/mypoll.h @@ -1,21 +1,28 @@ #ifndef MYPOLL_H #define MYPOLL_H -#include <sys/select.h> +#include "config.h" #ifdef HAVE_POLL_H + #include <poll.h> typedef struct pollfd pollfd_struct; + +#define MYPOLL_READ POLLIN +#define MYPOLL_WRITE POLLOUT + #else + +#include <sys/select.h> typedef struct mypollfd { int fd; short events; short revents; } pollfd_struct; -#endif #define MYPOLL_READ (1<<1) #define MYPOLL_WRITE (1<<2) +#endif int mypoll(pollfd_struct* fds, int nfds, int timeout); |