Mercurial > vim
comparison src/channel.c @ 15764:208bf8b36075 v8.1.0889
patch 8.1.0889: MS-Windows: a channel write may hang
commit https://github.com/vim/vim/commit/6524068ff3252f1373807f1ebfde21408cef624e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 10 22:23:26 2019 +0100
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 10 Feb 2019 22:30:07 +0100 |
parents | c017195b121b |
children | 7fad90423bd2 |
comparison
equal
deleted
inserted
replaced
15763:75ae11beca53 | 15764:208bf8b36075 |
---|---|
89 { | 89 { |
90 if (todo > MAX_NAMED_PIPE_SIZE) | 90 if (todo > MAX_NAMED_PIPE_SIZE) |
91 size = MAX_NAMED_PIPE_SIZE; | 91 size = MAX_NAMED_PIPE_SIZE; |
92 else | 92 else |
93 size = (DWORD)todo; | 93 size = (DWORD)todo; |
94 // If the pipe overflows while the job does not read the data, WriteFile | 94 // If the pipe overflows while the job does not read the data, |
95 // will block forever. This abandons the write. | 95 // WriteFile() will block forever. This abandons the write. |
96 memset(&ov, 0, sizeof(ov)); | 96 memset(&ov, 0, sizeof(ov)); |
97 nwrite = 0; | |
97 if (!WriteFile(h, buf + done, size, &nwrite, &ov)) | 98 if (!WriteFile(h, buf + done, size, &nwrite, &ov)) |
98 { | 99 { |
99 DWORD err = GetLastError(); | 100 DWORD err = GetLastError(); |
100 | 101 |
101 if (err != ERROR_IO_PENDING) | 102 if (err != ERROR_IO_PENDING) |
102 return -1; | 103 return -1; |
103 if (!GetOverlappedResult(h, &ov, &nwrite, FALSE)) | 104 if (!GetOverlappedResult(h, &ov, &nwrite, FALSE)) |
104 return -1; | 105 return -1; |
105 FlushFileBuffers(h); | 106 FlushFileBuffers(h); |
106 } | 107 } |
108 else if (nwrite == 0) | |
109 // WriteFile() returns TRUE but did not write anything. This causes | |
110 // a hang, so bail out. | |
111 break; | |
107 todo -= nwrite; | 112 todo -= nwrite; |
108 done += nwrite; | 113 done += nwrite; |
109 } | 114 } |
110 return (int)done; | 115 return (int)done; |
111 } | 116 } |