@@ -1820,19 +1820,25 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
1820
1820
if (hfile == INVALID_HANDLE_VALUE ) {
1821
1821
return -1 ;
1822
1822
}
1823
- DWORD mode , pipe_size ;
1823
+ DWORD pipe_mode , pipe_flags , pipe_size , pipe_insize , pipe_outsize ;
1824
1824
if (gil_held ) {
1825
1825
Py_BEGIN_ALLOW_THREADS
1826
1826
if (GetFileType (hfile ) == FILE_TYPE_PIPE &&
1827
- GetNamedPipeHandleStateW (hfile , & mode , NULL , NULL , NULL ,
1827
+ GetNamedPipeHandleStateW (hfile , & pipe_mode , NULL , NULL , NULL ,
1828
1828
NULL , 0 ) &&
1829
- mode & PIPE_NOWAIT )
1829
+ pipe_mode & PIPE_NOWAIT )
1830
1830
{
1831
1831
// GetNamedPipeInfo() requires FILE_READ_ATTRIBUTES access.
1832
1832
// 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
+ {
1834
1836
pipe_size = 4096 ;
1835
1837
}
1838
+ else {
1839
+ pipe_size = pipe_flags & PIPE_SERVER_END ? pipe_outsize :
1840
+ pipe_insize ;
1841
+ }
1836
1842
if (count > pipe_size ) {
1837
1843
count = pipe_size ;
1838
1844
}
@@ -1841,15 +1847,21 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
1841
1847
}
1842
1848
else {
1843
1849
if (GetFileType (hfile ) == FILE_TYPE_PIPE &&
1844
- GetNamedPipeHandleStateW (hfile , & mode , NULL , NULL , NULL ,
1850
+ GetNamedPipeHandleStateW (hfile , & pipe_mode , NULL , NULL , NULL ,
1845
1851
NULL , 0 ) &&
1846
- mode & PIPE_NOWAIT )
1852
+ pipe_mode & PIPE_NOWAIT )
1847
1853
{
1848
1854
// GetNamedPipeInfo() requires FILE_READ_ATTRIBUTES access.
1849
1855
// 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
+ {
1851
1859
pipe_size = 4096 ;
1852
1860
}
1861
+ else {
1862
+ pipe_size = pipe_flags & PIPE_SERVER_END ? pipe_outsize :
1863
+ pipe_insize ;
1864
+ }
1853
1865
if (count > pipe_size ) {
1854
1866
count = pipe_size ;
1855
1867
}
0 commit comments