Skip to content

Commit

Permalink
tftp_rx: handle resends
Browse files Browse the repository at this point in the history
Re-send ACK for block X in case we receive block X data again while
waiting for block X+1.

Based on an earlier patch by Marcin Adamski.
  • Loading branch information
Christian Vogt authored and bagder committed Nov 16, 2012
1 parent c277bd6 commit 0ac8278
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/tftp.c
Expand Up @@ -591,16 +591,26 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
case TFTP_EVENT_DATA:
/* Is this the block we expect? */
rblock = getrpacketblock(&state->rpacket);
if(NEXT_BLOCKNUM(state->block) != rblock) {
/* No, log it */
if( NEXT_BLOCKNUM(state->block) == rblock ) {
/* This is the expected block. Reset counters and ACK it. */
state->retries = 0;
}
else if( state->block == rblock ) {
/* This is the last recently received block again. Log it and ACK it again. */
infof(data,
"Received last DATA packet block %d again.\n",
rblock);
}
else {
/* totally unexpected, just log it */
infof(data,
"Received unexpected DATA packet block %d, expecting block %d\n",
rblock, NEXT_BLOCKNUM(state->block));
break;
}
/* This is the expected block. Reset counters and ACK it. */

/* ACK this block. */
state->block = (unsigned short)rblock;
state->retries = 0;
setpacketevent(&state->spacket, TFTP_EVENT_ACK);
setpacketblock(&state->spacket, state->block);
sbytes = sendto(state->sockfd, (void *)state->spacket.data,
Expand Down

0 comments on commit 0ac8278

Please sign in to comment.