From 491f633a208ab1b16ad39653b4ccdf180fd7505d Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 25 Apr 2014 19:11:58 +0200 Subject: stream: use uninterruptible sleep on reconnecting This is the only function which actually used the time argument of stream_check_interrupt(). Considering that the whole player freezes anyway, this is not worth the complication. Also generally reduce the maximum wait time due to timeout. Introduce exponential backoff, which makes the first reconnect retries faster, but still waits up to 500ms in the later retries. --- stream/stream.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stream/stream.c b/stream/stream.c index b48de575ea..cd809503d2 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -396,16 +396,22 @@ stream_t *open_output_stream(const char *filename, struct mpv_global *global) static int stream_reconnect(stream_t *s) { #define MAX_RECONNECT_RETRIES 5 -#define RECONNECT_SLEEP_MS 1000 +#define RECONNECT_SLEEP_MAX_MS 500 if (!s->streaming) return 0; if (!(s->flags & MP_STREAM_SEEK_FW)) return 0; int64_t pos = s->pos; + int sleep_ms = 5; for (int retry = 0; retry < MAX_RECONNECT_RETRIES; retry++) { MP_WARN(s, "Connection lost! Attempting to reconnect (%d)...\n", retry + 1); - if (stream_check_interrupt(retry ? RECONNECT_SLEEP_MS : 0)) + if (retry) { + mp_sleep_us(sleep_ms * 1000); + sleep_ms = MPMIN(sleep_ms * 2, RECONNECT_SLEEP_MAX_MS); + } + + if (stream_check_interrupt(0)) return 0; s->eof = 1; -- cgit v1.2.3