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

时间:2013-12-25 12:17:29

标签: curl ftp

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

2 个答案:

答案 0 :(得分:0)

这是来自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)

答案 1 :(得分:0)

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