Changeset 5683


Ignore:
Timestamp:
Apr 24, 2008, 7:38:59 PM (14 years ago)
Author:
charles
Message:

maybe work on libcurl < 7.16.3

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/trevent.c

    r5673 r5683  
    122122        {
    123123            case TR_EV_TIMER_ADD:
    124                 timeout_add( &cmd->timer->event, &cmd->timer->tv );
     124                evtimer_add( &cmd->timer->event, &cmd->timer->tv );
    125125                ++eh->timerCount;
    126126                break;
     
    139139
    140140    if( !doDie )
    141         timeout_add( &eh->pulse, &eh->pulseInterval );
     141        evtimer_add( &eh->pulse, &eh->pulseInterval );
    142142    else {
    143143        assert( eh->timerCount ==  0 );
     
    168168    eh->base = event_init( );
    169169    event_set_log_callback( logFunc );
    170     timeout_set( &eh->pulse, pumpList, veh );
    171     timeout_add( &eh->pulse, &eh->pulseInterval );
     170    evtimer_set( &eh->pulse, pumpList, veh );
     171    evtimer_add( &eh->pulse, &eh->pulseInterval );
    172172    eh->h->events = eh;
    173173
     
    254254
    255255    if( more )
    256         timeout_add( &timer->event, &timer->tv );
     256        evtimer_add( &timer->event, &timer->tv );
    257257    else
    258258        tr_timerFree( &timer );
     
    287287             timer_func         func,
    288288             void             * user_data,
    289              uint64_t           timeout_milliseconds )
     289             uint64_t           interval_milliseconds )
    290290{
    291291    tr_timer * timer = tr_new0( tr_timer, 1 );
    292     timer->tv = tr_timevalMsec( timeout_milliseconds );
     292    timer->tv = tr_timevalMsec( interval_milliseconds );
    293293    timer->func = func;
    294294    timer->user_data = user_data;
    295295    timer->eh = handle->events;
    296     timeout_set( &timer->event, timerCallback, timer );
     296    evtimer_set( &timer->event, timerCallback, timer );
    297297
    298298    if( tr_amInThread( handle->events->thread ) ) {
    299         timeout_add( &timer->event,  &timer->tv );
     299        evtimer_add( &timer->event,  &timer->tv );
    300300        ++handle->events->timerCount;
    301301    } else {
  • trunk/libtransmission/web.c

    r5673 r5683  
    1 /*
    2  * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
     1/* * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
    32 *
    43 * This file is licensed by the GPL version 2.  Works owned by the
     
    1817#include "web.h"
    1918
     19#define CURL_CHECK_VERSION(major,minor,micro)    \
     20    (LIBCURL_VERSION_MAJOR > (major) || \
     21     (LIBCURL_VERSION_MAJOR == (major) && LIBCURL_VERSION_MINOR > (minor)) || \
     22     (LIBCURL_VERSION_MAJOR == (major) && LIBCURL_VERSION_MINOR == (minor) && \
     23      LIBCURL_VERSION_PATCH >= (micro)))
     24
     25#if CURL_CHECK_VERSION(7,16,0)
     26#define HAVE_CURL_MULTI_SOCKET
     27#else
     28#define PULSE_MSEC 200
     29static void pulse( int socket UNUSED, short action UNUSED, void * vweb );
     30#endif
     31
    2032struct tr_web
    2133{
     
    2335    tr_session * session;
    2436    int remain;
    25     struct event timeout;
     37    struct event timer;
    2638};
    2739
     
    4355}
    4456
     57static void
     58pump( tr_web * web )
     59{
     60    CURLMcode rc;
     61    do {
     62#if HAVE_CURL_MULTI_SOCKET
     63        rc = curl_multi_socket_all( web->cm, &web->remain );
     64#else
     65        rc = curl_multi_perform( web->cm, &web->remain );
     66#endif
     67fprintf( stderr, "remaining: %d\n", web->remain );
     68    } while( rc == CURLM_CALL_MULTI_PERFORM );
     69}
     70
    4571void
    4672tr_webRun( tr_session         * session,
     
    5379    struct tr_web * web = session->web;
    5480    CURL * ch;
    55     CURLMcode rc;
    5681
    5782    task = tr_new0( struct tr_web_task, 1 );
     
    7398    curl_multi_add_handle( web->cm, ch );
    7499
    75     do {
    76         int tmp;
    77         rc = curl_multi_socket_all( web->cm, &tmp );
    78     } while( rc == CURLM_CALL_MULTI_PERFORM );
     100    pump( web );
     101
     102#if !HAVE_CURL_MULTI_SOCKET
     103    if( !evtimer_initialized( &web->timer ) )
     104    {
     105        struct timeval tv = tr_timevalMsec( PULSE_MSEC );
     106        evtimer_set( &web->timer, pulse, web );
     107        fprintf( stderr, "no timer running yet... starting one\n" );
     108        evtimer_add( &web->timer, &tv );
     109    }
     110#endif
    79111}
    80112
     
    114146    }
    115147    while( remaining );
    116 }
    117 
     148
     149    /* remove timeout if there are no transfers left */
     150    if( !web->remain && evtimer_initialized( &web->timer ) )
     151        evtimer_del( &web->timer );
     152}
     153
     154#if HAVE_CURL_MULTI_SOCKET
    118155/* libevent says that sock is ready to be processed, so wake up libcurl */
    119156static void
     
    146183
    147184    responseHandler( web );
    148 
    149     /* remove timeout if there are no transfers left */
    150     if( !web->remain
    151         && event_initialized( &web->timeout )
    152         && event_pending( &web->timeout, EV_TIMEOUT, NULL ) ) {
    153             event_del( &web->timeout );
    154             fprintf( stderr, "Removed timeout\n" );
    155     }
    156185}
    157186
     
    218247    struct timeval tv = tr_timevalMsec( timeout_ms );
    219248
    220     if( event_initialized( &web->timeout )
    221         && event_pending( &web->timeout, EV_TIMEOUT, NULL ) )
    222             event_del( &web->timeout );
    223 
    224     event_set( &web->timeout, -1, 0, timeout_callback, vweb );
    225     event_add( &web->timeout, &tv );
    226 }
     249    if( evtimer_initialized( &web->timeout ) )
     250        evtimer_del( &web->timeout );
     251
     252    evtimer_set( &web->timer, timeout_callback, vweb );
     253    evtimer_add( &web->timer, &tv );
     254}
     255#else
     256
     257static void
     258pulse( int socket UNUSED, short action UNUSED, void * vweb )
     259{
     260    tr_web * web = vweb;
     261
     262    pump( web );
     263    responseHandler( web );
     264
     265    if( web->remain > 0 ) {
     266        struct timeval tv = tr_timevalMsec( PULSE_MSEC );
     267        evtimer_add( &web->timer, &tv );
     268    }
     269}
     270
     271#endif
    227272
    228273tr_web*
     
    246291    web->remain = 0;
    247292
     293#if HAVE_CURL_MULTI_SOCKET
    248294    curl_multi_setopt( web->cm, CURLMOPT_SOCKETDATA, web );
    249295    curl_multi_setopt( web->cm, CURLMOPT_SOCKETFUNCTION, socket_callback );
    250296    curl_multi_setopt( web->cm, CURLMOPT_TIMERDATA, web );
    251297    curl_multi_setopt( web->cm, CURLMOPT_TIMERFUNCTION, timer_callback );
     298#endif
     299#if CURL_CHECK_VERSION(7,16,3)
    252300    curl_multi_setopt( web->cm, CURLMOPT_MAXCONNECTS, 20 );
     301#endif
     302#if CURL_CHECK_VERSION(7,16,0)
    253303    curl_multi_setopt( web->cm, CURLMOPT_PIPELINING, 1 );
     304#endif
    254305
    255306    return web;
Note: See TracChangeset for help on using the changeset viewer.