]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - fd.c
fd.c: Prefer poll(2) over select(2) for write_ok().
[paraslash.git] / fd.c
diff --git a/fd.c b/fd.c
index d72096e1e9674fb0d5307dc4005f8a3d3aa7e6dc..2f3ec997c11e796fc5ff8ada46c40a662e0aef13 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -6,6 +6,7 @@
 #include <sys/types.h>
 #include <dirent.h>
 #include <sys/mman.h>
+#include <poll.h>
 
 #include "para.h"
 #include "error.h"
@@ -651,14 +652,17 @@ int para_munmap(void *start, size_t length)
  * \return positive if fd is ready for writing, zero if it isn't, negative if
  * an error occurred.
  */
-
 int write_ok(int fd)
 {
-       fd_set wfds;
+       int ret;
+       struct pollfd pfd = {.fd = fd, .events = POLLOUT};
 
-       FD_ZERO(&wfds);
-       FD_SET(fd, &wfds);
-       return para_select(fd + 1, NULL, &wfds, 0);
+       do
+               ret = poll(&pfd, 1, 0);
+       while (ret < 0 && errno == EINTR);
+       if (ret < 0)
+               return -ERRNO_TO_PARA_ERROR(errno);
+       return pfd.revents & POLLOUT;
 }
 
 /**