Revision 9adea5f7 util/osdep.c

b/util/osdep.c
429 429
#endif
430 430
    return 0;
431 431
}
432

  
433
#ifndef CONFIG_IOVEC
434
/* helper function for iov_send_recv() */
435
static ssize_t
436
readv_writev(int fd, const struct iovec *iov, int iov_cnt, bool do_write)
437
{
438
    unsigned i = 0;
439
    ssize_t ret = 0;
440
    while (i < iov_cnt) {
441
        ssize_t r = do_write
442
            ? write(fd, iov[i].iov_base, iov[i].iov_len)
443
            : read(fd, iov[i].iov_base, iov[i].iov_len);
444
        if (r > 0) {
445
            ret += r;
446
        } else if (!r) {
447
            break;
448
        } else if (errno == EINTR) {
449
            continue;
450
        } else {
451
            /* else it is some "other" error,
452
             * only return if there was no data processed. */
453
            if (ret == 0) {
454
                ret = -1;
455
            }
456
            break;
457
        }
458
        i++;
459
    }
460
    return ret;
461
}
462

  
463
ssize_t
464
readv(int fd, const struct iovec *iov, int iov_cnt)
465
{
466
    return readv_writev(fd, iov, iov_cnt, false);
467
}
468

  
469
ssize_t
470
writev(int fd, const struct iovec *iov, int iov_cnt)
471
{
472
    return readv_writev(fd, iov, iov_cnt, true);
473
}
474
#endif

Also available in: Unified diff