Skip to content
Snippets Groups Projects
Commit 3175cf91 authored by Hongjia Cao's avatar Hongjia Cao Committed by Morris Jette
Browse files

change select() to poll() in waiting for a socket to be readable

select()/FD_ISSET() does not work for file descriptor larger than 1023.
parent 8e038b5c
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <poll.h>
#include <unistd.h> #include <unistd.h>
#include "src/common/macros.h" #include "src/common/macros.h"
...@@ -280,30 +281,30 @@ ssize_t fd_read_line(int fd, void *buf, size_t maxlen) ...@@ -280,30 +281,30 @@ ssize_t fd_read_line(int fd, void *buf, size_t maxlen)
* Return 0 when readable or -1 on error */ * Return 0 when readable or -1 on error */
extern int wait_fd_readable(int fd, int time_limit) extern int wait_fd_readable(int fd, int time_limit)
{ {
fd_set except_fds, read_fds; struct pollfd ufd;
struct timeval timeout; time_t start;
int rc; int rc, time_left;
FD_ZERO(&except_fds); start = time(NULL);
FD_SET(fd, &except_fds); time_left = time_limit;
FD_ZERO(&read_fds); ufd.fd = fd;
FD_SET(fd, &read_fds); ufd.events = POLLIN;
timeout.tv_sec = time_limit; ufd.revents = 0;
timeout.tv_usec = 0;
while (1) { while (1) {
rc = select(fd+1, &read_fds, NULL, &except_fds, &timeout); rc = poll(&ufd, 1, time_left * 1000);
if (rc > 0) { /* activity on this fd */ if (rc > 0) { /* activity on this fd */
if (FD_ISSET(fd, &read_fds)) if (ufd.revents & POLLIN)
return 0; return 0;
else /* Exception */ else /* Exception */
return -1; return -1;
} else if (rc == 0) { } else if (rc == 0) {
error("Timeout waiting for slurmstepd"); error("Timeout waiting for slurmstepd");
return -1; return -1;
} else if (errno == EINTR) { } else if (errno != EINTR) {
error("select(): %m"); error("poll(): %m");
return -1; return -1;
} else {
time_left = time_limit - (time(NULL) - start);
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment