[axel-devel] [PATCH] prevent -a from thrashing the terminal

Philipp Hagemeister phihag at phihag.de
Wed Jan 6 13:08:29 UTC 2010


Hi Aron,

thank you very much for your patch. It looks great and will be applied
before the release of 2.5. The reason I'm not immediately applying is a
few minor nitpicks:

* I'd very much avoid (more) static variables because they prevent
running multiple instances in a single process. Better allocate the
current version in the scope of main.
* str should be called statestr, prev prev_statestr. s could be
statestr_curpos.
* I don't think that the state string is always smaller than MAX_STRING.

I'll try to fix the problem in the next days, starting from your patch.

Again, thank you very much for your contribution to axel and patience
with me and my schedule.

Regards,

Philipp

Aron Griffis wrote:
> Presently alternate output mode writes a new string to the
> terminal every time any data arrives on any connection. This
> redraws the output line even when there's no change from the last
> output.
> 
> This patch causes the redraw to occur only when the string
> changes. Patch is against trunk and also applies cleanly to 2.4
> in Debian. Tested and demonstrated effective using 2.4 on Debian.
> 
> Signed-off-by: Aron Griffis <agriffis at n01se.net>
> 
> Index: text.c
> ===================================================================
> --- text.c	(revision 115)
> +++ text.c	(working copy)
> @@ -486,35 +486,38 @@
>  	long long int total=axel->size;
>  	int i,j=0;
>  	double now = gettime();
> +	static char str[MAX_STRING] = {0};
> +	static char prev[MAX_STRING] = {0};
> +	char *s = str;
>  	
> -	printf("\r[%3ld%%] [", min(100,(long)(done*100./total+.5) ) );
> -		
> +	s += sprintf(s, "\r[%3ld%%] [", min(100,(long)(done*100./total+.5) ) );
> +
>  	for(i=0;i<axel->conf->num_connections;i++)
>  	{
>  		for(;j<((double)axel->conn[i].currentbyte/(total+1)*50)-1;j++)
> -			putchar('.');
> +			*s++ = '.';
>  
>  		if(axel->conn[i].currentbyte<axel->conn[i].lastbyte)
>  		{
>  			if(now <= axel->conn[i].last_transfer + axel->conf->connection_timeout/2 )
> -				putchar(i+'0');
> +				*s++ = '0'+i;
>  			else
> -				putchar('#');
> +				*s++ = '#';
>  		} else 
> -			putchar('.');
> +			*s++ = '.';
>  
>  		j++;
>  		
>  		for(;j<((double)axel->conn[i].lastbyte/(total+1)*50);j++)
> -			putchar(' ');
> +			*s++ = ' ';
>  	}
>  	
>  	if(axel->bytes_per_second > 1048576)
> -		printf( "] [%6.1fMB/s]", (double) axel->bytes_per_second / (1024*1024) );
> +		s += sprintf(s, "] [%6.1fMB/s]", (double) axel->bytes_per_second / (1024*1024) );
>  	else if(axel->bytes_per_second > 1024)
> -		printf( "] [%6.1fKB/s]", (double) axel->bytes_per_second / 1024 );
> +		s += sprintf(s, "] [%6.1fKB/s]", (double) axel->bytes_per_second / 1024 );
>  	else
> -		printf( "] [%6.1fB/s]", (double) axel->bytes_per_second );
> +		s += sprintf(s, "] [%6.1fB/s]", (double) axel->bytes_per_second );
>  	
>  	if(done<total)
>  	{
> @@ -524,14 +527,18 @@
>  		hours=minutes/60;minutes-=hours*60;
>  		days=hours/24;hours-=days*24;
>  		if(days)
> -			printf(" [%2dd%2d]",days,hours);
> +			s += sprintf(s, " [%2dd%2d]",days,hours);
>  		else if(hours)
> -			printf(" [%2dh%02d]",hours,minutes);
> +			s += sprintf(s, " [%2dh%02d]",hours,minutes);
>  		else
> -			printf(" [%02d:%02d]",minutes,seconds);
> +			s += sprintf(s, " [%02d:%02d]",minutes,seconds);
>  	}
> -	
> -	fflush( stdout );
> +
> +	if(strcmp(str, prev)) {
> +		strcpy(prev, str);
> +		fputs(str, stdout);
> +		fflush(stdout);
> +	}
>  }
>  
>  void print_help()
> 
> _______________________________________________
> axel-devel mailing list
> axel-devel at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/axel-devel
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://lists.alioth.debian.org/pipermail/axel-devel/attachments/20100106/3600d5a6/attachment.pgp>


More information about the axel-devel mailing list