From 32908ad06dc6f23dbae528b1a289a4990de40910 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20Salvet?= Date: Thu, 4 May 2006 17:40:59 +0000 Subject: [PATCH] Use poll() instead of select() in order to work in apps with fd>1023 open (bug #16506). --- org.glite.lb.common/src/lb_plain_io.c | 37 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/org.glite.lb.common/src/lb_plain_io.c b/org.glite.lb.common/src/lb_plain_io.c index 7915dfa..a1e4dd2 100644 --- a/org.glite.lb.common/src/lb_plain_io.c +++ b/org.glite.lb.common/src/lb_plain_io.c @@ -13,6 +13,10 @@ #include #include #include +#include +#ifndef INFTIM +#define INFTIM (-1) +#endif #include "lb_plain_io.h" @@ -68,7 +72,8 @@ int edg_wll_plain_read( struct timeval *to) { int ct, toread = 0; - fd_set fds; + struct pollfd pollfds[1]; + int polltime = 0; struct timeval timeout, before, after; @@ -89,11 +94,16 @@ int edg_wll_plain_read( 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 ) { @@ -173,7 +183,8 @@ int edg_wll_plain_write_full( { 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; @@ -188,12 +199,18 @@ int edg_wll_plain_write_full( 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; } -- 1.8.2.3