stream: minor cleanup to previous commit

This is almost cosmetic, but removes the duplicated EOF-setting.

Somewhat oddly, this will enter the reconnect path and exit it
immediately again - should be fine.
This commit is contained in:
wm4 2017-01-27 09:03:14 +01:00
parent 4e53f9e5b2
commit 70411f2709
1 changed files with 7 additions and 12 deletions

View File

@ -359,24 +359,19 @@ static bool stream_reconnect(stream_t *s)
// Partial reads are possible, even if EOF is not reached. // Partial reads are possible, even if EOF is not reached.
static int stream_read_unbuffered(stream_t *s, void *buf, int len) static int stream_read_unbuffered(stream_t *s, void *buf, int len)
{ {
int orig_len = len; int res = 0;
s->buf_pos = s->buf_len = 0; s->buf_pos = s->buf_len = 0;
if (mp_cancel_test(s->cancel)) {
s->eof = 1;
return 0;
}
// we will retry even if we already reached EOF previously. // we will retry even if we already reached EOF previously.
len = s->fill_buffer ? s->fill_buffer(s, buf, len) : -1; if (s->fill_buffer && !mp_cancel_test(s->cancel))
if (len < 0) res = s->fill_buffer(s, buf, len);
len = 0; if (res <= 0) {
if (len == 0) {
// just in case this is an error e.g. due to network // just in case this is an error e.g. due to network
// timeout reset and retry // timeout reset and retry
// do not retry if this looks like proper eof // do not retry if this looks like proper eof
int64_t size = stream_get_size(s); int64_t size = stream_get_size(s);
if (!s->eof && s->pos != size && stream_reconnect(s)) { if (!s->eof && s->pos != size && stream_reconnect(s)) {
s->eof = 1; // make sure EOF is set to ensure no endless recursion s->eof = 1; // make sure EOF is set to ensure no endless recursion
return stream_read_unbuffered(s, buf, orig_len); return stream_read_unbuffered(s, buf, len);
} }
s->eof = 1; s->eof = 1;
@ -384,8 +379,8 @@ static int stream_read_unbuffered(stream_t *s, void *buf, int len)
} }
// When reading succeeded we are obviously not at eof. // When reading succeeded we are obviously not at eof.
s->eof = 0; s->eof = 0;
s->pos += len; s->pos += res;
return len; return res;
} }
static int stream_fill_buffer_by(stream_t *s, int64_t len) static int stream_fill_buffer_by(stream_t *s, int64_t len)