Bläddra i källkod

In readFromChild() for Windows: Call PeekNamedPipe() to check for available data.

Reason: ReadFile() doesn't always return if there's no data and the child exits after ReadFile()
is called.
adeniz_1
Alban Deniz 11 månader sedan
förälder
incheckning
02aafe6f93
1 ändrade filer med 55 tillägg och 10 borttagningar
  1. 55
    10
      child.cpp

+ 55
- 10
child.cpp Visa fil

@@ -1455,20 +1455,64 @@ namespace CodeDweller {
// Blocking read from the child.
#ifdef _WIN32
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) {
errorText = "Error reading from the child process: ";
@@ -1476,6 +1520,7 @@ namespace CodeDweller {
}
// Exit the thread.
break;
}

Laddar…
Avbryt
Spara