浏览代码

Call select() before reading from the child.

In readFromChild() for non-Windows: Call select() to check
for available data.  Reason: To ensure that ::read() doesn't
hang if the child exits during the call to ::read().
adeniz_1
Alban Deniz 11 个月前
父节点
当前提交
a1cd1bb00d
共有 1 个文件被更改,包括 23 次插入0 次删除
  1. 23
    0
      child.cpp

+ 23
- 0
child.cpp 查看文件

@@ -1525,6 +1525,29 @@ namespace CodeDweller {
}
#else
fd_set readFd;
int retVal;
struct timeval timeout = {0, 0};
FD_ZERO(&readFd);
FD_SET(inputFileDescriptor, &readFd);
// Check if input is available.
retVal = select(inputFileDescriptor + 1, &readFd, NULL, NULL, &timeout);
if (-1 == retVal) {
throw std::runtime_error("Error from select() when reading from the "
"child process: " + getErrorText());
}
// Is data available?
if (0 == retVal) {
// No. Wait and try again.
pollTimer.pause();
continue;
}
ssize_t nBytesRead;
nBytesRead = ::read(inputFileDescriptor,

正在加载...
取消
保存