Skip to content

Commit ba81217

Browse files
authored
Refactor transport parameter logging and stream handling
1 parent 49ecff7 commit ba81217

1 file changed

Lines changed: 51 additions & 56 deletions

File tree

lib/vquic/curl_ngtcp2.c

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,11 @@ static int cf_ngtcp2_handshake_completed(ngtcp2_conn *tconn, void *user_data)
523523
if(Curl_trc_is_verbose(data)) {
524524
const ngtcp2_transport_params *rp;
525525
rp = ngtcp2_conn_get_remote_transport_params(ctx->qconn);
526-
CURL_TRC_CF(data, cf, "handshake complete after %dms, remote transport["
527-
"max_udp_payload=%" FMT_PRIu64
526+
CURL_TRC_CF(data, cf, "handshake complete after %" FMT_TIMEDIFF_T
527+
"ms, remote transport[max_udp_payload=%" FMT_PRIu64
528528
", initial_max_data=%" FMT_PRIu64
529529
"]",
530-
(int)curlx_timediff(ctx->handshake_at, ctx->started_at),
530+
curlx_timediff_ms(ctx->handshake_at, ctx->started_at),
531531
(curl_uint64_t)rp->max_udp_payload_size,
532532
(curl_uint64_t)rp->initial_max_data);
533533
}
@@ -1327,32 +1327,25 @@ static CURLcode init_ngh3_conn(struct Curl_cfilter *cf,
13271327
return CURLE_OK;
13281328
}
13291329

1330-
static ssize_t recv_closed_stream(struct Curl_cfilter *cf,
1330+
static CURLcode recv_closed_stream(struct Curl_cfilter *cf,
13311331
struct Curl_easy *data,
13321332
struct h3_stream_ctx *stream,
1333-
CURLcode *err)
1333+
size_t *pnread)
13341334
{
1335-
ssize_t nread = -1;
1336-
13371335
(void)cf;
1336+
*pnread = 0;
13381337
if(stream->reset) {
13391338
failf(data, "HTTP/3 stream %" FMT_PRId64 " reset by server", stream->id);
1340-
*err = data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3;
1341-
goto out;
1339+
return data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3;
13421340
}
13431341
else if(!stream->resp_hds_complete) {
13441342
failf(data,
13451343
"HTTP/3 stream %" FMT_PRId64 " was closed cleanly, but before "
13461344
"getting all response header fields, treated as error",
13471345
stream->id);
1348-
*err = CURLE_HTTP3;
1349-
goto out;
1346+
return CURLE_HTTP3;
13501347
}
1351-
*err = CURLE_OK;
1352-
nread = 0;
1353-
1354-
out:
1355-
return nread;
1348+
return CURLE_OK;
13561349
}
13571350

13581351
/* incoming data frames on the h3 stream */
@@ -1398,9 +1391,7 @@ static CURLcode cf_ngtcp2_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
13981391
goto out;
13991392
}
14001393
else if(stream->closed) {
1401-
ssize_t nread = recv_closed_stream(cf, data, stream, &result);
1402-
if(nread > 0)
1403-
*pnread = (size_t)nread;
1394+
result = recv_closed_stream(cf, data, stream, pnread);
14041395
goto out;
14051396
}
14061397
result = CURLE_AGAIN;
@@ -2720,7 +2711,7 @@ static CURLcode cf_ngtcp2_query(struct Curl_cfilter *cf,
27202711
}
27212712
case CF_QUERY_CONNECT_REPLY_MS:
27222713
if(ctx->q.got_first_byte) {
2723-
timediff_t ms = curlx_timediff(ctx->q.first_byte_at, ctx->started_at);
2714+
timediff_t ms = curlx_timediff_ms(ctx->q.first_byte_at, ctx->started_at);
27242715
*pres1 = (ms < INT_MAX) ? (int)ms : INT_MAX;
27252716
}
27262717
else
@@ -2764,45 +2755,49 @@ static CURLcode cf_ngtcp2_query(struct Curl_cfilter *cf,
27642755
}
27652756

27662757
static bool cf_ngtcp2_conn_is_alive(struct Curl_cfilter *cf,
2767-
struct Curl_easy *data,
2768-
bool *input_pending)
2769-
{
2770-
struct cf_ngtcp2_ctx *ctx = cf->ctx;
2771-
bool alive = FALSE;
2772-
const ngtcp2_transport_params *rp;
2773-
struct cf_call_data save;
2774-
2775-
CF_DATA_SAVE(save, cf, data);
2776-
*input_pending = FALSE;
2777-
if(!ctx->qconn || ctx->shutdown_started)
2778-
goto out;
2779-
2780-
/* We do not announce a max idle timeout, but when the peer does
2781-
* it will close the connection when it expires. */
2782-
rp = ngtcp2_conn_get_remote_transport_params(ctx->qconn);
2783-
if(rp && rp->max_idle_timeout) {
2784-
timediff_t idletime = curlx_timediff(curlx_now(), ctx->q.last_io);
2785-
if(idletime > 0 && (uint64_t)idletime > rp->max_idle_timeout)
2786-
goto out;
2787-
}
2758+
struct Curl_easy *data,
2759+
bool *input_pending)
2760+
{
2761+
struct cf_ngtcp2_ctx *ctx = cf->ctx;
2762+
bool alive = FALSE;
2763+
const ngtcp2_transport_params *rp;
2764+
struct cf_call_data save;
27882765

2789-
if(!cf->next || !cf->next->cft->is_alive(cf->next, data, input_pending))
2790-
goto out;
2791-
2792-
alive = TRUE;
2793-
if(*input_pending) {
2794-
CURLcode result;
2795-
/* This happens before we have sent off a request and the connection is
2796-
not in use by any other transfer, there should not be any data here,
2797-
only "protocol frames" */
2798-
*input_pending = FALSE;
2799-
result = cf_progress_ingress(cf, data, NULL);
2800-
CURL_TRC_CF(data, cf, "is_alive, progress ingress -> %d", result);
2801-
alive = result ? FALSE : TRUE;
2802-
}
2766+
CF_DATA_SAVE(save, cf, data);
2767+
*input_pending = FALSE;
2768+
if(!ctx->qconn || ctx->shutdown_started)
2769+
goto out;
2770+
2771+
/* We do not announce a max idle timeout, but when the peer does
2772+
* it will close the connection when it expires. */
2773+
rp = ngtcp2_conn_get_remote_transport_params(ctx->qconn);
2774+
if(rp && rp->max_idle_timeout) {
2775+
timediff_t idletime_ms = curlx_timediff_ms(curlx_now(), ctx->q.last_io);
2776+
if(idletime_ms > 0) {
2777+
uint64_t max_idle_ms =
2778+
(uint64_t)(rp->max_idle_timeout / NGTCP2_MILLISECONDS);
2779+
if((uint64_t)idletime_ms > max_idle_ms)
2780+
goto out;
2781+
}
2782+
}
2783+
2784+
if(!cf->next || !cf->next->cft->is_alive(cf->next, data, input_pending))
2785+
goto out;
2786+
2787+
alive = TRUE;
2788+
if(*input_pending) {
2789+
CURLcode result;
2790+
/* This happens before we have sent off a request and the connection is
2791+
not in use by any other transfer, there should not be any data here,
2792+
only "protocol frames" */
2793+
*input_pending = FALSE;
2794+
result = cf_progress_ingress(cf, data, NULL);
2795+
CURL_TRC_CF(data, cf, "is_alive, progress ingress -> %d", result);
2796+
alive = result ? FALSE : TRUE;
2797+
}
28032798

28042799
out:
2805-
CF_DATA_RESTORE(cf, save);
2800+
CF_DATA_RESTORE(cf, save);
28062801
return alive;
28072802
}
28082803

0 commit comments

Comments
 (0)