什么选项会导致 curl 无限次重新连接



我正在使用curl将文件上传到远程服务器。如果我向远程服务器添加了iptables规则以拒绝来自客户端的访问,我希望客户端继续尝试重新连接到远程服务器。启用详细模式后,我看到在第三次上传超时后,curl 不会第 4 次重试连接到远程服务器。为什么会这样以及如何改变它?curl_easy_setopt有没有选择?

这是

来自curl的手册页。如果我误会了,请原谅我。

--retry <num>
          If a transient error is returned when curl tries  to  perform  a
          transfer,  it  will retry this number of times before giving up.
          Setting the number to 0 makes curl do no retries (which  is  the
          default).  Transient  error  means either: a timeout, an FTP 4xx
          response code or an HTTP 5xx response code.
          When curl is about to retry a transfer, it will first  wait  one
          second  and  then for all forthcoming retries it will double the
          waiting time until it reaches 10 minutes which then will be  the
          delay  between  the rest of the retries.  By using --retry-delay
          you  disable  this  exponential  backoff  algorithm.  See   also
          --retry-max-time  to  limit  the total time allowed for retries.
          (Added in 7.12.3)
          If this option is used several times, the last one will be used.
   --retry-delay <seconds>
          Make curl sleep this amount of time before  each  retry  when  a
          transfer  has  failed  with  a  transient  error (it changes the
          default backoff time algorithm between retries). This option  is
          only  interesting if --retry is also used. Setting this delay to
          zero will make curl use the default  backoff  time.   (Added  in
          7.12.3)
          If this option is used several times, the last one will be used.
   --retry-max-time <seconds>
          The  retry  timer  is  reset  before the first transfer attempt.
          Retries will be done as usual (see --retry) as long as the timer
          hasn't reached this given limit. Notice that if the timer hasn't
          reached the limit, the request will be made and  while  perform‐
          ing,  it may take longer than this given time period. To limit a
          single request´s maximum time, use  -m,  --max-time.   Set  this
          option to zero to not timeout retries. (Added in 7.12.3)

此操作会自动发生,curl每次请求的操作超时时都会尝试重新连接。添加类似 curl_easy_setopt(m_curl, CURLOPT_TIMEOUT, 5L) 的内容以添加超时选项。我报告的问题实际上是我的代码中的错误。