aboutsummaryrefslogtreecommitdiff
path: root/lib/tftp.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2008-02-11 22:03:31 +0000
committerDaniel Stenberg <daniel@haxx.se>2008-02-11 22:03:31 +0000
commitfcc320ee404606b7f9d4d140e7770a0f8dd2754d (patch)
tree6de4df1001ba130d74af3790c30bf0f34feabde7 /lib/tftp.c
parentdc9fe9c3610fe96554978d4b2f6090ac7887ef79 (diff)
Yang Tse pointed out a few remaining quirks from my timeout refactoring from
Feb 7 that didn't abort properly on timeouts. These are actually old problems but now they should be fixed.
Diffstat (limited to 'lib/tftp.c')
-rw-r--r--lib/tftp.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/tftp.c b/lib/tftp.c
index 8b3656cdf..ffd668c19 100644
--- a/lib/tftp.c
+++ b/lib/tftp.c
@@ -189,16 +189,24 @@ const struct Curl_handler Curl_handler_tftp = {
*
*
**********************************************************/
-static void tftp_set_timeouts(tftp_state_data_t *state)
+static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
{
time_t maxtime, timeout;
long timeout_ms;
time(&state->start_time);
+ /* Compute drop-dead time */
+ timeout_ms = Curl_timeleft(state->conn, NULL, TRUE);
+
+ if(timeout_ms < 0) {
+ /* time-out, bail out, go home */
+ failf(state->conn->data, "Connection time-out");
+ return CURLE_OPERATION_TIMEDOUT;
+ }
+
if(state->state == TFTP_STATE_START) {
- /* Compute drop-dead time */
- timeout_ms = Curl_timeleft(state->conn, NULL, TRUE);
+
maxtime = (time_t)(timeout_ms + 500) / 1000;
state->max_time = state->start_time+maxtime;
@@ -219,8 +227,6 @@ static void tftp_set_timeouts(tftp_state_data_t *state)
}
else {
- /* Compute drop-dead time */
- timeout_ms = Curl_timeleft(state->conn, NULL, TRUE);
if(timeout_ms > 0)
maxtime = (time_t)(timeout_ms + 500) / 1000;
else
@@ -250,6 +256,8 @@ static void tftp_set_timeouts(tftp_state_data_t *state)
"set timeouts for state %d; Total %d, retry %d maxtry %d\n",
state->state, (state->max_time-state->start_time),
state->retry_time, state->retry_max);
+
+ return CURLE_OK;
}
/**********************************************************
@@ -343,13 +351,17 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
case TFTP_EVENT_ACK: /* Connected for transmit */
infof(data, "%s\n", "Connected for transmit");
state->state = TFTP_STATE_TX;
- tftp_set_timeouts(state);
+ res = tftp_set_timeouts(state);
+ if(res)
+ break;
return tftp_tx(state, event);
case TFTP_EVENT_DATA: /* connected for receive */
infof(data, "%s\n", "Connected for receive");
state->state = TFTP_STATE_RX;
- tftp_set_timeouts(state);
+ res = tftp_set_timeouts(state);
+ if(res)
+ break;
return tftp_rx(state, event);
case TFTP_EVENT_ERROR: