summaryrefslogtreecommitdiff
path: root/lib/easy.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-01-08 17:58:15 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-01-17 23:56:09 +0100
commit215db086e09665ee7af9b646ad6c4d6e281001ac (patch)
tree50c74f8456df87e86de6d72e90190a3563083a1a /lib/easy.c
parent0d26ab9ed3ac29da2a383d313e93df3e9f5295a2 (diff)
downloadcurl-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/easy.c')
-rw-r--r--lib/easy.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/easy.c b/lib/easy.c
index 04e59144b..3b72ce7a4 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -1072,7 +1072,7 @@ CURLcode curl_easy_pause(struct Curl_easy *data, int action)
/* even if one function returns error, this loops through and frees
all buffers */
if(!result)
- result = Curl_client_write(conn, writebuf[i].type,
+ result = Curl_client_write(data, writebuf[i].type,
Curl_dyn_ptr(&writebuf[i].b),
Curl_dyn_len(&writebuf[i].b));
Curl_dyn_free(&writebuf[i].b);
@@ -1156,8 +1156,13 @@ CURLcode curl_easy_recv(struct Curl_easy *data, void *buffer, size_t buflen,
if(result)
return result;
+ if(!data->conn)
+ /* on first invoke, the transfer has been detached from the connection and
+ needs to be reattached */
+ Curl_attach_connnection(data, c);
+
*n = 0;
- result = Curl_read(c, sfd, buffer, buflen, &n1);
+ result = Curl_read(data, sfd, buffer, buflen, &n1);
if(result)
return result;
@@ -1186,8 +1191,13 @@ CURLcode curl_easy_send(struct Curl_easy *data, const void *buffer,
if(result)
return result;
+ if(!data->conn)
+ /* on first invoke, the transfer has been detached from the connection and
+ needs to be reattached */
+ Curl_attach_connnection(data, c);
+
*n = 0;
- result = Curl_write(c, sfd, buffer, buflen, &n1);
+ result = Curl_write(data, sfd, buffer, buflen, &n1);
if(n1 == -1)
return CURLE_SEND_ERROR;
@@ -1206,16 +1216,16 @@ CURLcode curl_easy_send(struct Curl_easy *data, const void *buffer,
*
* Returns always 0.
*/
-static int conn_upkeep(struct connectdata *conn,
+static int conn_upkeep(struct Curl_easy *data,
+ struct connectdata *conn,
void *param)
{
/* Param is unused. */
(void)param;
- if(conn->handler->connection_check) {
+ if(conn->handler->connection_check)
/* Do a protocol-specific keepalive check on the connection. */
- conn->handler->connection_check(conn, CONNCHECK_KEEPALIVE);
- }
+ conn->handler->connection_check(data, conn, CONNCHECK_KEEPALIVE);
return 0; /* continue iteration */
}