block waiting for end of stdout data not more than a second

This commit is contained in:
Axel Kohlmeyer
2023-10-11 02:12:03 -04:00
parent 86a5d6bb15
commit cc5c5bbd49

View File

@ -77,6 +77,7 @@ bool StdCapture::EndCapture()
int bytesRead; int bytesRead;
bool fd_blocked; bool fd_blocked;
int maxwait = 100;
do { do {
bytesRead = 0; bytesRead = 0;
@ -93,9 +94,10 @@ bool StdCapture::EndCapture()
buf[bytesRead] = 0; buf[bytesRead] = 0;
m_captured += buf; m_captured += buf;
} else if (bytesRead < 0) { } else if (bytesRead < 0) {
fd_blocked = ((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINTR)); fd_blocked = ((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINTR)) && (maxwait > 0);
if (fd_blocked) std::this_thread::sleep_for(std::chrono::milliseconds(10)); if (fd_blocked) std::this_thread::sleep_for(std::chrono::milliseconds(10));
--maxwait;
} }
} while (fd_blocked || (bytesRead == (bufSize - 1))); } while (fd_blocked || (bytesRead == (bufSize - 1)));
m_capturing = false; m_capturing = false;