Changeset 9652


Ignore:
Timestamp:
Dec 2, 2009, 3:16:29 PM (12 years ago)
Author:
charles
Message:

(trunk libT) minor tweaks: make bencode's int parser code more consistent; make some comments more readable

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r9651 r9652  
    131131}
    132132
     133/* format: hostname + ':' + port */
    133134static char *
    134135getHostName( const char * url )
     
    426427tierIncrementTracker( tr_tier * tier )
    427428{
     429    /* move our index to the next tracker in the tier */
    428430    const int i = ( tier->currentTrackerIndex + 1 )
    429431                        % tr_ptrArraySize( &tier->trackers );
     
    14571459              void         * vdata )
    14581460{
     1461    tr_bool success = FALSE;
    14591462    tr_announcer * announcer = session->announcer;
    14601463    struct announce_data * data = vdata;
    14611464    tr_tier * tier = getTier( announcer, data->torrentId, data->tierId );
    14621465    const time_t now = tr_time( );
    1463     tr_bool success = FALSE;
    14641466
    14651467    if( announcer )
     
    15331535tierScrape( tr_announcer * announcer, tr_tier * tier )
    15341536{
     1537    char * url;
    15351538    const char * scrape;
    1536     struct evbuffer * buf;
    15371539    struct announce_data * data;
    15381540    const time_t now = tr_time( );
     
    15491551    scrape = tier->currentTracker->scrape;
    15501552
    1551     buf = evbuffer_new( );
    1552     evbuffer_add_printf( buf, "%s%cinfo_hash=%s",
    1553                          scrape,
    1554                          strchr( scrape, '?' ) ? '&' : '?',
    1555                          tier->tor->info.hashEscaped );
     1553    url = tr_strdup_printf( "%s%cinfo_hash=%s",
     1554                            scrape,
     1555                            strchr( scrape, '?' ) ? '&' : '?',
     1556                            tier->tor->info.hashEscaped );
    15561557
    15571558    tier->isScraping = TRUE;
    15581559    tier->lastScrapeStartTime = now;
    15591560    --announcer->scrapeSlotsAvailable;
    1560     dbgmsg( tier, "scraping \"%s\"", (const char*)EVBUFFER_DATA(buf) );
    1561     tr_webRun( announcer->session, (const char*)EVBUFFER_DATA(buf), NULL, onScrapeDone, data );
    1562 
    1563     evbuffer_free( buf );
     1561    dbgmsg( tier, "scraping \"%s\"", url );
     1562    tr_webRun( announcer->session, url, NULL, onScrapeDone, data );
     1563
     1564    tr_free( url );
    15641565}
    15651566
  • trunk/libtransmission/bencode.c

    r9032 r9652  
    8484                 int64_t *        setme_val )
    8585{
    86     int          err = 0;
    8786    char *       endptr;
    8887    const void * begin;
     
    103102    val = evutil_strtoll( begin, &endptr, 10 );
    104103    if( errno || ( endptr != end ) ) /* incomplete parse */
    105         err = EILSEQ;
    106     else if( val && *(const char*)begin == '0' ) /* no leading zeroes! */
    107         err = EILSEQ;
    108     else
    109     {
    110         *setme_end = (const uint8_t*)end + 1;
    111         *setme_val = val;
    112     }
    113 
    114     return err;
     104        return EILSEQ;
     105    if( val && *(const char*)begin == '0' ) /* no leading zeroes! */
     106        return EILSEQ;
     107
     108    *setme_end = (const uint8_t*)end + 1;
     109    *setme_val = val;
     110    return 0;
    115111}
    116112
  • trunk/libtransmission/peer-mgr.c

    r9651 r9652  
    956956    }
    957957
    958     /* We almost always change only a handful of pieces in the array.
    959      * In these cases, it's cheaper to sort those changed pieces and merge,
    960      * than qsort()ing the whole array again */
     958    /* In most cases we've just changed the weights of a small number of pieces.
     959     * So rather than qsort()ing the entire array, it's faster to sort just the
     960     * changed ones, then do a standard merge-two-sorted-arrays pass on the
     961     * changed and unchanged pieces. */
    961962    if( got > 0 )
    962963    {
     
    968969        struct weighted_piece * b_end = t->pieces + t->pieceCount;
    969970
    970         /* rescore the pieces that we changed */
     971        /* resort the pieces that we changed */
    971972        weightTorrent = t->tor;
    972973        qsort( a, a_end-a, sizeof( struct weighted_piece ), comparePieceByWeight );
Note: See TracChangeset for help on using the changeset viewer.