mirror of
https://github.com/mpv-player/mpv
synced 2025-04-24 12:24:21 +00:00
stream: handle short writes
The write functionality is almost unused (only encoding 2-pass mode uses it to write the log file). Moreover, it almost makes no sense to use this in a not local scenario. This change is just to prevent people from duplicating the short write logic across all streams that happen to support writing. Mostly untested; local log file writing still works.
This commit is contained in:
parent
ebab42c9a8
commit
bec218c4ad
@ -419,15 +419,18 @@ struct bstr stream_peek(stream_t *s, int len)
|
|||||||
|
|
||||||
int stream_write_buffer(stream_t *s, unsigned char *buf, int len)
|
int stream_write_buffer(stream_t *s, unsigned char *buf, int len)
|
||||||
{
|
{
|
||||||
int rd;
|
|
||||||
if (!s->write_buffer)
|
if (!s->write_buffer)
|
||||||
return -1;
|
return -1;
|
||||||
rd = s->write_buffer(s, buf, len);
|
int orig_len = len;
|
||||||
if (rd < 0)
|
while (len) {
|
||||||
return -1;
|
int w = s->write_buffer(s, buf, len);
|
||||||
s->pos += rd;
|
if (w <= 0)
|
||||||
assert(rd == len && "stream_write_buffer(): unexpected short write");
|
return -1;
|
||||||
return rd;
|
s->pos += w;
|
||||||
|
buf += w;
|
||||||
|
len -= w;
|
||||||
|
}
|
||||||
|
return orig_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop len bytes form input, possibly reading more until all is skipped. If
|
// Drop len bytes form input, possibly reading more until all is skipped. If
|
||||||
|
Loading…
Reference in New Issue
Block a user