From daa2217ab852cd295f97ce1805a529109da0b087 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20Salvet?= Date: Thu, 4 May 2006 17:41:22 +0000 Subject: [PATCH] Use poll() instead of select() in order to work in apps with fd>1023 open (bug #16506). --- org.glite.security.proxyrenewal/src/api.c | 12 ++++++------ org.glite.security.proxyrenewal/src/common.c | 22 ++++++++++------------ org.glite.security.proxyrenewal/src/renewal_locl.h | 5 +++++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/org.glite.security.proxyrenewal/src/api.c b/org.glite.security.proxyrenewal/src/api.c index 850aebf..a72d692 100644 --- a/org.glite.security.proxyrenewal/src/api.c +++ b/org.glite.security.proxyrenewal/src/api.c @@ -210,7 +210,7 @@ do_connect(char *socket_name, struct timeval *timeout, int *sock) struct sockaddr_un my_addr; int s; int ret; - struct timeval before,after,to; + struct timeval before,after; int sock_err; socklen_t err_len; @@ -234,13 +234,13 @@ do_connect(char *socket_name, struct timeval *timeout, int *sock) ret = connect(s, (struct sockaddr *) &my_addr, sizeof(my_addr)); if (ret == -1) { if (errno == EINPROGRESS) { - fd_set fds; + struct pollfd pollfds[1]; - FD_ZERO(&fds); - FD_SET(s, &fds); - memcpy(&to, timeout, sizeof(to)); + pollfds[0].fd = s; + pollfds[0].events = POLLOUT; + gettimeofday(&before,NULL); - switch (select(s+1, NULL, &fds, NULL, &to)) { + switch (poll(pollfds, 1, timeout->tv_sec*1000+timeout->tv_usec/1000)) { case -1: close(s); return errno; case 0: close(s); diff --git a/org.glite.security.proxyrenewal/src/common.c b/org.glite.security.proxyrenewal/src/common.c index 86cfa4a..206bc2f 100644 --- a/org.glite.security.proxyrenewal/src/common.c +++ b/org.glite.security.proxyrenewal/src/common.c @@ -9,19 +9,18 @@ nread(int sock, struct timeval *to, char *buf, size_t buf_len, size_t *read_len) int count; size_t remain = buf_len; char *cbuf = buf; - fd_set fds; - struct timeval timeout,before,after; + struct pollfd pollfds[1]; + struct timeval before,after; int ret; if (to) { - memcpy(&timeout,to,sizeof(timeout)); gettimeofday(&before,NULL); } while (remain > 0) { - FD_ZERO(&fds); - FD_SET(sock,&fds); - switch (select(sock+1, &fds, NULL, NULL, to ? &timeout : NULL)) { + pollfds[0].fd = sock; + pollfds[0].events = POLLIN; + switch (poll(pollfds, 1, to ? (to->tv_sec*1000+to->tv_usec/1000) : INFTIM)) { case 0: ret = EDG_WLPR_ERROR_TIMEOUT; goto end; @@ -68,19 +67,18 @@ nwrite(int sock, struct timeval *to, const char *buf, size_t buf_len) const char *cbuf = buf; int count; size_t remain = buf_len; - fd_set fds; - struct timeval timeout,before,after; + struct pollfd pollfds[1]; + struct timeval before,after; int ret; if (to) { - memcpy(&timeout,to,sizeof(timeout)); gettimeofday(&before,NULL); } while (remain > 0) { - FD_ZERO(&fds); - FD_SET(sock,&fds); - switch (select(sock+1, NULL, &fds, NULL, to ? &timeout : NULL)) { + pollfds[0].fd = sock; + pollfds[0].events = POLLOUT; + switch (poll(pollfds, 1, to ? (to->tv_sec*1000+to->tv_usec/1000) : INFTIM)) { case 0: ret = EDG_WLPR_ERROR_TIMEOUT; goto end; case -1: ret = EDG_WLPR_ERROR_ERRNO; diff --git a/org.glite.security.proxyrenewal/src/renewal_locl.h b/org.glite.security.proxyrenewal/src/renewal_locl.h index 9d0774d..256eb26 100644 --- a/org.glite.security.proxyrenewal/src/renewal_locl.h +++ b/org.glite.security.proxyrenewal/src/renewal_locl.h @@ -22,6 +22,11 @@ #include #include #include +#include +#ifndef INFTIM +#define INFTIM (-1) +#endif + #include #include #include -- 1.8.2.3