]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - fd.c
introduce mark_fd_nonblock()
[paraslash.git] / fd.c
diff --git a/fd.c b/fd.c
index 5db30b63fd9ed62148b8d04390ec8456826337a3..c48f1fef175708331706594f51d54e6d69d0662f 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -1,4 +1,5 @@
 #include "para.h"
 #include "para.h"
+#include "error.h"
 /**
  * check whether a file exists
  *
 /**
  * check whether a file exists
  *
@@ -12,3 +13,27 @@ int file_exists(const char *fn)
 
        return !stat(fn, &statbuf);
 }
 
        return !stat(fn, &statbuf);
 }
+
+int para_select(int n, fd_set *readfds, fd_set *writefds,
+               struct timeval *timeout)
+{
+       int ret, err;
+       do {
+               ret = select(n, readfds, writefds, NULL, timeout);
+               err = errno;
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0)
+               PARA_CRIT_LOG("select error (%s)\n", strerror(err));
+       return ret;
+}
+
+int mark_fd_nonblock(int fd)
+{
+       int flags = fcntl(fd, F_GETFL);
+       if (flags < 0)
+               return -E_F_GETFL;
+       if (fcntl(fd, F_SETFL, ((long)flags) | O_NONBLOCK) < 0)
+               return -E_F_SETFL;
+       return 1;
+}
+