What option causes curl to reconnect infinite time

2019-07-23 07:54发布

问题:

I'm using curl to upload files to a remote server. If I added to the remote server iptables rule to deny access from client, I want the client to keep trying to reconnect to the remote server. After enabling verbose mode I see that after the 3rd time the upload timed out, curl will not retry for the 4th time to connect to the remote server. Why is that and how to change it? Is there an option for that in curl_easy_setopt?

回答1:

This is from curl's man page. Forgive me if I misunderstood.

--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)


回答2:

This happens automatically, curl will try to reconnect every time the requested operation will timeout. Add something like curl_easy_setopt(m_curl, CURLOPT_TIMEOUT, 5L) to add timeout option. The problem I have reported was actually a bug in my code.



标签: curl ftp