summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-09-14 12:55:06 +0200
committerwm4 <wm4@nowhere>2019-09-14 12:55:06 +0200
commitbec218c4ad70d0eb1ae5a1d6a4455d9fd16bad0c (patch)
tree739280a02f19542799ef2d373ad5a08c921afc8f /stream
parentebab42c9a826e346faa89482847f442546a554f5 (diff)
downloadmpv-bec218c4ad70d0eb1ae5a1d6a4455d9fd16bad0c.tar.bz2
mpv-bec218c4ad70d0eb1ae5a1d6a4455d9fd16bad0c.tar.xz
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.
Diffstat (limited to 'stream')
-rw-r--r--stream/stream.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 8068effc06..c318554feb 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -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 rd;
if (!s->write_buffer)
return -1;
- rd = s->write_buffer(s, buf, len);
- if (rd < 0)
- return -1;
- s->pos += rd;
- assert(rd == len && "stream_write_buffer(): unexpected short write");
- return rd;
+ int orig_len = len;
+ while (len) {
+ int w = s->write_buffer(s, buf, len);
+ if (w <= 0)
+ return -1;
+ s->pos += w;
+ buf += w;
+ len -= w;
+ }
+ return orig_len;
}
// Drop len bytes form input, possibly reading more until all is skipped. If