int tr_rcCanGlobalTransfer( tr_handle_t * h, int isUpload )
{
    tr_torrent_t * tor;
    tr_ratecontrol_t * r;
    float rate = 0;
    int limit = isUpload ? h->uploadLimit : h->downloadLimit;
    
    if( limit <= 0 )
    {
        return limit < 0;
    }
    
    tr_sharedLock( h->shared );
    for( tor = h->torrentList; tor; tor = tor->next )
    {
        if( isUpload ? tor->customUploadLimit : tor->customDownloadLimit )
        {
            continue;
        }
        
        r = isUpload ? tor->upload : tor->download;
        tr_lockLock( &r->lock );
        rate += rateForInterval( r, SHORT_INTERVAL );
        tr_lockUnlock( &r->lock );
        
        if( rate >= (float)limit )
        {
            tr_sharedUnlock( h->shared );
            return 0;
        }
    }
    tr_sharedUnlock( h->shared );
    
    return 1;
}
Exemple #2
0
float
tr_rcRate( const tr_ratecontrol * r )
{
    float ret = 0.0f;

    if( r )
        ret = rateForInterval( r, INTERVAL_MSEC );

    return ret;
}
float tr_rcRate( tr_ratecontrol_t * r )
{
    float ret;

    tr_lockLock( &r->lock );
    ret = rateForInterval( r, LONG_INTERVAL );
    tr_lockUnlock( &r->lock );

    return ret;
}
int tr_rcCanTransfer( tr_ratecontrol_t * r )
{
    int ret;

    tr_lockLock( &r->lock );
    ret = ( r->limit <= 0 ) ? ( r->limit < 0 ) :
            ( rateForInterval( r, SHORT_INTERVAL ) < r->limit );
    tr_lockUnlock( &r->lock );

    return ret;
}