lib: replace conn [write]sockfd members by index

The `connectdata` members `sockfd` and `writesockfd` needed to by either
CURL_SOCKET_BAD or a copy of one of `conn->sock[2]`. When equal to one,
that index was used to send/recv/poll the proper socket or connection
filter chain.

Replace those with `send_idx` and `recv_idx` which are either -1, 0 or 1
to indicate which socket/filter to send/receive on.

Closes #18179
This commit is contained in:
Stefan Eissing 2025-08-05 13:11:53 +02:00 committed by Daniel Stenberg
parent aec28f3ad3
commit 6d5570c4dd
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
9 changed files with 120 additions and 92 deletions

View file

@ -1115,8 +1115,8 @@ static int myssh_in_AUTH_DONE(struct Curl_easy *data,
/* At this point we have an authenticated ssh session. */
infof(data, "Authentication complete");
Curl_pgrsTime(data, TIMER_APPCONNECT); /* SSH is connected */
data->conn->sockfd = data->conn->sock[FIRSTSOCKET];
data->conn->writesockfd = CURL_SOCKET_BAD;
data->conn->recv_idx = FIRSTSOCKET;
data->conn->send_idx = -1;
if(data->conn->handler->protocol == CURLPROTO_SFTP) {
myssh_to(data, sshc, SSH_SFTP_INIT);
@ -1254,7 +1254,7 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
data->conn->sockfd = data->conn->writesockfd;
data->conn->recv_idx = FIRSTSOCKET;
/* store this original bitmask setup to use later on if we cannot
figure out a "real" bitmask */
@ -1426,7 +1426,7 @@ static int myssh_in_SFTP_DOWNLOAD_STAT(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_RECV, data->req.size, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
data->conn->writesockfd = data->conn->sockfd;
data->conn->send_idx = 0;
sshc->sftp_recv_state = 0;
myssh_to(data, sshc, SSH_STOP);
@ -2243,7 +2243,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
conn->sockfd = conn->writesockfd;
data->conn->recv_idx = FIRSTSOCKET;
/* store this original bitmask setup to use later on if we cannot
figure out a "real" bitmask */
@ -2282,7 +2282,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_RECV, bytecount, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
conn->writesockfd = conn->sockfd;
conn->send_idx = 0;
myssh_to(data, sshc, SSH_STOP);
break;

View file

@ -1202,7 +1202,7 @@ sftp_upload_init(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
data->conn->sockfd = data->conn->writesockfd;
data->conn->recv_idx = FIRSTSOCKET;
/* store this original bitmask setup to use later on if we cannot
figure out a "real" bitmask */
@ -1543,7 +1543,7 @@ sftp_download_stat(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_RECV, data->req.size, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
data->conn->writesockfd = data->conn->sockfd;
data->conn->send_idx = 0;
myssh_state(data, sshc, SSH_STOP);
@ -1945,8 +1945,8 @@ static CURLcode ssh_state_auth_done(struct Curl_easy *data,
Curl_pgrsTime(data, TIMER_APPCONNECT); /* SSH is connected */
conn->sockfd = conn->sock[FIRSTSOCKET];
conn->writesockfd = CURL_SOCKET_BAD;
data->conn->recv_idx = FIRSTSOCKET;
conn->send_idx = -1;
if(conn->handler->protocol == CURLPROTO_SFTP) {
myssh_state(data, sshc, SSH_SFTP_INIT);
@ -2463,7 +2463,7 @@ static CURLcode ssh_state_scp_download_init(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_RECV, bytecount, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
data->conn->writesockfd = data->conn->sockfd;
data->conn->send_idx = 0;
myssh_state(data, sshc, SSH_STOP);
return CURLE_OK;
@ -2612,7 +2612,7 @@ static CURLcode ssh_state_scp_upload_init(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
data->conn->sockfd = data->conn->writesockfd;
data->conn->recv_idx = FIRSTSOCKET;
/* store this original bitmask setup to use later on if we cannot
figure out a "real" bitmask */

View file

@ -720,7 +720,7 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
conn->sockfd = conn->writesockfd;
data->conn->recv_idx = FIRSTSOCKET;
if(result) {
wssh_state(data, sshc, SSH_SFTP_CLOSE);
@ -819,7 +819,7 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data,
Curl_xfer_setup1(data, CURL_XFER_RECV, data->req.size, FALSE);
/* not set by Curl_xfer_setup to preserve keepon bits */
conn->writesockfd = conn->sockfd;
conn->send_idx = 0;
if(result) {
/* this should never occur; the close state should be entered