Changeset 8134


Ignore:
Timestamp:
Apr 5, 2009, 1:00:17 PM (13 years ago)
Author:
charles
Message:

(trunk libT) re-add the curl "easy queue" from 1.4x to queue libcurl tasks to ameliorate complaints of "too many open files"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/web.c

    r7905 r8134  
    7373    tr_session * session;
    7474    struct event timer_event;
     75    tr_list * easy_queue;
    7576    tr_list * fds;
    7677};
     
    215216            curl_easy_setopt( easy, CURLOPT_ENCODING, "" );
    216217
    217         {
     218        if( web->still_running >= MAX_CONCURRENT_TASKS ) {
     219            tr_list_append( &web->easy_queue, easy );
     220            dbgmsg( ">> enqueueing a task... size is now %d", tr_list_size( web->easy_queue ) );
     221        } else {
    218222            const CURLMcode mcode = curl_multi_add_handle( web->multi, easy );
    219223            tr_assert( mcode == CURLM_OK, "curl_multi_add_handle() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
     
    323327    tr_timevalMsec( g->timer_ms, &interval );
    324328    evtimer_add( &g->timer_event, &interval );
     329}
     330
     331static void
     332add_tasks_from_queue( tr_web * g )
     333{
     334    while( ( g->still_running < MAX_CONCURRENT_TASKS )
     335        && ( tr_list_size( g->easy_queue ) > 0 ) )
     336    {
     337        CURL * easy = tr_list_pop_front( &g->easy_queue );
     338        if( easy )
     339        {
     340            const CURLMcode rc = curl_multi_add_handle( g->multi, easy );
     341            if( rc != CURLM_OK )
     342                tr_err( "%s", curl_multi_strerror( rc ) );
     343            else {
     344                dbgmsg( "pumped the task queue, %d remain",
     345                        tr_list_size( g->easy_queue ) );
     346                ++g->still_running;
     347            }
     348        }
     349    }
    325350}
    326351
     
    372397
    373398    remove_finished_tasks( g );
     399
     400    add_tasks_from_queue( g );
    374401
    375402    if( !g->still_running ) {
Note: See TracChangeset for help on using the changeset viewer.