mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
lib: reduce use of data->conn->
If there are more than two of them in a function, use a local 'conn' variable instead. Closes #19063
This commit is contained in:
parent
9441127394
commit
ae5fb4188d
@ -932,13 +932,14 @@ Curl_conn_get_remote_addr(struct Curl_easy *data, int sockindex)
|
||||
|
||||
void Curl_conn_forget_socket(struct Curl_easy *data, int sockindex)
|
||||
{
|
||||
if(data->conn && CONN_SOCK_IDX_VALID(sockindex)) {
|
||||
struct Curl_cfilter *cf = data->conn->cfilter[sockindex];
|
||||
struct connectdata *conn = data->conn;
|
||||
if(conn && CONN_SOCK_IDX_VALID(sockindex)) {
|
||||
struct Curl_cfilter *cf = conn->cfilter[sockindex];
|
||||
if(cf)
|
||||
(void)Curl_conn_cf_cntrl(cf, data, TRUE,
|
||||
CF_CTRL_FORGET_SOCKET, 0, NULL);
|
||||
fake_sclose(data->conn->sock[sockindex]);
|
||||
data->conn->sock[sockindex] = CURL_SOCKET_BAD;
|
||||
fake_sclose(conn->sock[sockindex]);
|
||||
conn->sock[sockindex] = CURL_SOCKET_BAD;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -158,20 +158,21 @@ void Curl_shutdown_start(struct Curl_easy *data, int sockindex,
|
||||
int timeout_ms, struct curltime *nowp)
|
||||
{
|
||||
struct curltime now;
|
||||
struct connectdata *conn = data->conn;
|
||||
|
||||
DEBUGASSERT(data->conn);
|
||||
DEBUGASSERT(conn);
|
||||
if(!nowp) {
|
||||
now = curlx_now();
|
||||
nowp = &now;
|
||||
}
|
||||
data->conn->shutdown.start[sockindex] = *nowp;
|
||||
data->conn->shutdown.timeout_ms = (timeout_ms > 0) ?
|
||||
conn->shutdown.start[sockindex] = *nowp;
|
||||
conn->shutdown.timeout_ms = (timeout_ms > 0) ?
|
||||
(timediff_t)timeout_ms :
|
||||
((data->set.shutdowntimeout > 0) ?
|
||||
data->set.shutdowntimeout : DEFAULT_SHUTDOWN_TIMEOUT_MS);
|
||||
/* Set a timer, unless we operate on the admin handle */
|
||||
if(data->mid && (data->conn->shutdown.timeout_ms > 0))
|
||||
Curl_expire_ex(data, nowp, data->conn->shutdown.timeout_ms,
|
||||
if(data->mid && (conn->shutdown.timeout_ms > 0))
|
||||
Curl_expire_ex(data, nowp, conn->shutdown.timeout_ms,
|
||||
EXPIRE_SHUTDOWN);
|
||||
}
|
||||
|
||||
|
||||
23
lib/http.c
23
lib/http.c
@ -1977,6 +1977,9 @@ static CURLcode http_target(struct Curl_easy *data,
|
||||
CURLcode result = CURLE_OK;
|
||||
const char *path = data->state.up.path;
|
||||
const char *query = data->state.up.query;
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
struct connectdata *conn = data->conn;
|
||||
#endif
|
||||
|
||||
if(data->set.str[STRING_TARGET]) {
|
||||
path = data->set.str[STRING_TARGET];
|
||||
@ -1984,7 +1987,7 @@ static CURLcode http_target(struct Curl_easy *data,
|
||||
}
|
||||
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
if(data->conn->bits.httpproxy && !data->conn->bits.tunnel_proxy) {
|
||||
if(conn->bits.httpproxy && !conn->bits.tunnel_proxy) {
|
||||
/* Using a proxy but does not tunnel through it */
|
||||
|
||||
/* The path sent to the proxy is in fact the entire URL. But if the remote
|
||||
@ -1998,8 +2001,8 @@ static CURLcode http_target(struct Curl_easy *data,
|
||||
if(!h)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
if(data->conn->host.dispname != data->conn->host.name) {
|
||||
uc = curl_url_set(h, CURLUPART_HOST, data->conn->host.name, 0);
|
||||
if(conn->host.dispname != conn->host.name) {
|
||||
uc = curl_url_set(h, CURLUPART_HOST, conn->host.name, 0);
|
||||
if(uc) {
|
||||
curl_url_cleanup(h);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
@ -2746,6 +2749,7 @@ static CURLcode http_add_hd(struct Curl_easy *data,
|
||||
Curl_HttpReq httpreq)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
struct connectdata *conn = data->conn;
|
||||
switch(id) {
|
||||
case H1_HD_REQUEST:
|
||||
/* add the main request stuff */
|
||||
@ -2818,8 +2822,8 @@ static CURLcode http_add_hd(struct Curl_easy *data,
|
||||
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
case H1_HD_PROXY_CONNECTION:
|
||||
if(data->conn->bits.httpproxy &&
|
||||
!data->conn->bits.tunnel_proxy &&
|
||||
if(conn->bits.httpproxy &&
|
||||
!conn->bits.tunnel_proxy &&
|
||||
!Curl_checkheaders(data, STRCONST("Proxy-Connection")) &&
|
||||
!Curl_checkProxyheaders(data, data->conn, STRCONST("Proxy-Connection")))
|
||||
result = curlx_dyn_add(req, "Proxy-Connection: Keep-Alive\r\n");
|
||||
@ -2832,11 +2836,10 @@ static CURLcode http_add_hd(struct Curl_easy *data,
|
||||
|
||||
#ifndef CURL_DISABLE_ALTSVC
|
||||
case H1_HD_ALT_USED:
|
||||
if(data->conn->bits.altused &&
|
||||
!Curl_checkheaders(data, STRCONST("Alt-Used")))
|
||||
if(conn->bits.altused && !Curl_checkheaders(data, STRCONST("Alt-Used")))
|
||||
result = curlx_dyn_addf(req, "Alt-Used: %s:%d\r\n",
|
||||
data->conn->conn_to_host.name,
|
||||
data->conn->conn_to_port);
|
||||
conn->conn_to_host.name,
|
||||
conn->conn_to_port);
|
||||
break;
|
||||
#endif
|
||||
|
||||
@ -2849,7 +2852,7 @@ static CURLcode http_add_hd(struct Curl_easy *data,
|
||||
result = Curl_http2_request_upgrade(req, data);
|
||||
}
|
||||
#ifndef CURL_DISABLE_WEBSOCKETS
|
||||
if(!result && data->conn->handler->protocol&(CURLPROTO_WS|CURLPROTO_WSS))
|
||||
if(!result && conn->handler->protocol&(CURLPROTO_WS|CURLPROTO_WSS))
|
||||
result = Curl_ws_request(data, req);
|
||||
#endif
|
||||
break;
|
||||
|
||||
46
lib/multi.c
46
lib/multi.c
@ -939,11 +939,12 @@ static CURLcode mstate_connecting_pollset(struct Curl_easy *data,
|
||||
static CURLcode mstate_protocol_pollset(struct Curl_easy *data,
|
||||
struct easy_pollset *ps)
|
||||
{
|
||||
if(data->conn) {
|
||||
struct connectdata *conn = data->conn;
|
||||
if(conn) {
|
||||
curl_socket_t sockfd;
|
||||
if(data->conn->handler->proto_pollset)
|
||||
return data->conn->handler->proto_pollset(data, ps);
|
||||
sockfd = data->conn->sock[FIRSTSOCKET];
|
||||
if(conn->handler->proto_pollset)
|
||||
return conn->handler->proto_pollset(data, ps);
|
||||
sockfd = conn->sock[FIRSTSOCKET];
|
||||
if(sockfd != CURL_SOCKET_BAD) {
|
||||
/* Default is to wait to something from the server */
|
||||
return Curl_pollset_change(data, ps, sockfd, CURL_POLL_IN, 0);
|
||||
@ -955,13 +956,14 @@ static CURLcode mstate_protocol_pollset(struct Curl_easy *data,
|
||||
static CURLcode mstate_do_pollset(struct Curl_easy *data,
|
||||
struct easy_pollset *ps)
|
||||
{
|
||||
if(data->conn) {
|
||||
if(data->conn->handler->doing_pollset)
|
||||
return data->conn->handler->doing_pollset(data, ps);
|
||||
else if(CONN_SOCK_IDX_VALID(data->conn->send_idx)) {
|
||||
struct connectdata *conn = data->conn;
|
||||
if(conn) {
|
||||
if(conn->handler->doing_pollset)
|
||||
return conn->handler->doing_pollset(data, ps);
|
||||
else if(CONN_SOCK_IDX_VALID(conn->send_idx)) {
|
||||
/* Default is that we want to send something to the server */
|
||||
return Curl_pollset_add_out(
|
||||
data, ps, data->conn->sock[data->conn->send_idx]);
|
||||
data, ps, conn->sock[conn->send_idx]);
|
||||
}
|
||||
}
|
||||
return CURLE_OK;
|
||||
@ -970,13 +972,14 @@ static CURLcode mstate_do_pollset(struct Curl_easy *data,
|
||||
static CURLcode mstate_domore_pollset(struct Curl_easy *data,
|
||||
struct easy_pollset *ps)
|
||||
{
|
||||
if(data->conn) {
|
||||
if(data->conn->handler->domore_pollset)
|
||||
return data->conn->handler->domore_pollset(data, ps);
|
||||
else if(CONN_SOCK_IDX_VALID(data->conn->send_idx)) {
|
||||
struct connectdata *conn = data->conn;
|
||||
if(conn) {
|
||||
if(conn->handler->domore_pollset)
|
||||
return conn->handler->domore_pollset(data, ps);
|
||||
else if(CONN_SOCK_IDX_VALID(conn->send_idx)) {
|
||||
/* Default is that we want to send something to the server */
|
||||
return Curl_pollset_add_out(
|
||||
data, ps, data->conn->sock[data->conn->send_idx]);
|
||||
data, ps, conn->sock[conn->send_idx]);
|
||||
}
|
||||
}
|
||||
return CURLE_OK;
|
||||
@ -985,22 +988,23 @@ static CURLcode mstate_domore_pollset(struct Curl_easy *data,
|
||||
static CURLcode mstate_perform_pollset(struct Curl_easy *data,
|
||||
struct easy_pollset *ps)
|
||||
{
|
||||
if(!data->conn)
|
||||
struct connectdata *conn = data->conn;
|
||||
if(!conn)
|
||||
return CURLE_OK;
|
||||
else if(data->conn->handler->perform_pollset)
|
||||
return data->conn->handler->perform_pollset(data, ps);
|
||||
else if(conn->handler->perform_pollset)
|
||||
return conn->handler->perform_pollset(data, ps);
|
||||
else {
|
||||
/* Default is to obey the data->req.keepon flags for send/recv */
|
||||
CURLcode result = CURLE_OK;
|
||||
if(CURL_WANT_RECV(data) && CONN_SOCK_IDX_VALID(data->conn->recv_idx)) {
|
||||
if(CURL_WANT_RECV(data) && CONN_SOCK_IDX_VALID(conn->recv_idx)) {
|
||||
result = Curl_pollset_add_in(
|
||||
data, ps, data->conn->sock[data->conn->recv_idx]);
|
||||
data, ps, conn->sock[conn->recv_idx]);
|
||||
}
|
||||
|
||||
if(!result && Curl_req_want_send(data) &&
|
||||
CONN_SOCK_IDX_VALID(data->conn->send_idx)) {
|
||||
CONN_SOCK_IDX_VALID(conn->send_idx)) {
|
||||
result = Curl_pollset_add_out(
|
||||
data, ps, data->conn->sock[data->conn->send_idx]);
|
||||
data, ps, conn->sock[conn->send_idx]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1105,6 +1105,7 @@ static int myssh_in_AUTH_PASS(struct Curl_easy *data,
|
||||
static int myssh_in_AUTH_DONE(struct Curl_easy *data,
|
||||
struct ssh_conn *sshc)
|
||||
{
|
||||
struct connectdata *conn = data->conn;
|
||||
if(!sshc->authed) {
|
||||
failf(data, "Authentication failure");
|
||||
return myssh_to_ERROR(data, sshc, CURLE_LOGIN_DENIED);
|
||||
@ -1113,10 +1114,10 @@ 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->recv_idx = FIRSTSOCKET;
|
||||
data->conn->send_idx = -1;
|
||||
conn->recv_idx = FIRSTSOCKET;
|
||||
conn->send_idx = -1;
|
||||
|
||||
if(data->conn->handler->protocol == CURLPROTO_SFTP) {
|
||||
if(conn->handler->protocol == CURLPROTO_SFTP) {
|
||||
myssh_to(data, sshc, SSH_SFTP_INIT);
|
||||
return SSH_NO_ERROR;
|
||||
}
|
||||
@ -2428,14 +2429,15 @@ static CURLcode myssh_pollset(struct Curl_easy *data,
|
||||
struct easy_pollset *ps)
|
||||
{
|
||||
int flags = 0;
|
||||
if(data->conn->waitfor & KEEP_RECV)
|
||||
struct connectdata *conn = data->conn;
|
||||
if(conn->waitfor & KEEP_RECV)
|
||||
flags |= CURL_POLL_IN;
|
||||
if(data->conn->waitfor & KEEP_SEND)
|
||||
if(conn->waitfor & KEEP_SEND)
|
||||
flags |= CURL_POLL_OUT;
|
||||
if(!data->conn->waitfor)
|
||||
if(!conn->waitfor)
|
||||
flags |= CURL_POLL_OUT;
|
||||
return flags ?
|
||||
Curl_pollset_change(data, ps, data->conn->sock[FIRSTSOCKET], flags, 0) :
|
||||
Curl_pollset_change(data, ps, conn->sock[FIRSTSOCKET], flags, 0) :
|
||||
CURLE_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -3061,12 +3061,13 @@ static CURLcode ssh_pollset(struct Curl_easy *data,
|
||||
struct easy_pollset *ps)
|
||||
{
|
||||
int flags = 0;
|
||||
if(data->conn->waitfor & KEEP_RECV)
|
||||
struct connectdata *conn = data->conn;
|
||||
if(conn->waitfor & KEEP_RECV)
|
||||
flags |= CURL_POLL_IN;
|
||||
if(data->conn->waitfor & KEEP_SEND)
|
||||
if(conn->waitfor & KEEP_SEND)
|
||||
flags |= CURL_POLL_OUT;
|
||||
return flags ?
|
||||
Curl_pollset_change(data, ps, data->conn->sock[FIRSTSOCKET], flags, 0) :
|
||||
Curl_pollset_change(data, ps, conn->sock[FIRSTSOCKET], flags, 0) :
|
||||
CURLE_OK;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user