Skip to content

Commit 918bde3

Browse files
Update Python/fileutils.c
Co-authored-by: Eryk Sun <[email protected]>
1 parent ba175a1 commit 918bde3

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Python/fileutils.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,19 +1820,25 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
18201820
if (hfile == INVALID_HANDLE_VALUE) {
18211821
return -1;
18221822
}
1823-
DWORD mode, pipe_size;
1823+
DWORD pipe_mode, pipe_flags, pipe_size, pipe_insize, pipe_outsize;
18241824
if (gil_held) {
18251825
Py_BEGIN_ALLOW_THREADS
18261826
if (GetFileType(hfile) == FILE_TYPE_PIPE &&
1827-
GetNamedPipeHandleStateW(hfile, &mode, NULL, NULL, NULL,
1827+
GetNamedPipeHandleStateW(hfile, &pipe_mode, NULL, NULL, NULL,
18281828
NULL, 0) &&
1829-
mode & PIPE_NOWAIT)
1829+
pipe_mode & PIPE_NOWAIT)
18301830
{
18311831
// GetNamedPipeInfo() requires FILE_READ_ATTRIBUTES access.
18321832
// CreatePipe() includes this access for the write handle.
1833-
if (!GetNamedPipeInfo(hfile, NULL, NULL, &pipe_size, NULL)) {
1833+
if (!GetNamedPipeInfo(hfile, &pipe_flags, &pipe_outsize,
1834+
&pipe_insize, NULL))
1835+
{
18341836
pipe_size = 4096;
18351837
}
1838+
else {
1839+
pipe_size = pipe_flags & PIPE_SERVER_END ? pipe_outsize :
1840+
pipe_insize;
1841+
}
18361842
if (count > pipe_size) {
18371843
count = pipe_size;
18381844
}
@@ -1841,15 +1847,21 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
18411847
}
18421848
else {
18431849
if (GetFileType(hfile) == FILE_TYPE_PIPE &&
1844-
GetNamedPipeHandleStateW(hfile, &mode, NULL, NULL, NULL,
1850+
GetNamedPipeHandleStateW(hfile, &pipe_mode, NULL, NULL, NULL,
18451851
NULL, 0) &&
1846-
mode & PIPE_NOWAIT)
1852+
pipe_mode & PIPE_NOWAIT)
18471853
{
18481854
// GetNamedPipeInfo() requires FILE_READ_ATTRIBUTES access.
18491855
// CreatePipe() includes this access for the write handle.
1850-
if (!GetNamedPipeInfo(hfile, NULL, NULL, &pipe_size, NULL)) {
1856+
if (!GetNamedPipeInfo(hfile, &pipe_flags, &pipe_outsize,
1857+
&pipe_insize, NULL))
1858+
{
18511859
pipe_size = 4096;
18521860
}
1861+
else {
1862+
pipe_size = pipe_flags & PIPE_SERVER_END ? pipe_outsize :
1863+
pipe_insize;
1864+
}
18531865
if (count > pipe_size) {
18541866
count = pipe_size;
18551867
}

0 commit comments

Comments
 (0)