Skip to content

Commit

Permalink
lib: pass in 'struct Curl_easy *' to most functions
Browse files Browse the repository at this point in the history
... 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
  • Loading branch information
bagder committed Jan 17, 2021
1 parent 0d26ab9 commit 215db08
Show file tree
Hide file tree
Showing 76 changed files with 2,849 additions and 2,585 deletions.
2 changes: 1 addition & 1 deletion lib/asyn-ares.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
res->last_status = ARES_ENOTFOUND;
#ifdef ENABLE_IPV6
if(family == PF_UNSPEC) {
if(Curl_ipv6works(conn)) {
if(Curl_ipv6works(data)) {
res->num_pending = 2;

/* areschannel is already setup in the Curl_open() function */
Expand Down
4 changes: 2 additions & 2 deletions lib/asyn-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -749,7 +749,7 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
break;
}

if((pf != PF_INET) && !Curl_ipv6works(conn))
if((pf != PF_INET) && !Curl_ipv6works(data))
/* The stack seems to be a non-IPv6 one */
pf = PF_INET;
#endif /* CURLRES_IPV6 */
Expand Down
26 changes: 13 additions & 13 deletions lib/c-hyper.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ size_t Curl_hyper_recv(void *userp, hyper_context *ctx,

(void)ctx;

result = Curl_read(conn, conn->sockfd, (char *)buf, buflen, &nread);
result = Curl_read(data, conn->sockfd, (char *)buf, buflen, &nread);
if(result == CURLE_AGAIN) {
/* would block, register interest */
if(data->hyp.read_waker)
Expand All @@ -94,7 +94,7 @@ size_t Curl_hyper_send(void *userp, hyper_context *ctx,
CURLcode result;
ssize_t nwrote;

result = Curl_write(conn, conn->sockfd, (void *)buf, buflen, &nwrote);
result = Curl_write(data, conn->sockfd, (void *)buf, buflen, &nwrote);
if(result == CURLE_AGAIN) {
/* would block, register interest */
if(data->hyp.write_waker)
Expand Down Expand Up @@ -380,7 +380,7 @@ CURLcode Curl_hyper_stream(struct Curl_easy *data,
/* Curl_http_auth_act() checks what authentication methods that are
* available and decides which one (if any) to use. It will set 'newurl'
* if an auth method was picked. */
result = Curl_http_auth_act(conn);
result = Curl_http_auth_act(data);
if(result)
break;

Expand Down Expand Up @@ -628,9 +628,9 @@ static CURLcode cookies(struct Curl_easy *data,
* request is to be performed. This creates and sends a properly constructed
* HTTP request.
*/
CURLcode Curl_http(struct connectdata *conn, bool *done)
CURLcode Curl_http(struct Curl_easy *data, bool *done)
{
struct Curl_easy *data = conn->data;
struct connectdata *conn = data->conn;
struct hyptransfer *h = &data->hyp;
hyper_io *io = NULL;
hyper_clientconn_options *options = NULL;
Expand Down Expand Up @@ -670,7 +670,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
if(!pq)
return CURLE_OUT_OF_MEMORY;
}
result = Curl_http_output_auth(conn, method, httpreq,
result = Curl_http_output_auth(data, conn, method, httpreq,
(pq ? pq : data->state.up.path), FALSE);
free(pq);
if(result)
Expand All @@ -681,11 +681,11 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
if(result)
return result;

result = Curl_http_range(data, conn, httpreq);
result = Curl_http_range(data, httpreq);
if(result)
return result;

result = Curl_http_useragent(data, conn);
result = Curl_http_useragent(data);
if(result)
return result;

Expand Down Expand Up @@ -799,7 +799,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
Curl_hyper_header(data, headers, data->state.aptr.uagent))
goto error;

p_accept = Curl_checkheaders(conn, "Accept")?NULL:"Accept: */*\r\n";
p_accept = Curl_checkheaders(data, "Accept")?NULL:"Accept: */*\r\n";
if(p_accept && Curl_hyper_header(data, headers, p_accept))
goto error;

Expand All @@ -808,14 +808,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)

#ifndef CURL_DISABLE_PROXY
if(conn->bits.httpproxy && !conn->bits.tunnel_proxy &&
!Curl_checkProxyheaders(conn, "Proxy-Connection")) {
!Curl_checkProxyheaders(data, conn, "Proxy-Connection")) {
if(Curl_hyper_header(data, headers, "Proxy-Connection: Keep-Alive"))
goto error;
}
#endif

Curl_safefree(data->state.aptr.ref);
if(data->change.referer && !Curl_checkheaders(conn, "Referer")) {
if(data->change.referer && !Curl_checkheaders(data, "Referer")) {
data->state.aptr.ref = aprintf("Referer: %s\r\n", data->change.referer);
if(!data->state.aptr.ref)
return CURLE_OUT_OF_MEMORY;
Expand All @@ -827,11 +827,11 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
if(result)
return result;

result = Curl_add_timecondition(conn, headers);
result = Curl_add_timecondition(data, headers);
if(result)
return result;

result = Curl_add_custom_headers(conn, FALSE, headers);
result = Curl_add_custom_headers(data, FALSE, headers);
if(result)
return result;

Expand Down
7 changes: 4 additions & 3 deletions lib/conncache.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2012 - 2016, Linus Nielsen Feltzing, <linus@haxx.se>
* Copyright (C) 2012 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2012 - 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
Expand Down Expand Up @@ -318,7 +318,8 @@ void Curl_conncache_remove_conn(struct Curl_easy *data,
bool Curl_conncache_foreach(struct Curl_easy *data,
struct conncache *connc,
void *param,
int (*func)(struct connectdata *conn, void *param))
int (*func)(struct Curl_easy *data,
struct connectdata *conn, void *param))
{
struct Curl_hash_iterator iter;
struct Curl_llist_element *curr;
Expand All @@ -344,7 +345,7 @@ bool Curl_conncache_foreach(struct Curl_easy *data,
struct connectdata *conn = curr->ptr;
curr = curr->next;

if(1 == func(conn, param)) {
if(1 == func(data, conn, param)) {
CONNCACHE_UNLOCK(data);
return TRUE;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/conncache.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2015 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2015 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2012 - 2014, Linus Nielsen Feltzing, <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
Expand Down Expand Up @@ -101,7 +101,8 @@ void Curl_conncache_remove_conn(struct Curl_easy *data,
bool Curl_conncache_foreach(struct Curl_easy *data,
struct conncache *connc,
void *param,
int (*func)(struct connectdata *conn,
int (*func)(struct Curl_easy *data,
struct connectdata *conn,
void *param));

struct connectdata *
Expand Down
Loading

0 comments on commit 215db08

Please sign in to comment.