#
f0a016dc |
|
21-Sep-2023 |
Augustin Cavalier <waddlesplash@gmail.com> |
BBufferedDataIO: Fix Write(). I looked at this code as a reference when writing similar code in another project, and realized then that this was broken to the point where I don't think anyone could have actually used it: 1. Writes larger than the buffer should only return the amount written by this Write() call, not the amount flushed beforehand. 2. fDirty was only set if there were bytes remaining after the first write to the buffer. So, if you wrote small amounts of data, they would be silently discarded most of the time! 3. When filling the buffer, we might as well flush simultaneously. This allows the logic to be consolidated into a loop and remove the duplicate memcpy. In case of failure, just return the bytes-written as the write could be retried later. 4. Flush() should always return an error or 0, not bytes written. While at it, add some basic tests for this class. Change-Id: I2de01d0b31e3fe22863cef21dd7b0b62ed47121b
|