You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To simplify the logic create bufwriter_do_write. This function keeps
track of the data left on self->len and, if a partial write happens,
this function uses memmove to move the remaining data back to the
beginning of the buffer.
This allows simplifying bufwriter_write and bufwriter_flush significantly.
bufwriter_flush now only needs to call this function if the buffer has
some data stored and check for any error codes.
Additionally, if the buffer is only partially flushed we notify the user
too (so that they know there might be data left).
bufwriter_write now just needs to call this function whenever the buffer
gets full and copy the input into the buffer.
It will return when either no data is written at all or when all of the
input is consumed. In the case of a partial write it returns exactly the
amount of data which was written.
Additionally allow caching of errors to better handle partial writes.
Until now if an error occurred during the write, the error would be
raised and the caller had no way to know if any data was written at all
(for example in prior calls if more than one block of data was passed as
input). Now when we have written out some data and an error happens, we
reset the buffer to the state it would have if it did not contain the
data that was not written (and which was not buffered previously), and
then, we return the data that was written (if any) or raise an error if
no data from the input was written.
This allows the programmer better control of writes. In particular, the
programmer will know exactly how much of its last input data was written,
consequently allowing it to handle whatever data left to be written in
a better way.
Signed-off-by: Francisco Blas (klondike) Izquierdo Riera <klondike@klondike.es>
0 commit comments