libchromeos: Add FlushAsync() to the Stream interface.
Buffered streams such as compressed streams or simply memory buffered
streams need to write all the internal data to the underlying medium
on CloseBlocking(). This means that a compressed stream that writes
the compressed data to a socket-based stream would block on the network
on the final write when either FlushBlocking() or CloseBlocking() is
called.
This patch extends the Stream interface with a FlushAsync() method that
will flush all the internal buffer with a default implementation that
posts a task to the main loop and runs the FlushBlocking() from there.
This default implementation is suitable for Stream implementations that
don't have any user-space buffer.
The documentation of FlushBlocking() and FlushAsync() is updated to
mention that it is limited to flush user-space buffer, matching the
behavior of other library functions like fflush(). FileStream is
updated to match this new description.
BUG=None
TEST=FEATURES=test emerge-link libchromeos
Change-Id: I4c0bce92cd24ab9b26437a2dfd80fadb8fddd78e
Reviewed-on: https://chromium-review.googlesource.com/265142
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
5 files changed