[vlc-devel] [PATCH 5/8] httpd/core: handle stream drain
Thomas Guillem
thomas at gllm.fr
Mon Jan 29 18:25:53 CET 2018
When calling httpd_StreamSend(stream, NULL).
---
src/network/httpd.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/network/httpd.c b/src/network/httpd.c
index d9237ebb9c..0bd526c5eb 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -611,6 +611,7 @@ struct httpd_stream_t
uint8_t *p_buffer; /* buffer */
int64_t i_buffer_pos; /* absolute position from beginning */
int64_t i_buffer_last_pos; /* a new connection will start with that */
+ int64_t i_buffer_eof_pos;
/* custom headers */
size_t i_http_headers;
@@ -630,7 +631,11 @@ static int httpd_StreamCallBack(httpd_callback_sys_t *p_sys,
int i_pos;
if (answer->i_body_offset >= stream->i_buffer_pos)
+ {
+ if (stream->i_buffer_eof_pos != 0 && answer->i_body_offset >= stream->i_buffer_eof_pos)
+ cl->i_state = HTTPD_CLIENT_DEAD;
return VLC_EGENERIC; /* wait, no data available */
+ }
if (cl->i_keyframe_wait_to_pass >= 0) {
if (stream->i_last_keyframe_seen_pos <= cl->i_keyframe_wait_to_pass)
@@ -769,6 +774,7 @@ httpd_stream_t *httpd_StreamNew(httpd_host_t *host,
* (this way i_body_offset can never be 0) */
stream->i_buffer_pos = 1;
stream->i_buffer_last_pos = 1;
+ stream->i_buffer_eof_pos = 0;
stream->b_has_keyframes = false;
stream->i_last_keyframe_seen_pos = 0;
stream->i_http_headers = 0;
@@ -820,10 +826,17 @@ static void httpd_AppendData(httpd_stream_t *stream, uint8_t *p_data, int i_data
int httpd_StreamSend(httpd_stream_t *stream, const block_t *p_block)
{
- if (!p_block || !p_block->p_buffer)
+ vlc_mutex_lock(&stream->lock);
+
+ if (!p_block)
+ {
+ /* Drain */
+ stream->i_buffer_eof_pos = stream->i_buffer_pos;
+ vlc_mutex_unlock(&stream->lock);
return VLC_SUCCESS;
+ }
- vlc_mutex_lock(&stream->lock);
+ assert(p_block->p_buffer);
/* save this pointer (to be used by new connection) */
stream->i_buffer_last_pos = stream->i_buffer_pos;
--
2.11.0
More information about the vlc-devel
mailing list