]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Make write_data use write_data_iov
authorVolker Lendecke <vl@samba.org>
Mon, 22 Dec 2008 21:17:59 +0000 (22:17 +0100)
committerKarolin Seeger <kseeger@samba.org>
Fri, 2 Jan 2009 11:44:25 +0000 (12:44 +0100)
(cherry picked from commit f77527188bdc40a77764451c2fb7bba511a1f5a2)

source/lib/util_sock.c

index c0e947b06cbb7f40a0881d5a4ee7683efad2130c..9c37e0ca8e764c50e5a0330173392d5b651cb9fe 100644 (file)
@@ -1109,37 +1109,37 @@ ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt)
  Write data to a fd.
 ****************************************************************************/
 
+/****************************************************************************
+ Write data to a fd.
+****************************************************************************/
+
 ssize_t write_data(int fd, const char *buffer, size_t N)
 {
-       size_t total=0;
        ssize_t ret;
-       char addr[INET6_ADDRSTRLEN];
-
-       while (total < N) {
-               ret = sys_write(fd,buffer + total,N - total);
+       struct iovec iov;
 
-               if (ret == -1) {
-                       if (fd == get_client_fd()) {
-                               /* Try and give an error message saying
-                                * what client failed. */
-                               DEBUG(0,("write_data: write failure in "
-                                       "writing to client %s. Error %s\n",
-                                       get_peer_addr(fd,addr,sizeof(addr)),
-                                       strerror(errno) ));
-                       } else {
-                               DEBUG(0,("write_data: write failure. "
-                                       "Error = %s\n", strerror(errno) ));
-                       }
-                       return -1;
-               }
+       iov.iov_base = CONST_DISCARD(char *, buffer);
+       iov.iov_len = N;
 
-               if (ret == 0) {
-                       return total;
-               }
+       ret = write_data_iov(fd, &iov, 1);
+       if (ret >= 0) {
+               return ret;
+       }
 
-               total += ret;
+       if (fd == get_client_fd()) {
+               char addr[INET6_ADDRSTRLEN];
+               /*
+                * Try and give an error message saying what client failed.
+                */
+               DEBUG(0, ("write_data: write failure in writing to client %s. "
+                         "Error %s\n", get_peer_addr(fd,addr,sizeof(addr)),
+                         strerror(errno)));
+       } else {
+               DEBUG(0,("write_data: write failure. Error = %s\n",
+                        strerror(errno) ));
        }
-       return (ssize_t)total;
+
+       return -1;
 }
 
 /****************************************************************************