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

patch 8.1.0889: MS-Windows: a channel write may hang

Problem:    MS-Windows: a channel write may hang.
Solution:   Check for WriteFile() not writing anything. (Yasuhiro Matsumoto,
            closes #3920)
This commit is contained in:
Bram Moolenaar
2019-02-10 22:23:26 +01:00
parent 31b816042f
commit 6524068ff3
4 changed files with 26 additions and 2 deletions

View File

@@ -91,9 +91,10 @@ fd_write(sock_T fd, char *buf, size_t len)
size = MAX_NAMED_PIPE_SIZE;
else
size = (DWORD)todo;
// If the pipe overflows while the job does not read the data, WriteFile
// will block forever. This abandons the write.
// 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));
nwrite = 0;
if (!WriteFile(h, buf + done, size, &nwrite, &ov))
{
DWORD err = GetLastError();
@@ -104,6 +105,10 @@ fd_write(sock_T fd, char *buf, size_t len)
return -1;
FlushFileBuffers(h);
}
else if (nwrite == 0)
// WriteFile() returns TRUE but did not write anything. This causes
// a hang, so bail out.
break;
todo -= nwrite;
done += nwrite;
}