mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
pingpong: cleanup timeleft handling
- Move `RESP_TIMEOUT` from urldata.h to pingpong.h as `PINGPONG_TIMEOUT_MS`. - Rename `Curl_pp_state_timeout()` to `Curl_pp_state_timeleft_ms()` as the function returns the time left, not the timout.. - Update implementation comments and variable names Closes #20888
This commit is contained in:
parent
da7bfb89a1
commit
f14ce01369
@ -657,7 +657,7 @@ static CURLcode getftpresponse(struct Curl_easy *data,
|
|||||||
|
|
||||||
while(!*ftpcodep && !result) {
|
while(!*ftpcodep && !result) {
|
||||||
/* check and reset timeout value every lap */
|
/* check and reset timeout value every lap */
|
||||||
timediff_t timeout = Curl_pp_state_timeout(data, pp);
|
timediff_t timeout = Curl_pp_state_timeleft_ms(data, pp);
|
||||||
timediff_t interval_ms;
|
timediff_t interval_ms;
|
||||||
|
|
||||||
if(timeout <= 0) {
|
if(timeout <= 0) {
|
||||||
|
|||||||
@ -39,29 +39,21 @@
|
|||||||
#include "select.h"
|
#include "select.h"
|
||||||
#include "progress.h"
|
#include "progress.h"
|
||||||
|
|
||||||
/* Returns timeout in ms. 0 or negative number means the timeout has already
|
timediff_t Curl_pp_state_timeleft_ms(struct Curl_easy *data,
|
||||||
triggered */
|
struct pingpong *pp)
|
||||||
timediff_t Curl_pp_state_timeout(struct Curl_easy *data,
|
|
||||||
struct pingpong *pp)
|
|
||||||
{
|
{
|
||||||
timediff_t timeout_ms, xfer_timeout_ms;
|
timediff_t xfer_remain_ms;
|
||||||
timediff_t response_time = data->set.server_response_timeout ?
|
timediff_t remain_ms = data->set.server_response_timeout ?
|
||||||
data->set.server_response_timeout : RESP_TIMEOUT;
|
data->set.server_response_timeout : PINGPONG_TIMEOUT_MS;
|
||||||
|
|
||||||
/* if CURLOPT_SERVER_RESPONSE_TIMEOUT is set, use that to determine
|
/* If the overall transfer has less time remaining than pingpong
|
||||||
remaining time, or use pp->response because SERVER_RESPONSE_TIMEOUT is
|
* has otherwise for the state, return that. */
|
||||||
supposed to govern the response for any given server response, not for
|
remain_ms -= curlx_ptimediff_ms(Curl_pgrs_now(data), &pp->response);
|
||||||
the time from connect to the given server response. */
|
/* transfer remaining time is 0, when it has no timeout. */
|
||||||
|
xfer_remain_ms = Curl_timeleft_ms(data);
|
||||||
/* Without a requested timeout, we only wait 'response_time' seconds for the
|
if(xfer_remain_ms)
|
||||||
full response to arrive before we bail out */
|
return CURLMIN(remain_ms, xfer_remain_ms);
|
||||||
timeout_ms = response_time -
|
return remain_ms;
|
||||||
curlx_ptimediff_ms(Curl_pgrs_now(data), &pp->response);
|
|
||||||
/* transfer timeout can be 0, which means no timeout applies */
|
|
||||||
xfer_timeout_ms = Curl_timeleft_ms(data);
|
|
||||||
if(xfer_timeout_ms && (xfer_timeout_ms < timeout_ms))
|
|
||||||
return xfer_timeout_ms;
|
|
||||||
return timeout_ms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -75,7 +67,7 @@ CURLcode Curl_pp_statemach(struct Curl_easy *data,
|
|||||||
curl_socket_t sock = conn->sock[FIRSTSOCKET];
|
curl_socket_t sock = conn->sock[FIRSTSOCKET];
|
||||||
int rc;
|
int rc;
|
||||||
timediff_t interval_ms;
|
timediff_t interval_ms;
|
||||||
timediff_t timeout_ms = Curl_pp_state_timeout(data, pp);
|
timediff_t timeout_ms = Curl_pp_state_timeleft_ms(data, pp);
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
|
|
||||||
if(timeout_ms <= 0) {
|
if(timeout_ms <= 0) {
|
||||||
|
|||||||
@ -70,6 +70,10 @@ struct pingpong {
|
|||||||
read */
|
read */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Default pingpong response timeout in milliseconds, unless a transfer
|
||||||
|
* has CURLOPT_SERVER_RESPONSE_TIMEOUT(_MS) set. */
|
||||||
|
#define PINGPONG_TIMEOUT_MS (60 * 1000)
|
||||||
|
|
||||||
#define PINGPONG_SETUP(pp, s, e) \
|
#define PINGPONG_SETUP(pp, s, e) \
|
||||||
do { \
|
do { \
|
||||||
(pp)->statemachine = s; \
|
(pp)->statemachine = s; \
|
||||||
@ -88,10 +92,10 @@ CURLcode Curl_pp_statemach(struct Curl_easy *data, struct pingpong *pp,
|
|||||||
/* initialize stuff to prepare for reading a fresh new response */
|
/* initialize stuff to prepare for reading a fresh new response */
|
||||||
void Curl_pp_init(struct pingpong *pp, const struct curltime *pnow);
|
void Curl_pp_init(struct pingpong *pp, const struct curltime *pnow);
|
||||||
|
|
||||||
/* Returns timeout in ms. 0 or negative number means the timeout has already
|
/* Returns time remaining in ms. 0 or negative number means the
|
||||||
triggered */
|
timeout has already triggered */
|
||||||
timediff_t Curl_pp_state_timeout(struct Curl_easy *data,
|
timediff_t Curl_pp_state_timeleft_ms(struct Curl_easy *data,
|
||||||
struct pingpong *pp);
|
struct pingpong *pp);
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
|
|||||||
@ -120,9 +120,6 @@ typedef curl_off_t curl_prot_t;
|
|||||||
/* length of longest IPv6 address string including the trailing null */
|
/* length of longest IPv6 address string including the trailing null */
|
||||||
#define MAX_IPADR_LEN sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")
|
#define MAX_IPADR_LEN sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")
|
||||||
|
|
||||||
/* Default FTP/IMAP etc response timeout in milliseconds */
|
|
||||||
#define RESP_TIMEOUT (60 * 1000)
|
|
||||||
|
|
||||||
/* Max string input length is a precaution against abuse and to detect junk
|
/* Max string input length is a precaution against abuse and to detect junk
|
||||||
input easier and better. */
|
input easier and better. */
|
||||||
#define CURL_MAX_INPUT_LENGTH 8000000
|
#define CURL_MAX_INPUT_LENGTH 8000000
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user