From e6823e4df46d0d90576568634c7df172f2d453d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 12 Jul 2016 00:42:02 +0300 Subject: [PATCH] souphttpsrc: At the end of a range request, read another time to finalize the request If we're at the end of a range request, read again to let libsoup finalize the request. This allows to reuse the connection again later, otherwise we would have to cancel the message and close the connection. --- ext/soup/gstsouphttpsrc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ext/soup/gstsouphttpsrc.c b/ext/soup/gstsouphttpsrc.c index 4edc926..9af2672 100644 --- a/ext/soup/gstsouphttpsrc.c +++ b/ext/soup/gstsouphttpsrc.c @@ -1643,6 +1643,28 @@ gst_soup_http_src_read_buffer (GstSoupHTTPSrc * src, GstBuffer ** outbuf) src->retry_count = 0; gst_soup_http_src_check_update_blocksize (src, read_bytes); + + /* If we're at the end of a range request, read again to let libsoup + * finalize the request. This allows to reuse the connection again later, + * otherwise we would have to cancel the message and close the connection + */ + if (bsrc->segment.stop != -1 + && bsrc->segment.position + read_bytes >= bsrc->segment.stop) { + guint8 tmp[128]; + + g_object_unref (src->msg); + src->msg = NULL; + ret = GST_FLOW_EOS; + src->have_body = TRUE; + + /* This should return immediately as we're at the end of the range */ + read_bytes = + g_input_stream_read (src->input_stream, tmp, sizeof (tmp), + src->cancellable, NULL); + if (read_bytes > 0) + GST_ERROR_OBJECT (src, + "Read %" G_GSIZE_FORMAT " bytes after end of range", read_bytes); + } } else { gst_buffer_unref (*outbuf); if (read_bytes < 0) { -- 2.7.4