From 9cb93a64f243eb7a8fdb171c5683b880eb25f1ed Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 16 Nov 2020 11:09:23 -0800 Subject: [PATCH] SCP: Slow down debug output writes when the debug fd is non blocking This problem only appears when debug output is prodigious. That prodigious activity is already dramatically affecting timing, so adding additional delays to allow the debug output to catch up won't make anything worse. It appears that we could jump over the C runtime implementation of fwrite() and do an explicit write() system call and retry that until it succeeds, but this approach would have two negative consequences: 1) it would jump over other buffered data that the C runtime fwrite() may have pending due to output produced by other than debug activities, thus emitting output out of order. 2) Windows doesn't have a direct system call used by its C runtime for write(), but merely implements write() as part of the C runtime and as it turns out that write() returns an int vs a ssize_t type result. An explicit cast could address this, but point 1 would still be a concern. As discussed in #957 --- scp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scp.c b/scp.c index 48fd0bd5..5db59b0a 100644 --- a/scp.c +++ b/scp.c @@ -13271,6 +13271,8 @@ while (len > 0) { len_written = fwrite (buf, 1, len, f); len -= len_written; buf += len_written; + if (errno == EAGAIN) /* Non blocking file descriptor buffer full? */ + sim_os_ms_sleep(10);/* wait a bit to retry */ errno = 0; } }