cURL / Mailing Lists / curl-users / Single Mail

curl-users

[PATCH] TFTP: Fix Connect and Transfer Timeout Behavior

From: Grant Erickson <gerickson_at_nuovations.com>
Date: Mon, 12 Jan 2009 00:07:14 -0800

Fix timeouts for TFTP such that specifying a connect-timeout, a max-time
or both options work correctly and as expected by passing the correct
Boolean value to Curl_timeleft via the 'duringconnect' parameter.

Signed-off-by: Grant Erickson <gerickson_at_nuovations.com>

---
With this small change, curl TFTP now behaves as expected (and likely
as originally-designed):
1) For non-existent or unreachable dotted IP addresses:
   a) With no options, follows the default curl 300s timeout...
   b) With --connect-timeout only, follows that value...
   c) With --max-time only, follows that value...
   d) With both --connect-timeout and --max-time, follows the smaller value...
   and times out with a "curl: (7) Couldn't connect to server" error.
2) For transfers to/from a valid host:
   a) With no options, follows default curl 300s timeout for the
      first XRQ/DATA/ACK transaction and the default TFTP 3600s
      timeout for the remainder of the transfer...
   b) With --connect-time only, follows that value for the
      first XRQ/DATA/ACK transaction and the default TFTP 3600s
      timeout for the remainder of the transfer...
   c) With --max-time only, follows that value for the first
      XRQ/DATA/ACK transaction and for the remainder of the
      transfer...
   d) With both --connect-timeout and --max-time, follows the former
      for the first XRQ/DATA/ACK transaction and the latter for the
      remainder of the transfer...
   and times out with a "curl: (28) Timeout was reached" error as
   appropriate.
 lib/tftp.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/tftp.c b/lib/tftp.c
index b59fbae..0e22395 100644
--- a/lib/tftp.c
+++ b/lib/tftp.c
@@ -192,11 +192,12 @@ static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
 {
   time_t maxtime, timeout;
   long timeout_ms;
+  const bool start = (state->state == TFTP_STATE_START);
 
   time(&state->start_time);
 
   /* Compute drop-dead time */
-  timeout_ms = Curl_timeleft(state->conn, NULL, TRUE);
+  timeout_ms = Curl_timeleft(state->conn, NULL, start);
 
   if(timeout_ms < 0) {
     /* time-out, bail out, go home */
@@ -204,7 +205,7 @@ static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
     return CURLE_OPERATION_TIMEDOUT;
   }
 
-  if(state->state == TFTP_STATE_START) {
+  if(start) {
 
     maxtime = (time_t)(timeout_ms + 500) / 1000;
     state->max_time = state->start_time+maxtime;
-- 
1.6.1
-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2009-01-12