From 2d05db409e11443480c8cdc52e205f57aa512fba Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 22 Dec 2008 22:17:28 +0100 Subject: [PATCH] Add write_data_iov --- source/lib/util_sock.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/source/lib/util_sock.c b/source/lib/util_sock.c index e64b0036bfd..c0e947b06cb 100644 --- a/source/lib/util_sock.c +++ b/source/lib/util_sock.c @@ -1037,6 +1037,75 @@ NTSTATUS read_data(int fd, char *buffer, size_t N) } /**************************************************************************** + Write all data from an iov array +****************************************************************************/ + +ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt) +{ + int i; + size_t to_send; + ssize_t thistime; + size_t sent; + struct iovec *iov_copy, *iov; + + to_send = 0; + for (i=0; i 0) { + if (thistime < iov[0].iov_len) { + char *new_base = + (char *)iov[0].iov_base + thistime; + iov[0].iov_base = new_base; + iov[0].iov_len -= thistime; + break; + } + thistime -= iov[0].iov_len; + iov += 1; + iovcnt -= 1; + } + + thistime = sys_writev(fd, iov, iovcnt); + if (thistime <= 0) { + break; + } + sent += thistime; + } + + TALLOC_FREE(iov_copy); + return sent; +} + +/**************************************************************************** Write data to a fd. ****************************************************************************/ -- 2.11.4.GIT