diff options
author | Daniel Stenberg <daniel@haxx.se> | 2021-01-08 17:58:15 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-01-17 23:56:09 +0100 |
commit | 215db086e09665ee7af9b646ad6c4d6e281001ac (patch) | |
tree | 50c74f8456df87e86de6d72e90190a3563083a1a /lib/vquic | |
parent | 0d26ab9ed3ac29da2a383d313e93df3e9f5295a2 (diff) | |
download | curl-215db086e09665ee7af9b646ad6c4d6e281001ac.tar.gz |
lib: pass in 'struct Curl_easy *' to most functions
... in most cases instead of 'struct connectdata *' but in some cases in
addition to.
- We mostly operate on transfers and not connections.
- We need the transfer handle to log, store data and more. Everything in
libcurl is driven by a transfer (the CURL * in the public API).
- This work clarifies and separates the transfers from the connections
better.
- We should avoid "conn->data". Since individual connections can be used
by many transfers when multiplexing, making sure that conn->data
points to the current and correct transfer at all times is difficult
and has been notoriously error-prone over the years. The goal is to
ultimately remove the conn->data pointer for this reason.
Closes #6425
Diffstat (limited to 'lib/vquic')
-rw-r--r-- | lib/vquic/ngtcp2.c | 83 | ||||
-rw-r--r-- | lib/vquic/quiche.c | 40 |
2 files changed, 61 insertions, 62 deletions
diff --git a/lib/vquic/ngtcp2.c b/lib/vquic/ngtcp2.c index 3b401ef15..e1882dafc 100644 --- a/lib/vquic/ngtcp2.c +++ b/lib/vquic/ngtcp2.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -90,7 +90,7 @@ struct h3out { static CURLcode ng_process_ingress(struct connectdata *conn, curl_socket_t sockfd, struct quicsocket *qs); -static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, +static CURLcode ng_flush_egress(struct Curl_easy *data, int sockfd, struct quicsocket *qs); static int cb_h3_acked_stream_data(nghttp3_conn *conn, int64_t stream_id, size_t datalen, void *user_data, @@ -843,9 +843,10 @@ int Curl_quic_ver(char *p, size_t len) ng2->version_str, ht3->version_str); } -static int ng_getsock(struct connectdata *conn, curl_socket_t *socks) +static int ng_getsock(struct Curl_easy *data, struct connectdata *conn, + curl_socket_t *socks) { - struct SingleRequest *k = &conn->data->req; + struct SingleRequest *k = &data->req; int bitmap = GETSOCK_BLANK; socks[0] = conn->sock[FIRSTSOCKET]; @@ -861,12 +862,6 @@ static int ng_getsock(struct connectdata *conn, curl_socket_t *socks) return bitmap; } -static int ng_perform_getsock(const struct connectdata *conn, - curl_socket_t *socks) -{ - return ng_getsock((struct connectdata *)conn, socks); -} - static void qs_disconnect(struct quicsocket *qs) { int i; @@ -904,18 +899,22 @@ void Curl_quic_disconnect(struct connectdata *conn, qs_disconnect(&conn->hequic[tempindex]); } -static CURLcode ng_disconnect(struct connectdata *conn, +static CURLcode ng_disconnect(struct Curl_easy *data, + struct connectdata *conn, bool dead_connection) { (void)dead_connection; + (void)data; Curl_quic_disconnect(conn, 0); Curl_quic_disconnect(conn, 1); return CURLE_OK; } -static unsigned int ng_conncheck(struct connectdata *conn, +static unsigned int ng_conncheck(struct Curl_easy *data, + struct connectdata *conn, unsigned int checks_to_perform) { + (void)data; (void)conn; (void)checks_to_perform; return CONNRESULT_NONE; @@ -933,7 +932,7 @@ static const struct Curl_handler Curl_handler_http3 = { ng_getsock, /* proto_getsock */ ng_getsock, /* doing_getsock */ ZERO_NULL, /* domore_getsock */ - ng_perform_getsock, /* perform_getsock */ + ng_getsock, /* perform_getsock */ ng_disconnect, /* disconnect */ ZERO_NULL, /* readwrite */ ng_conncheck, /* connection_check */ @@ -1235,14 +1234,15 @@ static size_t drain_overflow_buffer(struct HTTP *stream) } /* incoming data frames on the h3 stream */ -static ssize_t ngh3_stream_recv(struct connectdata *conn, +static ssize_t ngh3_stream_recv(struct Curl_easy *data, int sockindex, char *buf, size_t buffersize, CURLcode *curlcode) { + struct connectdata *conn = data->conn; curl_socket_t sockfd = conn->sock[sockindex]; - struct HTTP *stream = conn->data->req.p.http; + struct HTTP *stream = data->req.p.http; struct quicsocket *qs = conn->quic; if(!stream->memlen) { @@ -1261,7 +1261,7 @@ static ssize_t ngh3_stream_recv(struct connectdata *conn, *curlcode = CURLE_RECV_ERROR; return -1; } - if(ng_flush_egress(conn, sockfd, qs)) { + if(ng_flush_egress(data, sockfd, qs)) { *curlcode = CURLE_SEND_ERROR; return -1; } @@ -1277,7 +1277,7 @@ static ssize_t ngh3_stream_recv(struct connectdata *conn, /* extend the stream window with the data we're consuming and send out any additional packets to tell the server that we can receive more */ extend_stream_window(qs->qconn, stream); - if(ng_flush_egress(conn, sockfd, qs)) { + if(ng_flush_egress(data, sockfd, qs)) { *curlcode = CURLE_SEND_ERROR; return -1; } @@ -1289,7 +1289,7 @@ static ssize_t ngh3_stream_recv(struct connectdata *conn, return 0; } - infof(conn->data, "ngh3_stream_recv returns 0 bytes and EAGAIN\n"); + infof(data, "ngh3_stream_recv returns 0 bytes and EAGAIN\n"); *curlcode = CURLE_AGAIN; return -1; } @@ -1382,10 +1382,11 @@ static ssize_t cb_h3_readfunction(nghttp3_conn *conn, int64_t stream_id, field list. */ #define AUTHORITY_DST_IDX 3 -static CURLcode http_request(struct connectdata *conn, const void *mem, +static CURLcode http_request(struct Curl_easy *data, const void *mem, size_t len) { - struct HTTP *stream = conn->data->req.p.http; + struct connectdata *conn = data->conn; + struct HTTP *stream = data->req.p.http; size_t nheader; size_t i; size_t authority_idx; @@ -1393,7 +1394,6 @@ static CURLcode http_request(struct connectdata *conn, const void *mem, char *end, *line_end; struct quicsocket *qs = conn->quic; CURLcode result = CURLE_OK; - struct Curl_easy *data = conn->data; nghttp3_nv *nva = NULL; int64_t stream3_id; int rc; @@ -1401,7 +1401,7 @@ static CURLcode http_request(struct connectdata *conn, const void *mem, rc = ngtcp2_conn_open_bidi_stream(qs->qconn, &stream3_id, NULL); if(rc) { - failf(conn->data, "can get bidi streams"); + failf(data, "can get bidi streams"); result = CURLE_SEND_ERROR; goto fail; } @@ -1587,8 +1587,7 @@ static CURLcode http_request(struct connectdata *conn, const void *mem, stream->h3out = h3out; rc = nghttp3_conn_submit_request(qs->h3conn, stream->stream3_id, - nva, nheader, &data_reader, - conn->data); + nva, nheader, &data_reader, data); if(rc) { result = CURLE_SEND_ERROR; goto fail; @@ -1598,9 +1597,7 @@ static CURLcode http_request(struct connectdata *conn, const void *mem, default: stream->upload_left = 0; /* nothing left to send */ rc = nghttp3_conn_submit_request(qs->h3conn, stream->stream3_id, - nva, nheader, - NULL, /* no body! */ - conn->data); + nva, nheader, NULL, data); if(rc) { result = CURLE_SEND_ERROR; goto fail; @@ -1619,19 +1616,20 @@ fail: free(nva); return result; } -static ssize_t ngh3_stream_send(struct connectdata *conn, +static ssize_t ngh3_stream_send(struct Curl_easy *data, int sockindex, const void *mem, size_t len, CURLcode *curlcode) { ssize_t sent; + struct connectdata *conn = data->conn; struct quicsocket *qs = conn->quic; curl_socket_t sockfd = conn->sock[sockindex]; - struct HTTP *stream = conn->data->req.p.http; + struct HTTP *stream = data->req.p.http; if(!stream->h3req) { - CURLcode result = http_request(conn, mem, len); + CURLcode result = http_request(data, mem, len); if(result) { *curlcode = CURLE_SEND_ERROR; return -1; @@ -1639,7 +1637,7 @@ static ssize_t ngh3_stream_send(struct connectdata *conn, sent = len; } else { - H3BUGF(infof(conn->data, "ngh3_stream_send() wants to send %zd bytes\n", + H3BUGF(infof(data, "ngh3_stream_send() wants to send %zd bytes\n", len)); if(!stream->upload_len) { stream->upload_mem = mem; @@ -1653,7 +1651,7 @@ static ssize_t ngh3_stream_send(struct connectdata *conn, } } - if(ng_flush_egress(conn, sockfd, qs)) { + if(ng_flush_egress(data, sockfd, qs)) { *curlcode = CURLE_SEND_ERROR; return -1; } @@ -1689,7 +1687,7 @@ CURLcode Curl_quic_is_connected(struct connectdata *conn, if(result) goto error; - result = ng_flush_egress(conn, sockfd, qs); + result = ng_flush_egress(conn->data, sockfd, qs); if(result) goto error; @@ -1749,7 +1747,8 @@ static CURLcode ng_process_ingress(struct connectdata *conn, return CURLE_OK; } -static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, +static CURLcode ng_flush_egress(struct Curl_easy *data, + int sockfd, struct quicsocket *qs) { int rv; @@ -1783,7 +1782,7 @@ static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, rv = ngtcp2_conn_handle_expiry(qs->qconn, ts); if(rv != 0) { - failf(conn->data, "ngtcp2_conn_handle_expiry returned error: %s", + failf(data, "ngtcp2_conn_handle_expiry returned error: %s", ngtcp2_strerror(rv)); return CURLE_SEND_ERROR; } @@ -1796,7 +1795,7 @@ static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, veccnt = nghttp3_conn_writev_stream(qs->h3conn, &stream_id, &fin, vec, sizeof(vec) / sizeof(vec[0])); if(veccnt < 0) { - failf(conn->data, "nghttp3_conn_writev_stream returned error: %s", + failf(data, "nghttp3_conn_writev_stream returned error: %s", nghttp3_strerror((int)veccnt)); return CURLE_SEND_ERROR; } @@ -1817,7 +1816,7 @@ static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, assert(ndatalen == -1); rv = nghttp3_conn_block_stream(qs->h3conn, stream_id); if(rv != 0) { - failf(conn->data, + failf(data, "nghttp3_conn_block_stream returned error: %s\n", nghttp3_strerror(rv)); return CURLE_SEND_ERROR; @@ -1829,7 +1828,7 @@ static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, rv = nghttp3_conn_add_write_offset(qs->h3conn, stream_id, ndatalen); if(rv != 0) { - failf(conn->data, + failf(data, "nghttp3_conn_add_write_offset returned error: %s\n", nghttp3_strerror(rv)); return CURLE_SEND_ERROR; @@ -1838,7 +1837,7 @@ static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, } else { assert(ndatalen == -1); - failf(conn->data, "ngtcp2_conn_writev_stream returned error: %s", + failf(data, "ngtcp2_conn_writev_stream returned error: %s", ngtcp2_strerror((int)outlen)); return CURLE_SEND_ERROR; } @@ -1852,7 +1851,7 @@ static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, outlen = ngtcp2_conn_write_pkt(qs->qconn, &ps.path, NULL, out, pktlen, ts); if(outlen < 0) { - failf(conn->data, "ngtcp2_conn_write_pkt returned error: %s", + failf(data, "ngtcp2_conn_write_pkt returned error: %s", ngtcp2_strerror((int)outlen)); return CURLE_SEND_ERROR; } @@ -1871,7 +1870,7 @@ static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, break; } else { - failf(conn->data, "send() returned %zd (errno %d)", sent, + failf(data, "send() returned %zd (errno %d)", sent, SOCKERRNO); return CURLE_SEND_ERROR; } @@ -1886,7 +1885,7 @@ static CURLcode ng_flush_egress(struct connectdata *conn, int sockfd, else { timeout = expiry - ts; } - Curl_expire(conn->data, timeout / NGTCP2_MILLISECONDS, EXPIRE_QUIC); + Curl_expire(data, timeout / NGTCP2_MILLISECONDS, EXPIRE_QUIC); } return CURLE_OK; diff --git a/lib/vquic/quiche.c b/lib/vquic/quiche.c index a66b66447..5601428e9 100644 --- a/lib/vquic/quiche.c +++ b/lib/vquic/quiche.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -65,9 +65,10 @@ static CURLcode http_request(struct connectdata *conn, const void *mem, static Curl_recv h3_stream_recv; static Curl_send h3_stream_send; -static int quiche_getsock(struct connectdata *conn, curl_socket_t *socks) +static int quiche_getsock(struct Curl_easy *data, + struct connectdata *conn, curl_socket_t *socks) { - struct SingleRequest *k = &conn->data->req; + struct SingleRequest *k = &data->req; int bitmap = GETSOCK_BLANK; socks[0] = conn->sock[FIRSTSOCKET]; @@ -83,12 +84,6 @@ static int quiche_getsock(struct connectdata *conn, curl_socket_t *socks) return bitmap; } -static int quiche_perform_getsock(const struct connectdata *conn, - curl_socket_t *socks) -{ - return quiche_getsock((struct connectdata *)conn, socks); -} - static CURLcode qs_disconnect(struct connectdata *conn, struct quicsocket *qs) { @@ -111,10 +106,12 @@ static CURLcode qs_disconnect(struct connectdata *conn, return CURLE_OK; } -static CURLcode quiche_disconnect(struct connectdata *conn, +static CURLcode quiche_disconnect(struct Curl_easy *data, + struct connectdata *conn, bool dead_connection) { struct quicsocket *qs = conn->quic; + (void)data; (void)dead_connection; return qs_disconnect(conn, qs); } @@ -126,19 +123,21 @@ void Curl_quic_disconnect(struct connectdata *conn, qs_disconnect(conn, &conn->hequic[tempindex]); } -static unsigned int quiche_conncheck(struct connectdata *conn, +static unsigned int quiche_conncheck(struct Curl_easy *data, + struct connectdata *conn, unsigned int checks_to_perform) { + (void)data; (void)conn; (void)checks_to_perform; return CONNRESULT_NONE; } -static CURLcode quiche_do(struct connectdata *conn, bool *done) +static CURLcode quiche_do(struct Curl_easy *data, bool *done) { - struct HTTP *stream = conn->data->req.p.http; + struct HTTP *stream = data->req.p.http; stream->h3req = FALSE; /* not sent */ - return Curl_http(conn, done); + return Curl_http(data, done); } static const struct Curl_handler Curl_handler_http3 = { @@ -153,7 +152,7 @@ static const struct Curl_handler Curl_handler_http3 = { quiche_getsock, /* proto_getsock */ quiche_getsock, /* doing_getsock */ ZERO_NULL, /* domore_getsock */ - quiche_perform_getsock, /* perform_getsock */ + quiche_getsock, /* perform_getsock */ quiche_disconnect, /* disconnect */ ZERO_NULL, /* readwrite */ quiche_conncheck, /* connection_check */ @@ -256,7 +255,7 @@ CURLcode Curl_quic_connect(struct connectdata *conn, curl_socket_t sockfd, return CURLE_BAD_FUNCTION_ARGUMENT; } memcpy(conn->ip_addr_str, conn->primary_ip, MAX_IPADR_LEN); - Curl_persistconninfo(conn); + Curl_persistconninfo(data, conn); /* for connection reuse purposes: */ conn->ssl[FIRSTSOCKET].state = ssl_connection_complete; @@ -453,7 +452,7 @@ static int cb_each_header(uint8_t *name, size_t name_len, return 0; } -static ssize_t h3_stream_recv(struct connectdata *conn, +static ssize_t h3_stream_recv(struct Curl_easy *data, int sockindex, char *buf, size_t buffersize, @@ -461,12 +460,12 @@ static ssize_t h3_stream_recv(struct connectdata *conn, { ssize_t recvd = -1; ssize_t rcode; + struct connectdata *conn = data->conn; struct quicsocket *qs = conn->quic; curl_socket_t sockfd = conn->sock[sockindex]; quiche_h3_event *ev; int rc; struct h3h1header headers; - struct Curl_easy *data = conn->data; struct HTTP *stream = data->req.p.http; headers.dest = buf; headers.destlen = buffersize; @@ -546,16 +545,17 @@ static ssize_t h3_stream_recv(struct connectdata *conn, return recvd; } -static ssize_t h3_stream_send(struct connectdata *conn, +static ssize_t h3_stream_send(struct Curl_easy *data, int sockindex, const void *mem, size_t len, CURLcode *curlcode) { ssize_t sent; + struct connectdata *conn = data->conn; struct quicsocket *qs = conn->quic; curl_socket_t sockfd = conn->sock[sockindex]; - struct HTTP *stream = conn->data->req.p.http; + struct HTTP *stream = data->req.p.http; if(!stream->h3req) { CURLcode result = http_request(conn, mem, len); |