summaryrefslogtreecommitdiff
path: root/lib/pingpong.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/pingpong.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/pingpong.c')
-rw-r--r--lib/pingpong.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/lib/pingpong.c b/lib/pingpong.c
index 5d6109a7d..8ff394866 100644
--- a/lib/pingpong.c
+++ b/lib/pingpong.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
@@ -44,10 +44,10 @@
/* Returns timeout in ms. 0 or negative number means the timeout has already
triggered */
-timediff_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting)
+timediff_t Curl_pp_state_timeout(struct Curl_easy *data,
+ struct pingpong *pp, bool disconnecting)
{
struct connectdata *conn = pp->conn;
- struct Curl_easy *data = conn->data;
timediff_t timeout_ms; /* in milliseconds */
timediff_t response_time = (data->set.server_response_timeout)?
data->set.server_response_timeout: pp->response_time;
@@ -77,15 +77,15 @@ timediff_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting)
/*
* Curl_pp_statemach()
*/
-CURLcode Curl_pp_statemach(struct pingpong *pp, bool block,
+CURLcode Curl_pp_statemach(struct Curl_easy *data,
+ struct pingpong *pp, bool block,
bool disconnecting)
{
struct connectdata *conn = pp->conn;
curl_socket_t sock = conn->sock[FIRSTSOCKET];
int rc;
timediff_t interval_ms;
- timediff_t timeout_ms = Curl_pp_state_timeout(pp, disconnecting);
- struct Curl_easy *data = conn->data;
+ timediff_t timeout_ms = Curl_pp_state_timeout(data, pp, disconnecting);
CURLcode result = CURLE_OK;
if(timeout_ms <= 0) {
@@ -131,17 +131,17 @@ CURLcode Curl_pp_statemach(struct pingpong *pp, bool block,
result = CURLE_OUT_OF_MEMORY;
}
else if(rc)
- result = pp->statemach_act(conn);
+ result = pp->statemachine(data, pp->conn);
return result;
}
/* initialize stuff to prepare for reading a fresh new response */
-void Curl_pp_init(struct pingpong *pp)
+void Curl_pp_init(struct Curl_easy *data, struct pingpong *pp)
{
- struct connectdata *conn = pp->conn;
+ DEBUGASSERT(data);
pp->nread_resp = 0;
- pp->linestart_resp = conn->data->state.buffer;
+ pp->linestart_resp = data->state.buffer;
pp->pending_resp = TRUE;
pp->response = Curl_now(); /* start response time-out now! */
}
@@ -162,7 +162,8 @@ void Curl_pp_setup(struct pingpong *pp)
*
* made to never block
*/
-CURLcode Curl_pp_vsendf(struct pingpong *pp,
+CURLcode Curl_pp_vsendf(struct Curl_easy *data,
+ struct pingpong *pp,
const char *fmt,
va_list args)
{
@@ -171,7 +172,6 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
char *s;
CURLcode result;
struct connectdata *conn = pp->conn;
- struct Curl_easy *data;
#ifdef HAVE_GSSAPI
enum protection_level data_sec;
@@ -184,7 +184,6 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
if(!conn)
/* can't send without a connection! */
return CURLE_SEND_ERROR;
- data = conn->data;
Curl_dyn_reset(&pp->sendbuf);
result = Curl_dyn_vaddf(&pp->sendbuf, fmt, args);
@@ -198,7 +197,7 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
write_len = Curl_dyn_len(&pp->sendbuf);
s = Curl_dyn_ptr(&pp->sendbuf);
- Curl_pp_init(pp);
+ Curl_pp_init(data, pp);
result = Curl_convert_to_network(data, s, write_len);
/* Curl_convert_to_network calls failf if unsuccessful */
@@ -208,7 +207,7 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
#ifdef HAVE_GSSAPI
conn->data_prot = PROT_CMD;
#endif
- result = Curl_write(conn, conn->sock[FIRSTSOCKET], s, write_len,
+ result = Curl_write(data, conn->sock[FIRSTSOCKET], s, write_len,
&bytes_written);
if(result)
return result;
@@ -246,14 +245,14 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
*
* made to never block
*/
-CURLcode Curl_pp_sendf(struct pingpong *pp,
+CURLcode Curl_pp_sendf(struct Curl_easy *data, struct pingpong *pp,
const char *fmt, ...)
{
CURLcode result;
va_list ap;
va_start(ap, fmt);
- result = Curl_pp_vsendf(pp, fmt, ap);
+ result = Curl_pp_vsendf(data, pp, fmt, ap);
va_end(ap);
@@ -265,7 +264,8 @@ CURLcode Curl_pp_sendf(struct pingpong *pp,
*
* Reads a piece of a server response.
*/
-CURLcode Curl_pp_readresp(curl_socket_t sockfd,
+CURLcode Curl_pp_readresp(struct Curl_easy *data,
+ curl_socket_t sockfd,
struct pingpong *pp,
int *code, /* return the server code if done */
size_t *size) /* size of the response */
@@ -275,7 +275,6 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
ssize_t gotbytes;
char *ptr;
struct connectdata *conn = pp->conn;
- struct Curl_easy *data = conn->data;
char * const buf = data->state.buffer;
CURLcode result = CURLE_OK;
@@ -315,7 +314,7 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
#endif
DEBUGASSERT((ptr + data->set.buffer_size - pp->nread_resp) <=
(buf + data->set.buffer_size + 1));
- result = Curl_read(conn, sockfd, ptr,
+ result = Curl_read(data, sockfd, ptr,
data->set.buffer_size - pp->nread_resp,
&gotbytes);
#ifdef HAVE_GSSAPI
@@ -371,12 +370,12 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
* for "headers". The response lines can be seen as a kind of
* headers.
*/
- result = Curl_client_write(conn, CLIENTWRITE_HEADER,
+ result = Curl_client_write(data, CLIENTWRITE_HEADER,
pp->linestart_resp, perline);
if(result)
return result;
- if(pp->endofresp(conn, pp->linestart_resp, perline, code)) {
+ if(pp->endofresp(data, conn, pp->linestart_resp, perline, code)) {
/* This is the end of the last line, copy the last line to the
start of the buffer and null-terminate, for old times sake */
size_t n = ptr - pp->linestart_resp;
@@ -456,8 +455,7 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
return result;
}
-int Curl_pp_getsock(struct pingpong *pp,
- curl_socket_t *socks)
+int Curl_pp_getsock(struct pingpong *pp, curl_socket_t *socks)
{
struct connectdata *conn = pp->conn;
socks[0] = conn->sock[FIRSTSOCKET];
@@ -477,7 +475,7 @@ CURLcode Curl_pp_flushsend(struct pingpong *pp)
struct connectdata *conn = pp->conn;
ssize_t written;
curl_socket_t sock = conn->sock[FIRSTSOCKET];
- CURLcode result = Curl_write(conn, sock, pp->sendthis + pp->sendsize -
+ CURLcode result = Curl_write(conn->data, sock, pp->sendthis + pp->sendsize -
pp->sendleft, pp->sendleft, &written);
if(result)
return result;