-/* non-blocking read or write */
-static int nonblock_rw(bool wr, int fd, char *buf, int size)
-{
- int rc;
-
- if (wr)
- rc = write(fd, buf, size);
- else
- rc = read(fd, buf, size);
-
- if ((rc < 0) && (errno == -EAGAIN)) {
- fd_set set;
- struct timeval timeout;
-
- timeout.tv_sec = opt.o_report_int;
-
- FD_ZERO(&set);
- FD_SET(fd, &set);
- if (wr)
- rc = select(FD_SETSIZE, NULL, &set, NULL, &timeout);
- else
- rc = select(FD_SETSIZE, &set, NULL, NULL, &timeout);
- if (rc < 0)
- return -errno;
- if (rc == 0)
- /* Timed out, we read nothing */
- return -EAGAIN;
-
- /* Should be available now */
- if (wr)
- rc = write(fd, buf, size);
- else
- rc = read(fd, buf, size);
- }
-
- if (rc < 0)
- rc = -errno;
-
- return rc;
-}
-