Changeset 8697


Ignore:
Timestamp:
Jun 15, 2009, 2:22:41 AM (13 years ago)
Author:
charles
Message:

(trunk libT) a minor but nice twofer: reduce per-peer memory overhead a little bit, and also avoid an extra malloc/free per peer connection

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r8689 r8697  
    3030#include "torrent.h"
    3131#include "tr-dht.h"
    32 #include "trevent.h"
    3332#include "utils.h"
    3433
     
    6665
    6766    /* how long to wait before giving up on a handshake */
    68     HANDSHAKE_TIMEOUT_MSEC         = 60 * 1000
     67    HANDSHAKE_TIMEOUT_SEC          = 60
    6968};
    7069
     
    119118    handshakeDoneCB       doneCB;
    120119    void *                doneUserData;
    121     tr_timer *            timeout;
     120    struct event          timeout_timer;
    122121};
    123122
     
    11131112        tr_peerIoUnref( handshake->io ); /* balanced by the ref in tr_handshakeNew */
    11141113
    1115     tr_timerFree( &handshake->timeout );
     1114    evtimer_del( &handshake->timeout_timer );
    11161115
    11171116    tr_free( handshake );
     
    11751174**/
    11761175
    1177 static int
    1178 handshakeTimeout( void * handshake )
     1176static void
     1177handshakeTimeout( int foo UNUSED, short bar UNUSED, void * handshake )
    11791178{
    11801179    tr_handshakeAbort( handshake );
    1181     return FALSE;
    11821180}
    11831181
     
    11881186                 void *             doneUserData )
    11891187{
     1188    struct timeval tv;
    11901189    tr_handshake * handshake;
    11911190
     
    11971196    handshake->doneUserData = doneUserData;
    11981197    handshake->session = tr_peerIoGetSession( io );
    1199     handshake->timeout = tr_timerNew( handshake->session, handshakeTimeout, handshake, HANDSHAKE_TIMEOUT_MSEC );
     1198
     1199    tr_timevalSet( &tv, HANDSHAKE_TIMEOUT_SEC, 0 );
     1200    evtimer_set( &handshake->timeout_timer, handshakeTimeout, handshake );
     1201    evtimer_add( &handshake->timeout_timer, &tv );
    12001202
    12011203    tr_peerIoRef( io ); /* balanced by the unref in tr_handshakeFree */
  • trunk/libtransmission/peer-msgs.c

    r8692 r8697  
    3838#include "torrent.h"
    3939#include "tr-dht.h"
    40 #include "trevent.h"
    4140#include "utils.h"
    4241#include "version.h"
     
    7877    KEEPALIVE_INTERVAL_SECS = 100,
    7978
    80     PEX_INTERVAL            = ( 90 * 1000 ), /* msec between sendPex() calls */
     79    PEX_INTERVAL_SECS       = 90, /* sec between sendPex() calls */
    8180
    8281
     
    177176    struct request_list    clientWillAskFor;
    178177
    179     tr_timer             * pexTimer;
    180178    tr_pex               * pex;
    181179    tr_pex               * pex6;
     
    193191       value is zero and should be ignored. */
    194192    int64_t               reqq;
     193
     194    struct event          pexTimer;
    195195};
    196196
     
    21142114}
    21152115
    2116 static TR_INLINE int
    2117 pexPulse( void * vpeer )
    2118 {
    2119     sendPex( vpeer );
    2120     return TRUE;
     2116static void
     2117pexPulse( int foo UNUSED, short bar UNUSED, void * vmsgs )
     2118{
     2119    struct timeval tv;
     2120    struct tr_peermsgs * msgs = vmsgs;
     2121
     2122    sendPex( msgs );
     2123
     2124    tr_timevalSet( &tv, PEX_INTERVAL_SECS, 0 );
     2125    evtimer_add( &msgs->pexTimer, &tv );
    21212126}
    21222127
     
    21332138{
    21342139    tr_peermsgs * m;
     2140    struct timeval tv;
    21352141
    21362142    assert( peer );
     
    21482154    m->peer->have = tr_bitfieldNew( torrent->info.pieceCount );
    21492155    m->state = AWAITING_BT_LENGTH;
    2150     m->pexTimer = tr_timerNew( m->session, pexPulse, m, PEX_INTERVAL );
    21512156    m->outMessages = evbuffer_new( );
    21522157    m->outMessagesBatchedAt = 0;
     
    21562161    m->clientAskedFor = REQUEST_LIST_INIT;
    21572162    m->clientWillAskFor = REQUEST_LIST_INIT;
     2163    tr_timevalSet( &tv, PEX_INTERVAL_SECS, 0 );
     2164    evtimer_set( &m->pexTimer, pexPulse, m );
     2165    evtimer_add( &m->pexTimer, &tv );
    21582166    peer->msgs = m;
    21592167
     
    21792187    if( msgs )
    21802188    {
    2181         tr_timerFree( &msgs->pexTimer );
     2189        evtimer_del( &msgs->pexTimer );
    21822190        tr_publisherDestruct( &msgs->publisher );
    21832191        reqListClear( &msgs->clientWillAskFor );
Note: See TracChangeset for help on using the changeset viewer.