summaryrefslogtreecommitdiff
path: root/src/channel.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-01-19 14:37:00 +0100
committerBram Moolenaar <Bram@vim.org>2019-01-19 14:37:00 +0100
commitb091f30bf38eacb31b9d8c97c82c7e0af9866301 (patch)
tree6bd242d9cad2c17b0ff2144666518faf4bae18b0 /src/channel.c
parentb2e54b009279754e420c992a5e4ec05b0728d915 (diff)
downloadvim-git-b091f30bf38eacb31b9d8c97c82c7e0af9866301.tar.gz
patch 8.1.0777: Win32: using pipes for channel does not work wellv8.1.0777
Problem: Win32: using pipes for channel does not work well. Solution: Use a larger buffer and handle overlaps. (Yasuhiro Matsumoto, closes #3782)
Diffstat (limited to 'src/channel.c')
-rw-r--r--src/channel.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/channel.c b/src/channel.c
index 8f0577f9b..f6ffcd67d 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -80,11 +80,23 @@ fd_read(sock_T fd, char *buf, size_t len)
static int
fd_write(sock_T fd, char *buf, size_t len)
{
- HANDLE h = (HANDLE)fd;
- DWORD nwrite;
+ HANDLE h = (HANDLE)fd;
+ DWORD nwrite;
+ OVERLAPPED ov;
- if (!WriteFile(h, buf, (DWORD)len, &nwrite, NULL))
- return -1;
+ // 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))
+ {
+ DWORD err = GetLastError();
+
+ if (err != ERROR_IO_PENDING)
+ return -1;
+ if (!GetOverlappedResult(h, &ov, &nwrite, FALSE))
+ return -1;
+ FlushFileBuffers(h);
+ }
return (int)nwrite;
}
@@ -3168,20 +3180,7 @@ channel_wait(channel_T *channel, sock_T fd, int timeout)
if (r && nread > 0)
return CW_READY;
if (r == 0)
- {
- DWORD err = GetLastError();
-
- if (err != ERROR_BAD_PIPE && err != ERROR_BROKEN_PIPE)
- return CW_ERROR;
-
- if (channel->ch_named_pipe)
- {
- DisconnectNamedPipe((HANDLE)fd);
- ConnectNamedPipe((HANDLE)fd, NULL);
- }
- else
- return CW_ERROR;
- }
+ return CW_ERROR;
/* perhaps write some buffer lines */
channel_write_any_lines();
@@ -3812,17 +3811,7 @@ channel_send(
if (part == PART_SOCK)
res = sock_write(fd, (char *)buf, len);
else
- {
res = fd_write(fd, (char *)buf, len);
-#ifdef WIN32
- if (channel->ch_named_pipe && res < 0)
- {
- DisconnectNamedPipe((HANDLE)fd);
- ConnectNamedPipe((HANDLE)fd, NULL);
- }
-#endif
-
- }
if (res < 0 && (errno == EWOULDBLOCK
#ifdef EAGAIN
|| errno == EAGAIN