put the write end of the pipe in non blocking mode to avoid deadlocks and return from wxPipeOutputStream::OnSysWrite() without having necessarily written all the data as this is not always possible
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -427,6 +427,21 @@ size_t wxPipeInputStream::OnSysRead(void *buffer, size_t len)
|
|||||||
wxPipeOutputStream::wxPipeOutputStream(HANDLE hOutput)
|
wxPipeOutputStream::wxPipeOutputStream(HANDLE hOutput)
|
||||||
{
|
{
|
||||||
m_hOutput = hOutput;
|
m_hOutput = hOutput;
|
||||||
|
|
||||||
|
// unblock the pipe to prevent deadlocks when we're writing to the pipe
|
||||||
|
// from which the child process can't read because it is writing in its own
|
||||||
|
// end of it
|
||||||
|
DWORD mode = PIPE_READMODE_BYTE | PIPE_NOWAIT;
|
||||||
|
if ( !::SetNamedPipeHandleState
|
||||||
|
(
|
||||||
|
m_hOutput,
|
||||||
|
&mode,
|
||||||
|
NULL, // collection count (we don't set it)
|
||||||
|
NULL // timeout (we don't set it neither)
|
||||||
|
) )
|
||||||
|
{
|
||||||
|
wxLogLastError(_T("SetNamedPipeHandleState(PIPE_NOWAIT)"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxPipeOutputStream::~wxPipeOutputStream()
|
wxPipeOutputStream::~wxPipeOutputStream()
|
||||||
@@ -436,17 +451,29 @@ wxPipeOutputStream::~wxPipeOutputStream()
|
|||||||
|
|
||||||
size_t wxPipeOutputStream::OnSysWrite(const void *buffer, size_t len)
|
size_t wxPipeOutputStream::OnSysWrite(const void *buffer, size_t len)
|
||||||
{
|
{
|
||||||
DWORD bytesWritten;
|
|
||||||
|
|
||||||
m_lasterror = wxSTREAM_NO_ERROR;
|
m_lasterror = wxSTREAM_NO_ERROR;
|
||||||
if ( !::WriteFile(m_hOutput, buffer, len, &bytesWritten, NULL) )
|
|
||||||
|
DWORD totalWritten = 0;
|
||||||
|
while ( len > 0 )
|
||||||
|
{
|
||||||
|
DWORD chunkWritten;
|
||||||
|
if ( !::WriteFile(m_hOutput, buffer, len, &chunkWritten, NULL) )
|
||||||
{
|
{
|
||||||
m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
|
m_lasterror = ::GetLastError() == ERROR_BROKEN_PIPE
|
||||||
? wxSTREAM_EOF
|
? wxSTREAM_EOF
|
||||||
: wxSTREAM_WRITE_ERROR;
|
: wxSTREAM_WRITE_ERROR;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesWritten;
|
if ( !chunkWritten )
|
||||||
|
break;
|
||||||
|
|
||||||
|
buffer = (char *)buffer + chunkWritten;
|
||||||
|
totalWritten += chunkWritten;
|
||||||
|
len -= chunkWritten;
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_STREAMS
|
#endif // wxUSE_STREAMS
|
||||||
|
Reference in New Issue
Block a user