X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=fd.c;h=763f756cdc3b5086ee9d26f432dbbfb760e02e4a;hb=539d39f36549c10656d8b31f3dea32702e9649df;hp=f7e0e42b3680707774cddd5c3bbd0c56cfc54bcb;hpb=4ddaef74ff8f605a31c499d77fcaaffa7a3708c0;p=paraslash.git diff --git a/fd.c b/fd.c index f7e0e42b..763f756c 100644 --- a/fd.c +++ b/fd.c @@ -6,7 +6,6 @@ #include #include #include -#include #include "para.h" #include "error.h" @@ -270,7 +269,7 @@ int read_nonblock(int fd, void *buf, size_t sz, size_t *num_bytes) int read_pattern(int fd, const char *pattern, size_t bufsize) { size_t n, len; - char *buf = para_malloc(bufsize + 1); + char *buf = alloc(bufsize + 1); int ret = read_nonblock(fd, buf, bufsize, &n); buf[n] = '\0'; @@ -309,37 +308,6 @@ bool file_exists(const char *fn) return !stat(fn, &statbuf); } -/** - * Paraslash's wrapper for select(2). - * - * It calls select(2) (with no exceptfds) and starts over if select() was - * interrupted by a signal. - * - * \param n The highest-numbered descriptor in any of the two sets, plus 1. - * \param readfds fds that should be checked for readability. - * \param writefds fds that should be checked for writablility. - * \param timeout Upper bound in milliseconds. - * - * \return The return value of the underlying select() call on success, the - * negative system error code on errors. - * - * All arguments are passed verbatim to select(2). - * \sa select(2) select_tut(2). - */ -int para_select(int n, fd_set *readfds, fd_set *writefds, int timeout) -{ - int ret; - struct timeval tv; - - ms2tv(timeout, &tv); - do - ret = select(n, readfds, writefds, NULL, &tv); - while (ret < 0 && errno == EINTR); - if (ret < 0) - return -ERRNO_TO_PARA_ERROR(errno); - return ret; -} - /** * Set a file descriptor to blocking mode. * @@ -376,34 +344,6 @@ __must_check int mark_fd_nonblocking(int fd) return 1; } -/** - * Set a file descriptor in a fd_set. - * - * \param fd The file descriptor to be set. - * \param fds The file descriptor set. - * \param max_fileno Highest-numbered file descriptor. - * - * This wrapper for FD_SET() passes its first two arguments to \p FD_SET. Upon - * return, \a max_fileno contains the maximum of the old_value and \a fd. - * - * \sa \ref para_select. -*/ -void para_fd_set(int fd, fd_set *fds, int *max_fileno) -{ - assert(fd >= 0 && fd < FD_SETSIZE); -#if 0 - { - int flags = fcntl(fd, F_GETFL); - if (!(flags & O_NONBLOCK)) { - PARA_EMERG_LOG("fd %d is a blocking file descriptor\n", fd); - exit(EXIT_FAILURE); - } - } -#endif - FD_SET(fd, fds); - *max_fileno = PARA_MAX(*max_fileno, fd); -} - /** * Paraslash's wrapper for mmap. * @@ -627,7 +567,21 @@ int para_munmap(void *start, size_t length) return -ERRNO_TO_PARA_ERROR(err); } -static int xpoll(struct pollfd *fds, nfds_t nfds, int timeout) +/** + * Simple wrapper for poll(2). + * + * It calls poll(2) and starts over if the call was interrupted by a signal. + * + * \param fds See poll(2). + * \param nfds See poll(2). + * \param timeout See poll(2). + * + * \return The return value of the underlying poll() call on success, the + * negative paraslash error code on errors. + * + * All arguments are passed verbatim to poll(2). + */ +int xpoll(struct pollfd *fds, nfds_t nfds, int timeout) { int ret;