From: Volker Lendecke Date: Mon, 22 Dec 2008 21:17:28 +0000 (+0100) Subject: Add write_data_iov X-Git-Tag: samba-3.3.0~127 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee03d50f5b40d6d50c99acac0cba62c7faa2f42a;p=thirdparty%2Fsamba.git Add write_data_iov (cherry picked from commit efd5aa6a75c68c6fa48eaa928e652e3cacf0e18e) --- diff --git a/source/include/proto.h b/source/include/proto.h index d29a108ac48..db47e2fbdba 100644 --- a/source/include/proto.h +++ b/source/include/proto.h @@ -1576,6 +1576,7 @@ NTSTATUS read_socket_with_timeout(int fd, char *buf, size_t *size_ret); NTSTATUS read_data(int fd, char *buffer, size_t N); ssize_t write_data(int fd, const char *buffer, size_t N); +ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt); bool send_keepalive(int client); NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf, unsigned int timeout, 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 @@ -1036,6 +1036,75 @@ NTSTATUS read_data(int fd, char *buffer, size_t N) return read_socket_with_timeout(fd, buffer, N, N, 0, NULL); } +/**************************************************************************** + 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. ****************************************************************************/