X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=c48f1fef175708331706594f51d54e6d69d0662f;hp=5db30b63fd9ed62148b8d04390ec8456826337a3;hb=e57d2b9211bb734b71838142a7936fe6dfdc449c;hpb=f2a7b00cf72104a38733b7bf3add9fb19dd71c93 diff --git a/fd.c b/fd.c index 5db30b63..c48f1fef 100644 --- a/fd.c +++ b/fd.c @@ -1,4 +1,5 @@ #include "para.h" +#include "error.h" /** * check whether a file exists * @@ -12,3 +13,27 @@ int file_exists(const char *fn) 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; +} +