Changeset 12183


Ignore:
Timestamp:
Mar 17, 2011, 1:16:23 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) as a followup to r12182, move LPD's periodic upkeep timer into the tr-lpd.c module where it can be started & stopped with the pre-existing tr_lpdInit() and tr_lpdUninit() functions.

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r12182 r12183  
    623623    tr_dhtUpkeep( session );
    624624
    625     /* lpd upkeep */
    626     if( session->lpdUpkeepAt <= now ) {
    627         const int LPD_UPKEEP_INTERVAL_SECS = 5;
    628         session->lpdUpkeepAt = now + LPD_UPKEEP_INTERVAL_SECS;
    629         tr_lpdAnnounceMore( now, LPD_UPKEEP_INTERVAL_SECS );
    630     }
    631 
    632625    if( session->turtle.isClockEnabled )
    633626        turtleCheckClock( session, &session->turtle );
  • trunk/libtransmission/session.h

    r12182 r12183  
    143143    struct event                 *udp6_event;
    144144
    145     time_t                       lpdUpkeepAt;
    146 
    147145    /* The open port on the local machine for incoming peer requests */
    148146    tr_port                      private_peer_port;
  • trunk/libtransmission/tr-lpd.c

    r12177 r12183  
    7070static void event_callback( int, short, void* );
    7171
     72enum {
     73   UPKEEP_INTERVAL_SECS = 5
     74};
     75static struct event * upkeep_timer = NULL;
     76
    7277static int lpd_socket; /**<separate multicast receive socket */
    7378static int lpd_socket2; /**<and multicast send socket */
     
    251256* @} */
    252257
     258static void on_upkeep_timer( int, short, void * );
     259
    253260/**
    254261* @brief Initializes Local Peer Discovery for this node
     
    342349    lpd_event = event_new( ss->event_base, lpd_socket, EV_READ | EV_PERSIST, event_callback, NULL );
    343350    event_add( lpd_event, NULL );
     351
     352    upkeep_timer = evtimer_new( ss->event_base, on_upkeep_timer, ss );
     353    tr_timerAdd( upkeep_timer, UPKEEP_INTERVAL_SECS, 0 );
    344354
    345355    tr_ndbg( "LPD", "Local Peer Discovery initialised" );
     
    371381    event_free( lpd_event );
    372382    lpd_event = NULL;
     383
     384    evtimer_del( upkeep_timer );
     385    upkeep_timer = NULL;
    373386
    374387    /* just shut down, we won't remember any former nodes */
     
    540553* Further, by setting interval to zero (or negative) the caller may actually disable LPD
    541554* announces on a per-interval basis.
    542 */
    543 int tr_lpdAnnounceMore( const time_t now, const int interval )
     555*
     556* FIXME: since this function's been made private and is called by a periodic timer,
     557* most of the previous paragraph isn't true anymore... we weren't using that functionality
     558* before. are there cases where we should? if not, should we remove the bells & whistles?
     559*/
     560static int
     561tr_lpdAnnounceMore( const time_t now, const int interval )
    544562{
    545563    tr_torrent* tor = NULL;
     
    599617}
    600618
     619static void
     620on_upkeep_timer( int foo UNUSED, short bar UNUSED, void * vsession UNUSED )
     621{
     622    const time_t now = tr_time( );
     623    tr_lpdAnnounceMore( now, UPKEEP_INTERVAL_SECS );
     624    tr_timerAdd( upkeep_timer, UPKEEP_INTERVAL_SECS, 0 );
     625}
     626
    601627/**
    602628* @brief Processing of timeout notifications and incoming data on the socket
  • trunk/libtransmission/tr-lpd.h

    r11599 r12183  
    3737tr_bool tr_lpdSendAnnounce( const tr_torrent* );
    3838
    39 int tr_lpdAnnounceMore( const time_t, const int );
    40 
    4139/**
    4240* @defgroup Preproc Helper macros
Note: See TracChangeset for help on using the changeset viewer.