Skip to content

Commit 8d792dc

Browse files
committed
Merge branch 'js/win32-retry-pipe-write-on-enospc' into maint-2.43
Update to the code that writes to pipes on Windows. * js/win32-retry-pipe-write-on-enospc: win32: special-case `ENOSPC` when writing to a pipe
2 parents 08b7e46 + 19ed0df commit 8d792dc

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

compat/mingw.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,24 @@ ssize_t mingw_write(int fd, const void *buf, size_t len)
707707
{
708708
ssize_t result = write(fd, buf, len);
709709

710-
if (result < 0 && errno == EINVAL && buf) {
710+
if (result < 0 && (errno == EINVAL || errno == ENOSPC) && buf) {
711+
int orig = errno;
712+
711713
/* check if fd is a pipe */
712714
HANDLE h = (HANDLE) _get_osfhandle(fd);
713-
if (GetFileType(h) == FILE_TYPE_PIPE)
715+
if (GetFileType(h) != FILE_TYPE_PIPE)
716+
errno = orig;
717+
else if (orig == EINVAL)
714718
errno = EPIPE;
715-
else
716-
errno = EINVAL;
719+
else {
720+
DWORD buf_size;
721+
722+
if (!GetNamedPipeInfo(h, NULL, NULL, &buf_size, NULL))
723+
buf_size = 4096;
724+
if (len > buf_size)
725+
return write(fd, buf, buf_size);
726+
errno = orig;
727+
}
717728
}
718729

719730
return result;

0 commit comments

Comments
 (0)