0
0
mirror of https://github.com/vim/vim.git synced 2025-11-15 23:14:06 -05:00

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)
This commit is contained in:
Bram Moolenaar
2019-01-24 23:11:49 +01:00
parent 99531a7604
commit 240583869a
6 changed files with 51 additions and 13 deletions

View File

@@ -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 (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);
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