When EOF on input and output is reached but the output pipe buffer is not empty, sleep for a short time before looping while waiting for the buffer to empty, to avoid a busy-wait (#164).

This commit is contained in:
Andrew Wood
2025-07-25 20:13:49 +01:00
parent d2e9028726
commit e687c9b4d9
+11
View File
@@ -400,6 +400,17 @@ int pv_main_loop(pvstate_t state)
}
}
/*
* If we've read everything and written everything, and the
* output pipe buffer is NOT empty, then pause a short while
* so we don't spin in a tight loop waiting for the output
* buffer to empty (#164).
*/
if (eof_in && eof_out && state->transfer.written_but_not_consumed > 0) {
debug("%s", "EOF but bytes remain in output pipe - sleeping");
pv_nanosleep(50000000);
}
/*
* Just go round the loop again if there's no display and
* we're not reporting statistics.