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();
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;
}
endtry
endfunc
+func Test_no_hang_windows()
+ if !has('job') || !has('win32')
+ return
+ endif
+
+ try
+ let job = job_start(s:python . " test_channel_pipe.py busy",
+ \ {'mode': 'raw', 'drop': 'never', 'noblock': 0})
+ call assert_fails('call ch_sendraw(job, repeat("X", 80000))', 'E631:')
+ finally
+ call job_stop(job)
+ endtry
+endfunc
+
func Test_job_exitval_and_termsig()
if !has('unix')
return