#include "util/netevent.h"
#include "util/fptr_wlist.h"
#include "util/ub_event.h"
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
#ifndef USE_WINSOCK
/* on unix */
return 1;
}
-/** perform a select() on the fd */
+/** perform poll() on the fd */
static int
pollit(int fd, struct timeval* t)
{
- fd_set r;
+ struct pollfd fds;
+ int pret;
+ int msec = -1;
+ memset(&fds, 0, sizeof(fds));
+ fds.fd = fd;
+ fds.events = POLLIN | POLLERR | POLLHUP;
#ifndef S_SPLINT_S
- FD_ZERO(&r);
- FD_SET(FD_SET_T fd, &r);
+ if(t)
+ msec = t->tv_sec*1000 + t->tv_usec/1000;
#endif
- if(select(fd+1, &r, NULL, NULL, t) == -1) {
+
+ pret = poll(&fds, 1, msec);
+
+ if(pret == -1)
return 0;
- }
- errno = 0;
- return (int)(FD_ISSET(fd, &r));
+ if(pret != 0)
+ return 1;
+ return 0;
}
int tube_poll(struct tube* tube)
int tube_wait_timeout(struct tube* tube, int msec)
{
- struct timeval t;
- int fd = tube->sr;
- fd_set r;
- t.tv_sec = msec/1000;
- t.tv_usec = (msec%1000)*1000;
-#ifndef S_SPLINT_S
- FD_ZERO(&r);
- FD_SET(FD_SET_T fd, &r);
-#endif
+ int ret = 0;
+
while(1) {
- if(select(fd+1, &r, NULL, NULL, &t) == -1) {
+ struct pollfd fds;
+ memset(&fds, 0, sizeof(fds));
+
+ fds.fd = tube->sr;
+ fds.events = POLLIN | POLLERR | POLLHUP;
+ ret = poll(&fds, 1, msec);
+
+ if(ret == -1) {
if(errno == EAGAIN || errno == EINTR)
continue;
return -1;
}
break;
}
- return (int)(FD_ISSET(fd, &r));
+
+ if(ret != 0)
+ return 1;
+ return 0;
}
int tube_read_fd(struct tube* tube)