From: Daniel Stenberg Date: Sun, 20 Apr 2025 21:24:52 +0000 (+0200) Subject: vquic: consistent name for the stream struct across backends X-Git-Tag: curl-8_14_0~251 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2de9a9714194f63b5043c0fe0cc0812a5274d11c;p=thirdparty%2Fcurl.git vquic: consistent name for the stream struct across backends Now known as "struct h3_stream_ctx" in all four backends. Also as a bonus: a single definition of the H3_STREAM_CTX macro Closes #17113 --- diff --git a/lib/vquic/curl_msh3.c b/lib/vquic/curl_msh3.c index 331bc37510..7dca1dc115 100644 --- a/lib/vquic/curl_msh3.c +++ b/lib/vquic/curl_msh3.c @@ -42,6 +42,7 @@ #include "../socketpair.h" #include "../vtls/vtls.h" #include "vquic.h" +#include "vquic_int.h" /* The last 3 #include files should be in this order */ #include "../curl_printf.h" @@ -170,7 +171,7 @@ static struct cf_msh3_ctx *h3_get_msh3_ctx(struct Curl_easy *data); /** * All about the H3 internals of a stream */ -struct stream_ctx { +struct h3_stream_ctx { struct MSH3_REQUEST *req; struct bufq recvbuf; /* h3 response */ #ifdef _WIN32 @@ -188,10 +189,7 @@ struct stream_ctx { BIT(recv_header_complete); }; -#define H3_STREAM_CTX(ctx,data) ((struct stream_ctx *)((data && ctx)? \ - Curl_uint_hash_get(&(ctx)->streams, (data)->mid) : NULL)) - -static void h3_stream_ctx_free(struct stream_ctx *stream) +static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { Curl_bufq_free(&stream->recvbuf); free(stream); @@ -201,14 +199,14 @@ static void h3_stream_hash_free(unsigned int id, void *stream) { (void)id; DEBUGASSERT(stream); - h3_stream_ctx_free((struct stream_ctx *)stream); + h3_stream_ctx_free((struct h3_stream_ctx *)stream); } static CURLcode h3_data_setup(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); if(stream) return CURLE_OK; @@ -234,7 +232,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)cf; if(stream) { @@ -244,7 +242,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) } static void drain_stream_from_other_thread(struct Curl_easy *data, - struct stream_ctx *stream) + struct h3_stream_ctx *stream) { unsigned char bits; @@ -262,7 +260,7 @@ static void h3_drain_stream(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); unsigned char bits; (void)cf; @@ -361,7 +359,7 @@ static CURLcode write_resp_raw(struct Curl_easy *data, const void *mem, size_t memlen) { struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data); - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); CURLcode result = CURLE_OK; ssize_t nwritten; @@ -388,7 +386,7 @@ static void MSH3_CALL msh3_header_received(MSH3_REQUEST *Request, { struct Curl_easy *data = userp; struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data); - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); CURLcode result; (void)Request; @@ -439,7 +437,7 @@ static bool MSH3_CALL msh3_data_received(MSH3_REQUEST *Request, { struct Curl_easy *data = IfContext; struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data); - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); CURLcode result; bool rv = FALSE; @@ -479,7 +477,7 @@ static void MSH3_CALL msh3_complete(MSH3_REQUEST *Request, void *IfContext, { struct Curl_easy *data = IfContext; struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data); - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)Request; if(!stream) @@ -499,7 +497,7 @@ static void MSH3_CALL msh3_shutdown_complete(MSH3_REQUEST *Request, { struct Curl_easy *data = IfContext; struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data); - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); if(!stream) return; @@ -512,7 +510,7 @@ static void MSH3_CALL msh3_data_sent(MSH3_REQUEST *Request, { struct Curl_easy *data = IfContext; struct cf_msh3_ctx *ctx = h3_get_msh3_ctx(data); - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); if(!stream) return; (void)Request; @@ -525,7 +523,7 @@ static ssize_t recv_closed_stream(struct Curl_cfilter *cf, CURLcode *err) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); ssize_t nread = -1; if(!stream) { @@ -559,7 +557,7 @@ out: static void set_quic_expire(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); /* we have no indication from msh3 when it would be a good time * to juggle the connection again. So, we compromise by calling @@ -577,7 +575,7 @@ static ssize_t cf_msh3_recv(struct Curl_cfilter *cf, struct Curl_easy *data, char *buf, size_t len, CURLcode *err) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); ssize_t nread = -1; struct cf_call_data save; @@ -629,7 +627,7 @@ static ssize_t cf_msh3_send(struct Curl_cfilter *cf, struct Curl_easy *data, CURLcode *err) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); struct h1_req_parser h1; struct dynhds h2_headers; MSH3_HEADER *nva = NULL; @@ -725,7 +723,7 @@ static void cf_msh3_adjust_pollset(struct Curl_cfilter *cf, struct easy_pollset *ps) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); struct cf_call_data save; CF_DATA_SAVE(save, cf, data); @@ -745,7 +743,7 @@ static bool cf_msh3_data_pending(struct Curl_cfilter *cf, const struct Curl_easy *data) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); struct cf_call_data save; bool pending = FALSE; @@ -783,7 +781,7 @@ static CURLcode cf_msh3_data_event(struct Curl_cfilter *cf, int event, int arg1, void *arg2) { struct cf_msh3_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); struct cf_call_data save; CURLcode result = CURLE_OK; diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 3909a8b74f..fc22f18f99 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -253,9 +253,6 @@ struct h3_stream_ctx { BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ }; -#define H3_STREAM_CTX(ctx,data) ((struct h3_stream_ctx *)(\ - data? Curl_uint_hash_get(&(ctx)->streams, (data)->mid) : NULL)) - static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { Curl_bufq_free(&stream->sendbuf); diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index f7409ad3d8..0603b1ab9c 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -590,9 +590,6 @@ struct h3_stream_ctx { BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ }; -#define H3_STREAM_CTX(ctx,data) ((struct h3_stream_ctx *)(\ - data? Curl_uint_hash_get(&(ctx)->streams, (data)->mid) : NULL)) - static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { cf_osslq_stream_cleanup(&stream->s); diff --git a/lib/vquic/curl_quiche.c b/lib/vquic/curl_quiche.c index d5e045779b..caae5f3082 100644 --- a/lib/vquic/curl_quiche.c +++ b/lib/vquic/curl_quiche.c @@ -165,7 +165,7 @@ static CURLcode cf_flush_egress(struct Curl_cfilter *cf, /** * All about the H3 internals of a stream */ -struct stream_ctx { +struct h3_stream_ctx { curl_uint64_t id; /* HTTP/3 protocol stream identifier */ struct bufq recvbuf; /* h3 response */ struct h1_req_parser h1; /* h1 request parsing */ @@ -179,10 +179,7 @@ struct stream_ctx { BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ }; -#define H3_STREAM_CTX(ctx,data) ((struct stream_ctx *)(\ - data? Curl_uint_hash_get(&(ctx)->streams, (data)->mid) : NULL)) - -static void h3_stream_ctx_free(struct stream_ctx *stream) +static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { Curl_bufq_free(&stream->recvbuf); Curl_h1_req_parse_free(&stream->h1); @@ -193,12 +190,12 @@ static void h3_stream_hash_free(unsigned int id, void *stream) { (void)id; DEBUGASSERT(stream); - h3_stream_ctx_free((struct stream_ctx *)stream); + h3_stream_ctx_free((struct h3_stream_ctx *)stream); } typedef bool cf_quiche_svisit(struct Curl_cfilter *cf, struct Curl_easy *sdata, - struct stream_ctx *stream, + struct h3_stream_ctx *stream, void *user_data); struct cf_quiche_visit_ctx { @@ -211,7 +208,7 @@ struct cf_quiche_visit_ctx { static bool cf_quiche_stream_do(unsigned int mid, void *val, void *user_data) { struct cf_quiche_visit_ctx *vctx = user_data; - struct stream_ctx *stream = val; + struct h3_stream_ctx *stream = val; struct Curl_easy *sdata = Curl_multi_get_easy(vctx->multi, mid); if(sdata) return vctx->cb(vctx->cf, sdata, stream, vctx->user_data); @@ -234,7 +231,7 @@ static void cf_quiche_for_all_streams(struct Curl_cfilter *cf, static bool cf_quiche_do_resume(struct Curl_cfilter *cf, struct Curl_easy *sdata, - struct stream_ctx *stream, + struct h3_stream_ctx *stream, void *user_data) { (void)user_data; @@ -248,7 +245,7 @@ static bool cf_quiche_do_resume(struct Curl_cfilter *cf, static bool cf_quiche_do_expire(struct Curl_cfilter *cf, struct Curl_easy *sdata, - struct stream_ctx *stream, + struct h3_stream_ctx *stream, void *user_data) { (void)stream; @@ -262,7 +259,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); if(stream) return CURLE_OK; @@ -287,7 +284,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); CURLcode result; (void)cf; @@ -314,7 +311,7 @@ static void h3_drain_stream(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); unsigned char bits; (void)cf; @@ -345,7 +342,7 @@ static CURLcode write_resp_raw(struct Curl_cfilter *cf, const void *mem, size_t memlen) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); CURLcode result = CURLE_OK; ssize_t nwritten; @@ -376,7 +373,7 @@ static int cb_each_header(uint8_t *name, size_t name_len, { struct cb_ctx *x = argp; struct cf_quiche_ctx *ctx = x->cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, x->data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, x->data); CURLcode result; if(!stream) @@ -416,7 +413,7 @@ static ssize_t stream_resp_read(void *reader_ctx, { struct cb_ctx *x = reader_ctx; struct cf_quiche_ctx *ctx = x->cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, x->data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, x->data); ssize_t nread; if(!stream) { @@ -440,7 +437,7 @@ static CURLcode cf_recv_body(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); ssize_t nwritten; struct cb_ctx cb_ctx; CURLcode result = CURLE_OK; @@ -498,7 +495,7 @@ static const char *cf_ev_name(quiche_h3_event *ev) static CURLcode h3_process_event(struct Curl_cfilter *cf, struct Curl_easy *data, - struct stream_ctx *stream, + struct h3_stream_ctx *stream, quiche_h3_event *ev) { struct cb_ctx cb_ctx; @@ -561,7 +558,7 @@ static CURLcode h3_process_event(struct Curl_cfilter *cf, static CURLcode cf_quiche_ev_process(struct Curl_cfilter *cf, struct Curl_easy *data, - struct stream_ctx *stream, + struct h3_stream_ctx *stream, quiche_h3_event *ev) { CURLcode result = h3_process_event(cf, data, stream, ev); @@ -584,7 +581,7 @@ struct cf_quich_disp_ctx { static bool cf_quiche_disp_event(unsigned int mid, void *val, void *user_data) { struct cf_quich_disp_ctx *dctx = user_data; - struct stream_ctx *stream = val; + struct h3_stream_ctx *stream = val; if(stream->id == dctx->stream_id) { struct Curl_easy *sdata = Curl_multi_get_easy(dctx->multi, mid); @@ -599,7 +596,7 @@ static CURLcode cf_poll_events(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = NULL; + struct h3_stream_ctx *stream = NULL; quiche_h3_event *ev; /* Take in the events and distribute them to the transfers. */ @@ -848,7 +845,7 @@ static ssize_t recv_closed_stream(struct Curl_cfilter *cf, CURLcode *err) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); ssize_t nread = -1; DEBUGASSERT(stream); @@ -880,7 +877,7 @@ static ssize_t cf_quiche_recv(struct Curl_cfilter *cf, struct Curl_easy *data, char *buf, size_t len, CURLcode *err) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); ssize_t nread = -1; CURLcode result; @@ -953,7 +950,7 @@ out: static ssize_t cf_quiche_send_body(struct Curl_cfilter *cf, struct Curl_easy *data, - struct stream_ctx *stream, + struct h3_stream_ctx *stream, const void *buf, size_t len, bool eos, CURLcode *err) { @@ -1012,7 +1009,7 @@ static ssize_t h3_open_stream(struct Curl_cfilter *cf, CURLcode *err) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); size_t nheader, i; curl_int64_t stream3_id; struct dynhds h2_headers; @@ -1132,7 +1129,7 @@ static ssize_t cf_quiche_send(struct Curl_cfilter *cf, struct Curl_easy *data, CURLcode *err) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); CURLcode result; ssize_t nwritten; @@ -1191,7 +1188,7 @@ static bool stream_is_writeable(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_quiche_ctx *ctx = cf->ctx; - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); return stream && (quiche_conn_stream_writable( ctx->qconn, (curl_uint64_t)stream->id, 1) > 0); @@ -1209,7 +1206,7 @@ static void cf_quiche_adjust_pollset(struct Curl_cfilter *cf, Curl_pollset_check(data, ps, ctx->q.sockfd, &want_recv, &want_send); if(want_recv || want_send) { - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); bool c_exhaust, s_exhaust; c_exhaust = FALSE; /* Have not found any call in quiche that tells @@ -1232,7 +1229,7 @@ static bool cf_quiche_data_pending(struct Curl_cfilter *cf, const struct Curl_easy *data) { struct cf_quiche_ctx *ctx = cf->ctx; - const struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + const struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)cf; return stream && !Curl_bufq_is_empty(&stream->recvbuf); } @@ -1269,7 +1266,7 @@ static CURLcode cf_quiche_data_event(struct Curl_cfilter *cf, h3_data_done(cf, data); break; case CF_CTRL_DATA_DONE_SEND: { - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); if(stream && !stream->send_closed) { unsigned char body[1]; ssize_t sent; @@ -1283,7 +1280,7 @@ static CURLcode cf_quiche_data_event(struct Curl_cfilter *cf, break; } case CF_CTRL_DATA_IDLE: { - struct stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); if(stream && !stream->closed) { result = cf_flush_egress(cf, data); if(result) diff --git a/lib/vquic/vquic_int.h b/lib/vquic/vquic_int.h index 0810b4dab1..4641c3125b 100644 --- a/lib/vquic/vquic_int.h +++ b/lib/vquic/vquic_int.h @@ -51,6 +51,9 @@ struct cf_quic_ctx { BIT(no_gso); /* do not use gso on sending */ }; +#define H3_STREAM_CTX(ctx,data) \ + (data ? Curl_uint_hash_get(&(ctx)->streams, (data)->mid) : NULL) + CURLcode vquic_ctx_init(struct cf_quic_ctx *qctx); void vquic_ctx_free(struct cf_quic_ctx *qctx);