[vlc-commits] http: define an error value for stream read (refs #17159)
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> | Mon Aug 22 05:24:07 2016 +0300| [df24c69f34e8202a8fd1cbe375419b6566ef1934] | committer: Rémi Denis-Courmont
http: define an error value for stream read (refs #17159)
This distinguishes unexpected error from regular end-of-stream.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=df24c69f34e8202a8fd1cbe375419b6566ef1934
---
modules/access/http/file.c | 9 ++++++---
modules/access/http/live.c | 2 +-
modules/access/http/message.c | 6 ++++++
modules/access/http/message.h | 20 +++++++++++++++++++-
4 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/modules/access/http/file.c b/modules/access/http/file.c
index a6b6bb0..ce101f6 100644
--- a/modules/access/http/file.c
+++ b/modules/access/http/file.c
@@ -234,18 +234,21 @@ block_t *vlc_http_file_read(struct vlc_http_resource *res)
struct vlc_http_file *file = (struct vlc_http_file *)res;
block_t *block = vlc_http_res_read(res);
- if (block == NULL)
- { /* Automatically reconnect if server supports seek */
+ if (block == vlc_http_error)
+ { /* Automatically reconnect on error if server supports seek */
if (res->response != NULL
&& vlc_http_msg_can_seek(res->response)
&& file->offset < vlc_http_msg_get_file_size(res->response)
&& vlc_http_file_seek(res, file->offset) == 0)
block = vlc_http_res_read(res);
- if (block == NULL)
+ if (block == vlc_http_error)
return NULL;
}
+ if (block == NULL)
+ return NULL; /* End of stream */
+
file->offset += block->i_buffer;
return block;
}
diff --git a/modules/access/http/live.c b/modules/access/http/live.c
index 3ef1870..6daf967 100644
--- a/modules/access/http/live.c
+++ b/modules/access/http/live.c
@@ -75,7 +75,7 @@ struct vlc_http_resource *vlc_http_live_create(struct vlc_http_mgr *mgr,
block_t *vlc_http_live_read(struct vlc_http_resource *res)
{
struct block_t *block = vlc_http_res_read(res);
- if (block != NULL)
+ if (block != NULL && block != vlc_http_error)
return block;
/* Automatically try to reconnect */
diff --git a/modules/access/http/message.c b/modules/access/http/message.c
index b3dd48a..b3874be 100644
--- a/modules/access/http/message.c
+++ b/modules/access/http/message.c
@@ -24,6 +24,7 @@
#include <assert.h>
#include <errno.h>
+#include <stdalign.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -48,6 +49,11 @@ struct vlc_http_msg
struct vlc_http_stream *payload;
};
+/* Maximum alignment for safe conversion to/from any specific pointer type */
+static const char alignas (max_align_t) vlc_http_error_loc;
+
+void *const vlc_http_error = (char *)&vlc_http_error_loc;
+
static bool vlc_http_is_token(const char *);
static ssize_t vlc_http_msg_find_header(const struct vlc_http_msg *m,
diff --git a/modules/access/http/message.h b/modules/access/http/message.h
index 302184e..0c34e85 100644
--- a/modules/access/http/message.h
+++ b/modules/access/http/message.h
@@ -280,7 +280,9 @@ struct vlc_http_msg *vlc_http_msg_get_final(struct vlc_http_msg *) VLC_USED;
* been received, waits until data is received, the stream ends or the
* underlying connection fails.
*
- * @return data block, or NULL on end-of-stream or error
+ * @return data block
+ * @retval NULL on end-of-stream
+ * @retval vlc_http_error on fatal error
*/
struct block_t *vlc_http_msg_read(struct vlc_http_msg *) VLC_USED;
@@ -306,6 +308,18 @@ struct block_t *vlc_http_msg_read(struct vlc_http_msg *) VLC_USED;
struct vlc_http_stream;
+/**
+ * Error pointer value
+ *
+ * This is an error value for some HTTP functions that can return NULL in
+ * non-error circumstances. Another return value is necessary to express
+ * error/failure, which this is.
+ * This compares different to NULL and to any valid pointer.
+ *
+ * @warning Dereferencing this pointer is undefined.
+ */
+extern void *const vlc_http_error;
+
void vlc_http_msg_attach(struct vlc_http_msg *m, struct vlc_http_stream *s);
struct vlc_http_msg *vlc_http_msg_get_initial(struct vlc_http_stream *s)
VLC_USED;
@@ -348,6 +362,10 @@ struct vlc_http_msg *vlc_http_stream_read_headers(struct vlc_http_stream *s)
* Reads message payload data.
*
* Reads the next block of data from the message payload of an HTTP stream.
+ *
+ * @return a block of data (use block_Release() to free it)
+ * @retval NULL The end of the stream was reached.
+ * @retval vlc_http_error The stream encountered a fatal error.
*/
static inline struct block_t *vlc_http_stream_read(struct vlc_http_stream *s)
{
More information about the vlc-commits
mailing list