[vlc-commits] http: add stream error reporting for HTTP/1.x

Rémi Denis-Courmont git at videolan.org
Tue Aug 30 15:12:59 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug 30 15:51:56 2016 +0300| [7946ad19a3ed8a62372fa2015b110482e16d5ad5] | committer: Rémi Denis-Courmont

http: add stream error reporting for HTTP/1.x

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7946ad19a3ed8a62372fa2015b110482e16d5ad5
---

 modules/access/http/h1conn.c      | 12 ++++++++++--
 modules/access/http/h1conn_test.c |  6 +++---
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/modules/access/http/h1conn.c b/modules/access/http/h1conn.c
index 9801d36..bc4ac48 100644
--- a/modules/access/http/h1conn.c
+++ b/modules/access/http/h1conn.c
@@ -23,6 +23,7 @@
 #endif
 
 #include <assert.h>
+#include <errno.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -236,7 +237,7 @@ static block_t *vlc_h1_stream_read(struct vlc_http_stream *stream)
     assert(conn->active);
 
     if (conn->conn.tls == NULL)
-        return NULL;
+        return vlc_http_error;
 
     if (size > conn->content_length)
         size = conn->content_length;
@@ -245,12 +246,19 @@ static block_t *vlc_h1_stream_read(struct vlc_http_stream *stream)
 
     block_t *block = block_Alloc(size);
     if (unlikely(block == NULL))
-        return NULL;
+        return vlc_http_error;
 
     ssize_t val = vlc_tls_Read(conn->conn.tls, block->p_buffer, size, false);
     if (val <= 0)
     {
         block_Release(block);
+        if (val < 0)
+            return vlc_http_error;
+        if (conn->content_length != UINTMAX_MAX)
+        {
+            errno = ECONNRESET;
+            return vlc_http_error;
+        }
         return NULL;
     }
 
diff --git a/modules/access/http/h1conn_test.c b/modules/access/http/h1conn_test.c
index 4e3b512..881eb5a 100644
--- a/modules/access/http/h1conn_test.c
+++ b/modules/access/http/h1conn_test.c
@@ -116,11 +116,11 @@ int main(void)
     m = vlc_http_stream_read_headers(s);
     assert(m == NULL);
     b = vlc_http_stream_read(s);
-    assert(b == NULL);
+    assert(b == vlc_http_error);
     m = vlc_http_stream_read_headers(s);
     assert(m == NULL);
     b = vlc_http_stream_read(s);
-    assert(b == NULL);
+    assert(b == vlc_http_error);
     m = vlc_http_msg_get_initial(s);
     assert(m == NULL);
 
@@ -138,7 +138,7 @@ int main(void)
     m = vlc_http_stream_read_headers(s);
     assert(m == NULL);
     b = vlc_http_stream_read(s);
-    assert(b == NULL);
+    assert(b == vlc_http_error);
     conn_destroy();
     vlc_http_stream_close(s, false);
 



More information about the vlc-commits mailing list