Changeset 7546


Ignore:
Timestamp:
Dec 30, 2008, 8:25:39 AM (12 years ago)
Author:
charles
Message:

(trunk libT) use a static buffer for fillOutputBuffer()

File:
1 edited

Legend:

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

    r7540 r7546  
    7878    PEX_INTERVAL            = ( 90 * 1000 ), /* msec between sendPex() calls */
    7979
    80     MAX_QUEUE_SIZE          = ( 100 ),
     80
     81    MAX_BLOCK_SIZE          = ( 1024 * 16 ),
     82
    8183
    8284    /* how long an unsent request can stay queued before it's returned
     
    868870
    869871static void
    870 expireOldRequests( tr_peermsgs * msgs, const time_t now  )
     872expireFromList( tr_peermsgs          * msgs,
     873                struct request_list  * list,
     874                const time_t           oldestAllowed )
    871875{
    872876    int i;
    873     time_t oldestAllowed;
    874     struct request_list tmp = REQUEST_LIST_INIT;
    875     const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
    876     dbgmsg( msgs, "entering `expire old requests' block" );
    877 
    878     /* cancel requests that have been queued for too long */
    879     oldestAllowed = now - QUEUED_REQUEST_TTL_SECS;
    880     reqListCopy( &tmp, &msgs->clientWillAskFor );
    881     for( i=0; i<tmp.count; ++i ) {
    882         const struct peer_request * req = &tmp.requests[i];
     877
     878    /* walk through the list, looking for the first req that's too old */
     879    for( i=0; i<list->count; ++i ) {
     880        const struct peer_request * req = &list->requests[i];
    883881        if( req->time_requested < oldestAllowed )
    884             tr_peerMsgsCancel( msgs, req->index, req->offset, req->length );
    885     }
    886     reqListClear( &tmp );
    887 
    888     /* if the peer doesn't support "Reject Request",
    889      * cancel requests that were sent too long ago. */
    890     if( !fext ) {
    891         oldestAllowed = now - SENT_REQUEST_TTL_SECS;
    892         reqListCopy( &tmp, &msgs->clientAskedFor );
    893         for( i=0; i<tmp.count; ++i ) {
     882            break;
     883    }
     884
     885    /* if we found one too old, start pruning them */
     886    if( i < list->count ) {
     887        struct request_list tmp = REQUEST_LIST_INIT;
     888        reqListCopy( &tmp, list );
     889        for( ; i<tmp.count; ++i ) {
    894890            const struct peer_request * req = &tmp.requests[i];
    895891            if( req->time_requested < oldestAllowed )
     
    897893        }
    898894        reqListClear( &tmp );
     895    }
     896}
     897
     898static void
     899expireOldRequests( tr_peermsgs * msgs, const time_t now  )
     900{
     901    time_t oldestAllowed;
     902    const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
     903    dbgmsg( msgs, "entering `expire old requests' block" );
     904
     905    /* cancel requests that have been queued for too long */
     906    oldestAllowed = now - QUEUED_REQUEST_TTL_SECS;
     907    expireFromList( msgs, &msgs->clientWillAskFor, oldestAllowed );
     908
     909    /* if the peer doesn't support "Reject Request",
     910     * cancel requests that were sent too long ago. */
     911    if( !fext ) {
     912        oldestAllowed = now - SENT_REQUEST_TTL_SECS;
     913        expireFromList( msgs, &msgs->clientAskedFor, oldestAllowed );
    899914    }
    900915
     
    18181833            && tr_cpPieceIsComplete( msgs->torrent->completion, req.index ) )
    18191834        {
     1835            int err;
     1836            static uint8_t * buf = NULL;
     1837            static struct evbuffer * out = NULL;
     1838
     1839            if( buf == NULL )
     1840                buf = tr_new( uint8_t, MAX_BLOCK_SIZE );
     1841            if( out == NULL )
     1842                out = evbuffer_new( );
     1843
     1844            assert( !EVBUFFER_LENGTH( out ) );
     1845
    18201846            /* send a block */
    1821             uint8_t * buf = tr_new( uint8_t, req.length );
    1822             const int err = tr_ioRead( msgs->torrent, req.index, req.offset, req.length, buf );
    1823             if( err ) {
     1847            if(( err = tr_ioRead( msgs->torrent, req.index, req.offset, req.length, buf ))) {
    18241848                fireError( msgs, err );
    18251849                bytesWritten = 0;
     
    18271851            } else {
    18281852                tr_peerIo * io = msgs->peer->io;
    1829                 struct evbuffer * out = evbuffer_new( );
    18301853                dbgmsg( msgs, "sending block %u:%u->%u", req.index, req.offset, req.length );
    18311854                tr_peerIoWriteUint32( io, out, sizeof( uint8_t ) + 2 * sizeof( uint32_t ) + req.length );
     
    18361859                tr_peerIoWriteBuf( io, out, TRUE );
    18371860                bytesWritten += EVBUFFER_LENGTH( out );
    1838                 evbuffer_free( out );
    18391861                msgs->clientSentAnythingAt = now;
    18401862            }
    1841             tr_free( buf );
    18421863        }
    18431864        else if( fext ) /* peer needs a reject message */
Note: See TracChangeset for help on using the changeset viewer.