#include <netdb.h>
#include <netinet/in.h>
#include <errno.h>
+#include <poll.h>
+#ifndef INFTIM
+#define INFTIM (-1)
+#endif
#include "lb_plain_io.h"
struct timeval *to)
{
int ct, toread = 0;
- fd_set fds;
+ struct pollfd pollfds[1];
+ int polltime = 0;
struct timeval timeout, before, after;
toread = 0;
do {
- FD_ZERO(&fds);
- FD_SET(conn->sock, &fds);
- switch (select(conn->sock+1, &fds, NULL, NULL, to ? &timeout : NULL)) {
- case 0: errno = ETIMEDOUT; goto cleanup; break;
- case -1: goto cleanup; break;
+ pollfds[0].fd = conn->sock;
+ pollfds[0].events = POLLIN;
+ polltime = to ? (timeout.tv_sec*1000+timeout.tv_usec/1000) : INFTIM;
+ switch (poll(pollfds, 1, polltime)) {
+ case 0: errno = ETIMEDOUT; goto cleanup; break;
+ case -1: goto cleanup; break;
+ default: if (!(pollfds[0].revents & POLLIN)) {
+ errno = EIO;
+ goto cleanup; break;
+ }
}
if ( conn->bufUse == conn->bufSize ) {
{
size_t written = 0;
int ct = -1;
- fd_set fds;
+ struct pollfd pollfds[1];
+ int polltime = 0;
struct timeval timeout, before, after;
struct sigaction sa,osa;
errno = 0;
while ( written < bufsz ) {
- FD_ZERO(&fds);
- FD_SET(conn->sock, &fds);
- switch ( select(conn->sock+1, NULL, &fds, NULL, to? &timeout: NULL) ) {
+ pollfds[0].fd = conn->sock;
+ pollfds[0].events = POLLOUT;
+ polltime = to ? (timeout.tv_sec*1000+timeout.tv_usec/1000) : INFTIM;
+
+ switch (poll(pollfds, 1, polltime)) {
case 0: errno = ETIMEDOUT; goto end; break;
case -1: goto end; break;
+ default: if (!(pollfds[0].revents & POLLOUT)) {
+ errno = ENOTCONN;
+ goto end; break;
+ }
}
if ( (ct=write(conn->sock, ((char*)buf)+written, bufsz-written)) < 0 ) {
if ( errno == EINTR ) { errno = 0; continue; }