[Interest] Flush after QProcess::write to prevent it from filling writeBuffer

Philip philip at c0xc.net
Mon Feb 20 12:20:07 CET 2023


Hi Thiago, thanks for your comment!

On 2/20/23 07:16, Thiago Macieira wrote:
>
> That's correct. The name of the "wait For BytesWritten" method means it waits
> for the bytesWritten signal to be emitted. That is emitted when any byte gets
> written, not when all bytes finish writing.
>
> If after the signal is emitted, bytesToWrite() is still too high for you, you
> can wait again until it drops to a low enough number.

I calculated the number of pending bytes myself by adding the count 
provided by bytesWritten to the total number of bytes written (the total 
number of bytes read minus that number should be identical to what 
bytesToWrite returns).

So I have tried to do that by removing the while loop and putting the 
rest in a function that's called whenever the bytesWritten signal is 
emitted - but only after the total number of bytes written reached the 
total number of bytes I had previously read (i.e., before reading more I 
would wait until everything has been written/sent). The code got stuck 
at 64KB pending bytes that have not yet been written (again, a flush 
method would be useful).

My next approach was that I would save the number of bytes written in 
one go (the bytesWritten argument) because I noticed that's 64KB too, 
assuming QProcess would always keep up to 64KB pending bytes somewhere. 
Then I would call the next iteration of my loop as soon as that was the 
maximum number of pending bytes not yet written (bytes read - bytes 
written <= 64KB). With that approach, the code got stuck a little later, 
as the number of bytes written in one go (block size?) began increasing 
to 128KB and further.

Isn't it possible to to turn off the internal write cache of QProcess? 
Or at least set a reasonable, known limit like 1 MB so it won't grow to 
4 GB?



Philip




More information about the Interest mailing list