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

http: use container_of()

parent b7933615
......@@ -46,8 +46,6 @@ struct vlc_chunked_stream
bool error;
};
static_assert(offsetof(struct vlc_chunked_stream, stream) == 0, "Cast error");
static void *vlc_chunked_fatal(struct vlc_chunked_stream *s)
{
s->error = true;
......@@ -64,7 +62,8 @@ static struct vlc_http_msg *vlc_chunked_wait(struct vlc_http_stream *stream)
static block_t *vlc_chunked_read(struct vlc_http_stream *stream)
{
struct vlc_chunked_stream *s = (struct vlc_chunked_stream *)stream;
struct vlc_chunked_stream *s =
container_of(stream, struct vlc_chunked_stream, stream);
block_t *block = NULL;
if (s->eof)
......@@ -134,7 +133,8 @@ static block_t *vlc_chunked_read(struct vlc_http_stream *stream)
static void vlc_chunked_close(struct vlc_http_stream *stream, bool abort)
{
struct vlc_chunked_stream *s = (struct vlc_chunked_stream *)stream;
struct vlc_chunked_stream *s =
container_of(stream, struct vlc_chunked_stream, stream);
if (!s->eof) /* Abort connection if stream is closed before end */
vlc_chunked_fatal(s);
......
......@@ -135,17 +135,15 @@ static void *vlc_h1_stream_fatal(struct vlc_h1_conn *conn)
return NULL;
}
static_assert(offsetof(struct vlc_h1_conn, conn) == 0, "Cast error");
static struct vlc_h1_conn *vlc_h1_stream_conn(struct vlc_http_stream *stream)
{
return (void *)(((char *)stream) - offsetof(struct vlc_h1_conn, stream));
return container_of(stream, struct vlc_h1_conn, stream);
}
static struct vlc_http_stream *vlc_h1_stream_open(struct vlc_http_conn *c,
const struct vlc_http_msg *req)
{
struct vlc_h1_conn *conn = (struct vlc_h1_conn *)c;
struct vlc_h1_conn *conn = container_of(c, struct vlc_h1_conn, conn);
size_t len;
ssize_t val;
......@@ -307,7 +305,7 @@ static void vlc_h1_conn_destroy(struct vlc_h1_conn *conn)
static void vlc_h1_conn_release(struct vlc_http_conn *c)
{
struct vlc_h1_conn *conn = (struct vlc_h1_conn *)c;
struct vlc_h1_conn *conn = container_of(c, struct vlc_h1_conn, conn);
assert(!conn->released);
conn->released = true;
......
......@@ -60,8 +60,6 @@ struct vlc_h2_conn
vlc_thread_t thread; /**< Receive thread */
};
static_assert(offsetof(struct vlc_h2_conn, conn) == 0, "Cast error");
static void vlc_h2_conn_destroy(struct vlc_h2_conn *conn);
/** HTTP/2 stream */
......@@ -237,11 +235,10 @@ static int vlc_h2_stream_unlock(struct vlc_h2_stream *s)
return vlc_interrupt_unregister();
}
static_assert(offsetof(struct vlc_h2_stream, stream) == 0, "Cast error");
static struct vlc_http_msg *vlc_h2_stream_wait(struct vlc_http_stream *stream)
{
struct vlc_h2_stream *s = (struct vlc_h2_stream *)stream;
struct vlc_h2_stream *s =
container_of(stream, struct vlc_h2_stream, stream);
struct vlc_h2_conn *conn = s->conn;
struct vlc_http_msg *m;
......@@ -272,7 +269,8 @@ static struct vlc_http_msg *vlc_h2_stream_wait(struct vlc_http_stream *stream)
*/
static block_t *vlc_h2_stream_read(struct vlc_http_stream *stream)
{
struct vlc_h2_stream *s = (struct vlc_h2_stream *)stream;
struct vlc_h2_stream *s =
container_of(stream, struct vlc_h2_stream, stream);
struct vlc_h2_conn *conn = s->conn;
struct vlc_h2_frame *f;
......@@ -339,7 +337,8 @@ static block_t *vlc_h2_stream_read(struct vlc_http_stream *stream)
*/
static void vlc_h2_stream_close(struct vlc_http_stream *stream, bool aborted)
{
struct vlc_h2_stream *s = (struct vlc_h2_stream *)stream;
struct vlc_h2_stream *s =
container_of(stream, struct vlc_h2_stream, stream);
struct vlc_h2_conn *conn = s->conn;
bool destroy = false;
uint_fast32_t code = VLC_H2_NO_ERROR;
......@@ -401,7 +400,7 @@ static const struct vlc_http_stream_cbs vlc_h2_stream_callbacks =
static struct vlc_http_stream *vlc_h2_stream_open(struct vlc_http_conn *c,
const struct vlc_http_msg *msg)
{
struct vlc_h2_conn *conn = (struct vlc_h2_conn *)c;
struct vlc_h2_conn *conn = container_of(c, struct vlc_h2_conn, conn);
struct vlc_h2_stream *s = malloc(sizeof (*s));
if (unlikely(s == NULL))
return NULL;
......@@ -697,7 +696,7 @@ static void vlc_h2_conn_destroy(struct vlc_h2_conn *conn)
static void vlc_h2_conn_release(struct vlc_http_conn *c)
{
struct vlc_h2_conn *conn = (struct vlc_h2_conn *)c;
struct vlc_h2_conn *conn = container_of(c, struct vlc_h2_conn, conn);
bool destroy;
vlc_mutex_lock(&conn->lock);
......
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