use poll() where available

This commit is contained in:
rofl0r 2020-09-15 20:01:01 +01:00
parent 10cdee3bc5
commit bd92446184
3 changed files with 20 additions and 7 deletions

View File

@ -141,7 +141,7 @@ AC_HEADER_STDC
AC_HEADER_TIME AC_HEADER_TIME
AC_HEADER_SYS_WAIT AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([sys/ioctl.h alloca.h memory.h malloc.h sysexits.h \ 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 dnl Checks for libary functions
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK

View File

@ -1,8 +1,14 @@
#include "mypoll.h" #include "mypoll.h"
#define MYPOLL_READ (1<<1) #ifdef HAVE_POLL_H
#define MYPOLL_WRITE (1<<2) 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) { int mypoll(pollfd_struct* fds, int nfds, int timeout) {
fd_set rset, wset, *r=0, *w=0; fd_set rset, wset, *r=0, *w=0;
int i, ret, maxfd=-1; int i, ret, maxfd=-1;
@ -39,4 +45,4 @@ int mypoll(pollfd_struct* fds, int nfds, int timeout) {
} }
return ret; return ret;
} }
#endif

View File

@ -1,21 +1,28 @@
#ifndef MYPOLL_H #ifndef MYPOLL_H
#define MYPOLL_H #define MYPOLL_H
#include <sys/select.h> #include "config.h"
#ifdef HAVE_POLL_H #ifdef HAVE_POLL_H
#include <poll.h> #include <poll.h>
typedef struct pollfd pollfd_struct; typedef struct pollfd pollfd_struct;
#define MYPOLL_READ POLLIN
#define MYPOLL_WRITE POLLOUT
#else #else
#include <sys/select.h>
typedef struct mypollfd { typedef struct mypollfd {
int fd; int fd;
short events; short events;
short revents; short revents;
} pollfd_struct; } pollfd_struct;
#endif
#define MYPOLL_READ (1<<1) #define MYPOLL_READ (1<<1)
#define MYPOLL_WRITE (1<<2) #define MYPOLL_WRITE (1<<2)
#endif
int mypoll(pollfd_struct* fds, int nfds, int timeout); int mypoll(pollfd_struct* fds, int nfds, int timeout);