From b1edc28695daffb1f986c812098ce64bfeaa3e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 11 Jul 2016 19:57:18 +0300 Subject: [PATCH] souphttpsrc: Fix keep-alive handling We have to get rid of the message on EOS when the complete stream is read to remember that we successfully finished handling this specific message. Otherwise we will cancel it later and close the connection instead of reusing it at a later time. It might also make sense to reuse connections if a non-200 response is received. As long as there was no connection error, the HTTP connection should be re-usable. --- ext/soup/gstsouphttpsrc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ext/soup/gstsouphttpsrc.c b/ext/soup/gstsouphttpsrc.c index cd6670439c..4edc9263c7 100644 --- a/ext/soup/gstsouphttpsrc.c +++ b/ext/soup/gstsouphttpsrc.c @@ -968,11 +968,16 @@ gst_soup_http_src_session_close (GstSoupHTTPSrc * src) GST_DEBUG_OBJECT (src, "Closing session"); g_mutex_lock (&src->mutex); + if (src->msg) { + soup_session_cancel_message (src->session, src->msg, SOUP_STATUS_CANCELLED); + g_object_unref (src->msg); + src->msg = NULL; + } + if (src->session) { - soup_session_abort (src->session); /* This unrefs the message. */ + soup_session_abort (src->session); g_object_unref (src->session); src->session = NULL; - src->msg = NULL; } g_mutex_unlock (&src->mutex); } @@ -1626,7 +1631,6 @@ gst_soup_http_src_read_buffer (GstSoupHTTPSrc * src, GstBuffer ** outbuf) g_mutex_unlock (&src->mutex); return GST_FLOW_FLUSHING; } - g_mutex_unlock (&src->mutex); gst_buffer_unmap (*outbuf, &mapinfo); if (read_bytes > 0) { @@ -1645,10 +1649,14 @@ gst_soup_http_src_read_buffer (GstSoupHTTPSrc * src, GstBuffer ** outbuf) /* Maybe the server disconnected, retry */ ret = GST_FLOW_CUSTOM_ERROR; } else { + g_object_unref (src->msg); + src->msg = NULL; ret = GST_FLOW_EOS; src->have_body = TRUE; } } + g_mutex_unlock (&src->mutex); + return ret; }