Changeset 12367


Ignore:
Timestamp:
Apr 17, 2011, 6:13:22 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) more heap pruning: don't allocate peer-msgs' incoming block buffer until it's needed. If we're seeding, we won't need it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-msgs.c

    r12366 r12367  
    13071307    {
    13081308        int err;
     1309        size_t n;
     1310        size_t nLeft;
     1311        struct evbuffer * block_buffer;
     1312
     1313        if( msgs->incoming.block == NULL )
     1314            msgs->incoming.block = evbuffer_new( );
     1315        block_buffer = msgs->incoming.block;
    13091316
    13101317        /* read in another chunk of data */
    1311         const size_t nLeft = req->length - evbuffer_get_length( msgs->incoming.block );
    1312         size_t n = MIN( nLeft, inlen );
    1313 
    1314         tr_peerIoReadBytesToBuf( msgs->peer->io, inbuf, msgs->incoming.block, n );
     1318        nLeft = req->length - evbuffer_get_length( block_buffer );
     1319        n = MIN( nLeft, inlen );
     1320
     1321        tr_peerIoReadBytesToBuf( msgs->peer->io, inbuf, block_buffer, n );
    13151322
    13161323        fireClientGotData( msgs, n, true );
     
    13181325        dbgmsg( msgs, "got %zu bytes for block %u:%u->%u ... %d remain",
    13191326               n, req->index, req->offset, req->length,
    1320                (int)( req->length - evbuffer_get_length( msgs->incoming.block ) ) );
    1321         if( evbuffer_get_length( msgs->incoming.block ) < req->length )
     1327               (int)( req->length - evbuffer_get_length( block_buffer ) ) );
     1328        if( evbuffer_get_length( block_buffer ) < req->length )
    13221329            return READ_LATER;
    13231330
    13241331        /* pass the block along... */
    1325         err = clientGotBlock( msgs, msgs->incoming.block, req );
    1326         evbuffer_drain( msgs->incoming.block, evbuffer_get_length( msgs->incoming.block ) );
     1332        err = clientGotBlock( msgs, block_buffer, req );
     1333        evbuffer_drain( block_buffer, evbuffer_get_length( block_buffer ) );
    13271334
    13281335        /* cleanup */
     
    23422349    m->outMessagesBatchedAt = 0;
    23432350    m->outMessagesBatchPeriod = LOW_PRIORITY_INTERVAL_SECS;
    2344     m->incoming.block = evbuffer_new( );
    23452351    peer->msgs = m;
    23462352
     
    23842390            event_free( msgs->pexTimer );
    23852391
    2386         evbuffer_free( msgs->incoming.block );
     2392        if( msgs->incoming.block != NULL )
     2393            evbuffer_free( msgs->incoming.block );
     2394
    23872395        evbuffer_free( msgs->outMessages );
    23882396        tr_free( msgs->pex6 );
Note: See TracChangeset for help on using the changeset viewer.