mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
Adds download rate limit
This commit is contained in:
parent
0563eaf19c
commit
b9a53769f9
4 changed files with 48 additions and 17 deletions
|
@ -41,16 +41,18 @@
|
|||
" -v, --verbose <int> Verbose level (0 to 2, default = 0)\n" \
|
||||
" -p, --port <int> Port we should listen on (default = %d)\n" \
|
||||
" -u, --upload <int> Maximum upload rate (-1 = no limit, default = 20)\n" \
|
||||
" -d, --download <int> Maximum download rate (-1 = no limit, default = -1)\n" \
|
||||
" -f, --finish <shell script> Command you wish to run on completion\n"
|
||||
|
||||
static int showHelp = 0;
|
||||
static int showInfo = 0;
|
||||
static int showScrape = 0;
|
||||
static int verboseLevel = 0;
|
||||
static int bindPort = TR_DEFAULT_PORT;
|
||||
static int uploadLimit = 20;
|
||||
static char * torrentPath = NULL;
|
||||
static volatile char mustDie = 0;
|
||||
static int showHelp = 0;
|
||||
static int showInfo = 0;
|
||||
static int showScrape = 0;
|
||||
static int verboseLevel = 0;
|
||||
static int bindPort = TR_DEFAULT_PORT;
|
||||
static int uploadLimit = 20;
|
||||
static int downloadLimit = -1;
|
||||
static char * torrentPath = NULL;
|
||||
static volatile char mustDie = 0;
|
||||
|
||||
static char * finishCall = NULL;
|
||||
|
||||
|
@ -158,6 +160,7 @@ int main( int argc, char ** argv )
|
|||
|
||||
tr_setBindPort( h, bindPort );
|
||||
tr_setUploadLimit( h, uploadLimit );
|
||||
tr_setDownloadLimit( h, downloadLimit );
|
||||
|
||||
tr_torrentSetFolder( tor, "." );
|
||||
tr_torrentStart( tor );
|
||||
|
@ -240,17 +243,18 @@ static int parseCommandLine( int argc, char ** argv )
|
|||
for( ;; )
|
||||
{
|
||||
static struct option long_options[] =
|
||||
{ { "help", no_argument, NULL, 'h' },
|
||||
{ "info", no_argument, NULL, 'i' },
|
||||
{ "scrape", no_argument, NULL, 's' },
|
||||
{ "verbose", required_argument, NULL, 'v' },
|
||||
{ "port", required_argument, NULL, 'p' },
|
||||
{ "upload", required_argument, NULL, 'u' },
|
||||
{ "finish", required_argument, NULL, 'f' },
|
||||
{ { "help", no_argument, NULL, 'h' },
|
||||
{ "info", no_argument, NULL, 'i' },
|
||||
{ "scrape", no_argument, NULL, 's' },
|
||||
{ "verbose", required_argument, NULL, 'v' },
|
||||
{ "port", required_argument, NULL, 'p' },
|
||||
{ "upload", required_argument, NULL, 'u' },
|
||||
{ "download", required_argument, NULL, 'd' },
|
||||
{ "finish", required_argument, NULL, 'f' },
|
||||
{ 0, 0, 0, 0} };
|
||||
|
||||
int c, optind = 0;
|
||||
c = getopt_long( argc, argv, "hisv:p:u:f:", long_options, &optind );
|
||||
c = getopt_long( argc, argv, "hisv:p:u:d:f:", long_options, &optind );
|
||||
if( c < 0 )
|
||||
{
|
||||
break;
|
||||
|
@ -275,6 +279,9 @@ static int parseCommandLine( int argc, char ** argv )
|
|||
case 'u':
|
||||
uploadLimit = atoi( optarg );
|
||||
break;
|
||||
case 'd':
|
||||
downloadLimit = atoi( optarg );
|
||||
break;
|
||||
case 'f':
|
||||
finishCall = optarg;
|
||||
break;
|
||||
|
|
|
@ -219,6 +219,11 @@ int tr_peerRead( tr_torrent_t * tor, tr_peer_t * peer )
|
|||
/* Try to read */
|
||||
for( ;; )
|
||||
{
|
||||
if( tor && !tr_rcCanTransfer( tor->globalDownload ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if( peer->size < 1 )
|
||||
{
|
||||
peer->size = 1024;
|
||||
|
@ -229,8 +234,10 @@ int tr_peerRead( tr_torrent_t * tor, tr_peer_t * peer )
|
|||
peer->size *= 2;
|
||||
peer->buf = realloc( peer->buf, peer->size );
|
||||
}
|
||||
/* Never read more than 1K each time, otherwise the rate
|
||||
control is no use */
|
||||
ret = tr_netRecv( peer->socket, &peer->buf[peer->pos],
|
||||
peer->size - peer->pos );
|
||||
MIN( 1024, peer->size - peer->pos ) );
|
||||
if( ret & TR_NET_CLOSE )
|
||||
{
|
||||
peer_dbg( "connection closed" );
|
||||
|
|
|
@ -139,6 +139,16 @@ void tr_setUploadLimit( tr_handle_t * h, int limit )
|
|||
tr_chokingSetLimit( h->choking, limit );
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* tr_setDownloadLimit
|
||||
***********************************************************************
|
||||
*
|
||||
**********************************************************************/
|
||||
void tr_setDownloadLimit( tr_handle_t * h, int limit )
|
||||
{
|
||||
tr_rcSetLimit( h->download, limit );
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* tr_torrentRates
|
||||
***********************************************************************
|
||||
|
|
|
@ -73,6 +73,13 @@ void tr_setBindPort( tr_handle_t *, int );
|
|||
**********************************************************************/
|
||||
void tr_setUploadLimit( tr_handle_t *, int );
|
||||
|
||||
/***********************************************************************
|
||||
* tr_setDownloadLimit
|
||||
***********************************************************************
|
||||
* Sets the total download rate limit in KB/s
|
||||
**********************************************************************/
|
||||
void tr_setDownloadLimit( tr_handle_t *, int );
|
||||
|
||||
/***********************************************************************
|
||||
* tr_torrentCount
|
||||
***********************************************************************
|
||||
|
|
Loading…
Reference in a new issue