Use poll() instead of select() in order to work in apps with fd>1023 open
authorZdeněk Salvet <salvet@ics.muni.cz>
Thu, 4 May 2006 17:41:22 +0000 (17:41 +0000)
committerZdeněk Salvet <salvet@ics.muni.cz>
Thu, 4 May 2006 17:41:22 +0000 (17:41 +0000)
(bug #16506).

org.glite.security.proxyrenewal/src/api.c
org.glite.security.proxyrenewal/src/common.c
org.glite.security.proxyrenewal/src/renewal_locl.h

index 850aebf..a72d692 100644 (file)
@@ -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);
index 86cfa4a..206bc2f 100644 (file)
@@ -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;
index 9d0774d..256eb26 100644 (file)
 #include <sys/stat.h>
 #include <sys/file.h>
 #include <sys/wait.h>
+#include <poll.h>
+#ifndef INFTIM
+#define INFTIM (-1)
+#endif
+
 #include <openssl/md5.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>