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 pipemaint
commit
8d792dcd5a
|
@ -707,13 +707,24 @@ ssize_t mingw_write(int fd, const void *buf, size_t len)
|
||||||
{
|
{
|
||||||
ssize_t result = write(fd, buf, len);
|
ssize_t result = write(fd, buf, len);
|
||||||
|
|
||||||
if (result < 0 && errno == EINVAL && buf) {
|
if (result < 0 && (errno == EINVAL || errno == ENOSPC) && buf) {
|
||||||
|
int orig = errno;
|
||||||
|
|
||||||
/* check if fd is a pipe */
|
/* check if fd is a pipe */
|
||||||
HANDLE h = (HANDLE) _get_osfhandle(fd);
|
HANDLE h = (HANDLE) _get_osfhandle(fd);
|
||||||
if (GetFileType(h) == FILE_TYPE_PIPE)
|
if (GetFileType(h) != FILE_TYPE_PIPE)
|
||||||
|
errno = orig;
|
||||||
|
else if (orig == EINVAL)
|
||||||
errno = EPIPE;
|
errno = EPIPE;
|
||||||
else
|
else {
|
||||||
errno = EINVAL;
|
DWORD buf_size;
|
||||||
|
|
||||||
|
if (!GetNamedPipeInfo(h, NULL, NULL, &buf_size, NULL))
|
||||||
|
buf_size = 4096;
|
||||||
|
if (len > buf_size)
|
||||||
|
return write(fd, buf, buf_size);
|
||||||
|
errno = orig;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in New Issue