Changeset 9710


Ignore:
Timestamp:
Dec 10, 2009, 7:05:21 PM (12 years ago)
Author:
charles
Message:

(trunk libT) use curl_multi_socket_action(), even on OS X.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r9693 r9710  
    732732{
    733733    return ( announce != NULL )
     734        && ( strstr( announce, "tracker.thepiratebay.org" ) == NULL ) /* dead */
    734735        && ( ( strstr( announce, "http://" ) == announce ) ||
    735736             ( strstr( announce, "https://" ) == announce ) );
  • trunk/libtransmission/web.c

    r9704 r9710  
    2828#include "web.h"
    2929
    30 static tr_bool
    31 useCurlMultiSocketAction( void )
    32 {
    33     static tr_bool tested = FALSE;
    34     static tr_bool useMultiSocketAction;
    35 
    36     if( !tested )
    37     {
    38 #ifdef SYS_DARWIN /* for some reason, curl_multi_socket_action() + libevent
    39                      keeps crashing in event_queue_insert() on OS X 10.5 & 10.6 */
    40         useMultiSocketAction = FALSE;
    41 #else
    42         curl_version_info_data * data = curl_version_info( CURLVERSION_NOW );
    43         tr_inf( "Using libcurl %s", data->version );
    44         /* Use curl_multi_socket_action() instead of curl_multi_perform()
    45          * if libcurl >= 7.18.2.  See http://trac.transmissionbt.com/ticket/1844 */
    46         useMultiSocketAction = data->version_num >= 0x071202;
    47 #endif
    48         tested = TRUE;
    49     }
    50 
    51     return useMultiSocketAction;
    52 }
    53 
    5430enum
    5531{
    5632    /* arbitrary number */
    57     DEFAULT_TIMER_MSEC = 2500
     33    DEFAULT_TIMER_MSEC = 1500
    5834};
     35
     36static void
     37tr_multi_perform( tr_web * g, int fd );
    5938
    6039#if 0
     
    8463    int prev_running;
    8564    int still_running;
    86     long timer_ms;
     65    long timer_msec;
    8766    CURLM * multi;
    8867    tr_session * session;
     
    279258            else
    280259                tr_err( "%s", curl_multi_strerror( mcode ) );
     260
     261            tr_multi_perform( web, CURL_SOCKET_TIMEOUT );
    281262        }
    282263    }
     
    372353restart_timer( tr_web * g )
    373354{
    374     struct timeval interval;
    375 
    376355    assert( tr_amInEventThread( g->session ) );
    377356    assert( g->session != NULL );
     
    379358
    380359    stop_timer( g );
    381     dbgmsg( "adding a timeout for %.1f seconds from now", g->timer_ms/1000.0 );
    382     tr_timevalMsec( g->timer_ms, &interval );
    383     evtimer_add( &g->timer_event, &interval );
     360    dbgmsg( "adding a timeout for %.1f seconds from now", g->timer_msec/1000.0 );
     361    tr_timerAddMsec( &g->timer_event, g->timer_msec );
    384362}
    385363
     
    412390
    413391    /* invoke libcurl's processing */
    414     if( useCurlMultiSocketAction( ) )
    415     {
    416         do {
    417             dbgmsg( "calling curl_multi_socket_action..." );
    418             mcode = curl_multi_socket_action( g->multi, fd, 0, &g->still_running );
    419             fd = CURL_SOCKET_TIMEOUT;
    420             dbgmsg( "done calling curl_multi_socket_action..." );
    421         } while( mcode == CURLM_CALL_MULTI_SOCKET );
    422     }
    423     else
    424     {
    425         do {
    426             dbgmsg( "calling curl_multi_perform..." );
    427             mcode = curl_multi_perform( g->multi, &g->still_running );
    428             dbgmsg( "done calling curl_multi_perform..." );
    429         } while( mcode == CURLM_CALL_MULTI_PERFORM );
    430     }
     392    do {
     393        dbgmsg( "calling curl_multi_socket_action..." );
     394        mcode = curl_multi_socket_action( g->multi, fd, 0, &g->still_running );
     395        fd = CURL_SOCKET_TIMEOUT;
     396        dbgmsg( "done calling curl_multi_socket_action..." );
     397    } while( mcode == CURLM_CALL_MULTI_SOCKET );
    431398    tr_assert( mcode == CURLM_OK, "curl_multi_perform() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
    432399    if( mcode != CURLM_OK )
     
    453420{
    454421    tr_multi_perform( g, fd );
    455 }
    456 
    457 /* libevent says that timer_ms have passed, so wake up libcurl */
    458 static void
    459 timer_cb( int socket UNUSED, short action UNUSED, void * g )
    460 {
    461     dbgmsg( "libevent timer is done" );
    462     tr_multi_perform( g, CURL_SOCKET_TIMEOUT );
    463422}
    464423
     
    501460}
    502461
     462/* libevent says that timer_msec have passed, so wake up libcurl */
     463static void
     464libevent_timer_cb( int fd UNUSED, short what UNUSED, void * g )
     465{
     466    dbgmsg( "libevent timer is done" );
     467    tr_multi_perform( g, CURL_SOCKET_TIMEOUT );
     468}
    503469
    504470/* libcurl documentation: "If 0, it means you should proceed immediately
     
    507473 * before you call curl_multi_perform() again."  */
    508474static void
    509 multi_timer_cb( CURLM *multi UNUSED, long timer_ms, void * vg )
     475multi_timer_cb( CURLM * multi UNUSED, long timer_msec, void * vg )
    510476{
    511477    tr_web * g = vg;
    512478
    513     if( timer_ms < 1 ) {
    514         if( timer_ms == 0 ) /* call it immediately */
    515             timer_cb( 0, 0, g );
    516         timer_ms = DEFAULT_TIMER_MSEC;
    517     }
    518 
    519     g->timer_ms = timer_ms;
     479    if( timer_msec < 1 ) {
     480        if( timer_msec == 0 ) /* call it immediately */
     481            libevent_timer_cb( 0, 0, g );
     482        timer_msec = DEFAULT_TIMER_MSEC;
     483    }
     484
     485    g->timer_msec = timer_msec;
    520486    restart_timer( g );
    521487}
     
    534500    if( session->web )
    535501    {
     502        struct tr_web_task * task;
    536503        static unsigned long tag = 0;
    537         struct tr_web_task * task;
    538504
    539505        task = tr_new0( struct tr_web_task, 1 );
     
    560526tr_webInit( tr_session * session )
    561527{
    562     CURLMcode mcode;
     528    tr_web * web;
    563529    static int curlInited = FALSE;
    564     tr_web * web;
    565530
    566531    /* call curl_global_init if we haven't done it already.
     
    576541    web->multi = curl_multi_init( );
    577542    web->session = session;
    578     web->timer_ms = DEFAULT_TIMER_MSEC; /* overwritten by multi_timer_cb() */
    579 
    580     evtimer_set( &web->timer_event, timer_cb, web );
    581     mcode = curl_multi_setopt( web->multi, CURLMOPT_SOCKETDATA, web );
    582     tr_assert( mcode == CURLM_OK, "curl_mutli_setopt() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
    583     mcode = curl_multi_setopt( web->multi, CURLMOPT_SOCKETFUNCTION, sock_cb );
    584     tr_assert( mcode == CURLM_OK, "curl_mutli_setopt() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
    585     mcode = curl_multi_setopt( web->multi, CURLMOPT_TIMERDATA, web );
    586     tr_assert( mcode == CURLM_OK, "curl_mutli_setopt() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
    587     mcode = curl_multi_setopt( web->multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb );
    588     tr_assert( mcode == CURLM_OK, "curl_mutli_setopt() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
     543    web->timer_msec = DEFAULT_TIMER_MSEC; /* overwritten by multi_timer_cb() */
     544
     545    evtimer_set( &web->timer_event, libevent_timer_cb, web );
     546    curl_multi_setopt( web->multi, CURLMOPT_SOCKETDATA, web );
     547    curl_multi_setopt( web->multi, CURLMOPT_SOCKETFUNCTION, sock_cb );
     548    curl_multi_setopt( web->multi, CURLMOPT_TIMERDATA, web );
     549    curl_multi_setopt( web->multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb );
    589550
    590551    return web;
Note: See TracChangeset for help on using the changeset viewer.