|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Blocking read from the child.
|
|
|
// Blocking read from the child.
|
|
|
#ifdef _WIN32
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
|
DWORD nBytesRead;
|
|
|
DWORD nBytesRead;
|
|
|
|
|
|
|
|
|
if (!ReadFile(inputHandle,
|
|
|
|
|
|
bufferPtr,
|
|
|
|
|
|
bufferCapacity,
|
|
|
|
|
|
&nBytesRead,
|
|
|
|
|
|
NULL)) {
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
if (stopReaderFlag) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
DWORD bytesAvailable;
|
|
|
|
|
|
|
|
|
|
|
|
if (!PeekNamedPipe(inputHandle,
|
|
|
|
|
|
NULL,
|
|
|
|
|
|
0,
|
|
|
|
|
|
NULL,
|
|
|
|
|
|
&bytesAvailable,
|
|
|
|
|
|
NULL)) {
|
|
|
|
|
|
throw std::runtime_error("Error from PeekNamedPipe: " +
|
|
|
|
|
|
getErrorText());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Is data available?
|
|
|
|
|
|
if (0 == bytesAvailable) {
|
|
|
|
|
|
|
|
|
|
|
|
// No. Wait and try again.
|
|
|
|
|
|
pollTimer.pause();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!ReadFile(inputHandle,
|
|
|
|
|
|
bufferPtr,
|
|
|
|
|
|
bufferCapacity,
|
|
|
|
|
|
&nBytesRead,
|
|
|
|
|
|
NULL)) {
|
|
|
|
|
|
|
|
|
|
|
|
if (stopReaderFlag) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Broken pipe occurs when the child exits; this is not
|
|
|
|
|
|
// necessarily an error condition.
|
|
|
|
|
|
if (GetLastError() != ERROR_BROKEN_PIPE) {
|
|
|
|
|
|
|
|
|
|
|
|
errorText = "Error reading from the child process: ";
|
|
|
|
|
|
errorText += getErrorText();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch(...) {
|
|
|
|
|
|
|
|
|
|
|
|
// Some error occurred.
|
|
|
|
|
|
if (stopReaderFlag) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
// Broken pipe occurs when the child exits; this is not
|
|
|
|
|
|
// necessarily an error condition.
|
|
|
|
|
|
|
|
|
// Thread was not commanded to stop; output error: Broken pipe
|
|
|
|
|
|
// occurs when the child exits; this is not an error
|
|
|
|
|
|
// condition.
|
|
|
if (GetLastError() != ERROR_BROKEN_PIPE) {
|
|
|
if (GetLastError() != ERROR_BROKEN_PIPE) {
|
|
|
|
|
|
|
|
|
errorText = "Error reading from the child process: ";
|
|
|
errorText = "Error reading from the child process: ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Exit the thread.
|
|
|
break;
|
|
|
break;
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|