diff src/channel.c @ 15621:bfbdef46aa7d v8.1.0818

patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw() commit https://github.com/vim/vim/commit/240583869ae477202494dd01ef1e8e2bac650f10 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 23:11:49 2019 +0100 patch 8.1.0818: MS-Windows: cannot send large data with ch_sendraw() Problem: MS-Windows: cannot send large data with ch_sendraw(). Solution: Split write into several WriteFile() calls. (Yasuhiro Matsumoto, closes #3823)
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 23:15:05 +0100
parents f611222a4349
children d4a6d575e910
line wrap: on
line diff
--- a/src/channel.c
+++ b/src/channel.c
@@ -80,24 +80,34 @@ fd_read(sock_T fd, char *buf, size_t len
     static int
 fd_write(sock_T fd, char *buf, size_t len)
 {
+    size_t	todo = len;
     HANDLE	h = (HANDLE)fd;
-    DWORD	nwrite;
+    DWORD	nwrite, size, done = 0;
     OVERLAPPED	ov;
 
-    // If the pipe overflows while the job does not read the data, WriteFile
-    // will block forever. This abandons the write.
-    memset(&ov, 0, sizeof(ov));
-    if (!WriteFile(h, buf, (DWORD)len, &nwrite, &ov))
+    while (todo > 0)
     {
-	DWORD err = GetLastError();
-
-	if (err != ERROR_IO_PENDING)
-	    return -1;
-	if (!GetOverlappedResult(h, &ov, &nwrite, FALSE))
-	    return -1;
-	FlushFileBuffers(h);
+	if (todo > MAX_NAMED_PIPE_SIZE)
+	    size = MAX_NAMED_PIPE_SIZE;
+	else
+	    size = todo;
+	// If the pipe overflows while the job does not read the data, WriteFile
+	// will block forever. This abandons the write.
+	memset(&ov, 0, sizeof(ov));
+	if (!WriteFile(h, buf + done, size, &nwrite, &ov))
+	{
+	    DWORD err = GetLastError();
+
+	    if (err != ERROR_IO_PENDING)
+		return -1;
+	    if (!GetOverlappedResult(h, &ov, &nwrite, FALSE))
+		return -1;
+	    FlushFileBuffers(h);
+	}
+	todo -= nwrite;
+	done += nwrite;
     }
-    return (int)nwrite;
+    return (int)done;
 }
 
     static void