Ignore:
Timestamp:
Apr 3, 2008, 9:38:32 PM (14 years ago)
Author:
charles
Message:

hack on IPC a bit because it's been too long since I broke it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r5329 r5498  
    9595tr_cpEnsureDoneValid( const tr_completion * ccp )
    9696{
    97     const tr_torrent * tor = ccp->tor;
    98     const tr_info * info = &tor->info;
    99     uint64_t have=0, total=0;
    100     tr_piece_index_t i;
    101     tr_completion * cp ;
    102 
    103     if( !ccp->doneDirty )
    104         return;
    105 
    106     /* too bad C doesn't have 'mutable' */
    107     cp = (tr_completion*) ccp;
    108     cp->doneDirty = FALSE;
    109 
    110     for( i=0; i<info->pieceCount; ++i ) {
    111         if( !info->pieces[i].dnd ) {
    112             total += info->pieceSize;
    113             have += cp->completeBlocks[ i ];
     97    if( ccp->doneDirty )
     98    {
     99        const tr_torrent * tor = ccp->tor;
     100        const tr_info * info = &tor->info;
     101        uint64_t have = 0;
     102        uint64_t total = 0;
     103        tr_piece_index_t i;
     104        tr_completion * cp ;
     105
     106        /* too bad C doesn't have 'mutable' */
     107        cp = (tr_completion*) ccp;
     108        cp->doneDirty = FALSE;
     109
     110        for( i=0; i<info->pieceCount; ++i ) {
     111            if( !info->pieces[i].dnd ) {
     112                total += info->pieceSize;
     113                have += cp->completeBlocks[ i ];
     114            }
    114115        }
     116
     117        have *= tor->blockSize;
     118
     119        /* the last piece/block is probably smaller than the others */
     120        if( !info->pieces[info->pieceCount-1].dnd ) {
     121            total -= ( info->pieceSize - tr_torPieceCountBytes(tor,info->pieceCount-1) );
     122            if( tr_cpBlockIsComplete( cp, tor->blockCount-1 ) )
     123                have -= ( tor->blockSize - tr_torBlockCountBytes(tor,tor->blockCount-1) );
     124        }
     125
     126        assert( have <= total );
     127        assert( total <= info->totalSize );
     128
     129        cp->doneHave = have;
     130        cp->doneTotal = total;
    115131    }
    116 
    117     have *= tor->blockSize;
    118 
    119     /* the last piece/block is probably smaller than the others */
    120     if( !info->pieces[info->pieceCount-1].dnd ) {
    121         total -= ( info->pieceSize - tr_torPieceCountBytes(tor,info->pieceCount-1) );
    122         if( tr_cpBlockIsComplete( cp, tor->blockCount-1 ) )
    123             have -= ( tor->blockSize - tr_torBlockCountBytes(tor,tor->blockCount-1) );
    124     }
    125 
    126     assert( have <= total );
    127     assert( total <= info->totalSize );
    128 
    129     cp->doneHave = have;
    130     cp->doneTotal = total;
    131132}
    132133
     
    312313    tr_cpEnsureDoneValid( cp );
    313314
    314     if( cp->doneHave >= cp->doneTotal )
    315         return TR_CP_DONE;
    316 
    317     return TR_CP_INCOMPLETE;
     315    return cp->doneHave >= cp->doneTotal ? TR_CP_DONE
     316                                         : TR_CP_INCOMPLETE;
    318317}
    319318
Note: See TracChangeset for help on using the changeset viewer.