patch: tftp retry/timeout tweaking

Denys Vlasenko vda.linux at googlemail.com
Thu Sep 6 09:53:29 PDT 2007


On Wednesday 05 September 2007 22:20, Paul Fox wrote:
> currently the busybox tftp client will retry forever, due
> to a misplaced reinitialization of the retry counter.
> 
> in addition, it times out for a full 5 seconds on any lost
> packet, which blows performance completely on a marginal
> network.
> 
> this patch cleans up both of these issues, by providing a
> simple exponential backoff mechanism.
> 
> i just blew away my baseline with a "make clean", but i believe
> the size cost was about 47 bytes.
> 
> i'll commit tomorrow if no one objects.

Go for it! :)

> -		timeout = TFTP_NUM_RETRIES;	/* re-initialize */
>   recv_again:
>  		/* Receive packet */
> -		tv.tv_sec = TFTP_TIMEOUT;
> -		tv.tv_usec = 0;
> +		tv.tv_sec = 0;
> +		tv.tv_usec = waittime;
>  		FD_ZERO(&rfds);
>  		FD_SET(socketfd, &rfds);
>  		switch (select(socketfd + 1, &rfds, NULL, NULL, &tv)) {

Select bitmasks are quite big: 128 bytes
I found out that using poll for waiting on one descriptor only
prodices noticeably smaller code.

For one, you have max timeout of 999000 us just because
you don't want to mess with tv_usec overflow.
With poll, it's trivial to have e.g. 2 second timeout -

int poll(struct pollfd *ufds, nfds_t nfds, int timeout_in_ms);
                                               ^^^^^^^^^^^^^

(I can imagine that it drives people mad when they need _micro_seconds...)
--
vda


More information about the busybox mailing list