From 82a152fcf9254fe4189cac12fa3fc1744284ca13 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 22 Dec 2008 22:17:28 +0100 Subject: Add write_data_iov --- source3/include/proto.h | 1 + source3/lib/util_sock.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/source3/include/proto.h b/source3/include/proto.h index f1be1874bf..08260517ff 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1441,6 +1441,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/source3/lib/util_sock.c b/source3/lib/util_sock.c index 7fe8ed82a2..a362938fd3 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -634,6 +634,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. ****************************************************************************/ -- cgit