Commit df24c69f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

http: define an error value for stream read (refs #17159)

This distinguishes unexpected error from regular end-of-stream.
parent 2c576fed
......@@ -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;
}
......@@ -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 */
......
......@@ -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,
......
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment