Changeset 2998


Ignore:
Timestamp:
Sep 9, 2007, 3:50:57 PM (14 years ago)
Author:
charles
Message:

tweaks to yesterday's checker rewrite -- easier to call and use now.

Location:
branches/encryption/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/encryption/libtransmission/inout.c

    r2992 r2998  
    338338    tr_torrent * torrent;
    339339    tr_recheck_done_cb recheck_done_cb;
     340    run_status_t status_when_done;
    340341};
     342
     343static void
     344fireCheckDone( tr_torrent          * torrent,
     345               tr_recheck_done_cb    recheck_done_cb,
     346               run_status_t          status_when_done )
     347{
     348    torrent->runStatus = status_when_done;
     349    (*recheck_done_cb)( torrent );
     350}
    341351
    342352struct recheck_node currentNode;
     
    365375        tr_free( node );
    366376
    367         if( tor->uncheckedPieces == NULL )
     377        if( tor->uncheckedPieces == NULL ) {
     378            fireCheckDone( tor, currentNode.recheck_done_cb, currentNode.status_when_done );
    368379            continue;
     380        }
     381
     382        tor->runStatus = TR_RUN_CHECKING;
    369383
    370384        /* remove the unchecked pieces from completion... */
     
    384398        }
    385399
    386         if( stopCurrent )
    387         {
    388             stopCurrent = FALSE;
    389             (currentNode.recheck_done_cb)( tor, TR_RECHECK_ABORTED );
    390         }
    391         else
     400        if( !stopCurrent )
    392401        {
    393402            tr_bitfieldFree( tor->uncheckedPieces );
    394403            tor->uncheckedPieces = NULL;
    395             tor->fastResumeDirty = TRUE;
    396             (currentNode.recheck_done_cb)( tor, TR_RECHECK_DONE );
    397404        }
     405        stopCurrent = FALSE;
     406        tor->fastResumeDirty = TRUE;
     407        fireCheckDone( tor, currentNode.recheck_done_cb, currentNode.status_when_done );
    398408    }
    399409
     
    403413void
    404414tr_ioRecheckAdd( tr_torrent          * tor,
    405                  tr_recheck_done_cb    recheck_done_cb )
     415                 tr_recheck_done_cb    recheck_done_cb,
     416                 run_status_t          status_when_done )
    406417{
    407418    if( tor->uncheckedPieces == NULL )
    408419    {
    409         (*recheck_done_cb)(tor, TR_RECHECK_DONE );
     420        fireCheckDone( tor, recheck_done_cb, status_when_done );
    410421    }
    411422    else
     
    415426        node->torrent = tor;
    416427        node->recheck_done_cb = recheck_done_cb;
     428        node->status_when_done = status_when_done;
    417429        tr_list_append( &recheckList, node );
     430
     431        tor->runStatus = TR_RUN_CHECKING_WAIT;
    418432
    419433        if( recheckThread == NULL )
     
    440454        struct recheck_node * node = tr_list_remove( &recheckList, &tmp, compareRecheckByTorrent );
    441455        if( node != NULL ) {
    442             (node->recheck_done_cb)( tor, TR_RECHECK_ABORTED );
     456            fireCheckDone( tor, node->recheck_done_cb, node->status_when_done );
    443457            tr_free( node );
    444458        }
  • branches/encryption/libtransmission/inout.h

    r2988 r2998  
    6666**/
    6767
    68 typedef enum
    69 {
    70    TR_RECHECK_DONE,
    71    TR_RECHECK_ABORTED
    72 }
    73 RecheckState;
    74 
    75 typedef void (*tr_recheck_done_cb)(tr_torrent * tor, int recheckState );
     68typedef void (*tr_recheck_done_cb)( tr_torrent * tor );
    7669
    7770void tr_ioRecheckAdd( tr_torrent          * tor,
    78                       tr_recheck_done_cb    recheck_done_cb );
     71                      tr_recheck_done_cb    recheck_done_cb,
     72                      run_status_t          status_when_done );
    7973
    8074void tr_ioRecheckRemove( tr_torrent * tor );
  • branches/encryption/libtransmission/internal.h

    r2988 r2998  
    9292typedef enum
    9393{
    94     TR_RUN_CHECKING           = (1<<0), /* checking files' checksums */
    95     TR_RUN_RUNNING            = (1<<1), /* seeding or leeching */
    96     TR_RUN_STOPPING           = (1<<2), /* stopping */
    97     TR_RUN_STOPPING_NET_WAIT  = (1<<3), /* waiting on network -- we're
     94    TR_RUN_CHECKING_WAIT      = (1<<0), /* waiting to be checked */
     95    TR_RUN_CHECKING           = (1<<1), /* checking files' checksums */
     96    TR_RUN_RUNNING            = (1<<2), /* seeding or leeching */
     97    TR_RUN_STOPPING           = (1<<3), /* stopping */
     98    TR_RUN_STOPPING_NET_WAIT  = (1<<4), /* waiting on network -- we're
    9899                                           telling tracker we've stopped */
    99     TR_RUN_STOPPED            = (1<<4)  /* stopped */
     100    TR_RUN_STOPPED            = (1<<5)  /* stopped */
    100101}
    101102run_status_t;
     
    140141    volatile char              dieFlag;
    141142    struct tr_bitfield       * uncheckedPieces;
    142     run_status_t               runStatusAfterCheck;
    143143    run_status_t               runStatus;
    144144    run_status_t               runStatusToSave;
  • branches/encryption/libtransmission/peer-msgs.c

    r2987 r2998  
    7373    READING_BT_PIECE
    7474};
    75 
    76 static const char *
    77 getStateName( int state )
    78 {
    79     switch( state )
    80     {
    81         case AWAITING_BT_LENGTH: return "awaiting bt length";
    82         case AWAITING_BT_MESSAGE: return "awaiting bt message";
    83         case READING_BT_PIECE: return "reading bt piece";
    84     }
    85 
    86     fprintf (stderr, "PeerManager::getStateName: unhandled state %d\n", state );
    87     abort( );
    88 }
    8975
    9076struct peer_request
     
    714700    tr_peermsgs * peer = (tr_peermsgs *) vpeer;
    715701    struct evbuffer * inbuf = EVBUFFER_INPUT ( evin );
    716     fprintf( stderr, "peer %p got a canRead; state is [%s]\n", peer, getStateName(peer->state) );
    717702
    718703    switch( peer->state )
  • branches/encryption/libtransmission/torrent.c

    r2989 r2998  
    265265
    266266static void
    267 recheckDoneCB( tr_torrent * tor, int recheckState UNUSED )
    268 {
    269 fprintf( stderr, "recheck done -- setting torrent %s to %d\n", tor->info.name, tor->runStatusAfterCheck );
     267recheckDoneCB( tr_torrent * tor )
     268{
    270269    tr_peerMgrUpdateCompletion( tor->handle->peerMgr, tor->info.hash );
    271     tor->runStatus = tor->runStatusAfterCheck;
    272270    fastResumeSave( tor );
    273271
     
    413411    tr_sharedUnlock( h->shared );
    414412
    415     tor->runStatusAfterCheck = tor->runStatus;
    416     tor->runStatus = TR_RUN_CHECKING;
    417     tr_ioRecheckAdd( tor, recheckDoneCB );
     413    tr_ioRecheckAdd( tor, recheckDoneCB, tor->runStatus );
    418414}
    419415
     
    760756    s->left = tr_cpLeftUntilDone( tor->completion );
    761757
    762     if( tor->uncheckedPieces )
    763         s->status = tor->runStatus==TR_RUN_CHECKING
    764             ? TR_STATUS_CHECK
    765             : TR_STATUS_CHECK_WAIT;
    766     else switch( tor->runStatus ) {
     758    switch( tor->runStatus ) {
     759        case TR_RUN_CHECKING_WAIT: s->status = TR_STATUS_CHECK_WAIT; break;
     760        case TR_RUN_CHECKING: s->status = TR_STATUS_CHECK; break;
    767761        case TR_RUN_STOPPING: /* fallthrough */
    768762        case TR_RUN_STOPPING_NET_WAIT: s->status = TR_STATUS_STOPPING; break;
    769763        case TR_RUN_STOPPED: s->status = TR_STATUS_STOPPED; break;
    770         case TR_RUN_CHECKING: s->status = TR_STATUS_CHECK; break;
    771764        case TR_RUN_RUNNING: switch( tor->cpStatus ) {
    772765            case TR_CP_INCOMPLETE: s->status = TR_STATUS_DOWNLOAD; break;
     
    985978    tr_bitfieldAddRange( tor->uncheckedPieces, 0, tor->info.pieceCount );
    986979
    987     tor->runStatusAfterCheck = tor->runStatus;
    988     tor->runStatus = TR_RUN_CHECKING;
    989     tr_ioRecheckAdd( tor, recheckDoneCB );
     980    tr_ioRecheckAdd( tor, recheckDoneCB, tor->runStatus );
    990981}
    991982
     
    10401031tr_torrentStart( tr_torrent * tor )
    10411032{
    1042     tor->runStatusAfterCheck = TR_RUN_RUNNING;
    1043     tor->runStatus = TR_RUN_CHECKING;
    1044     tr_ioRecheckAdd( tor, recheckDoneCB );
     1033    tr_ioRecheckAdd( tor, recheckDoneCB, TR_RUN_RUNNING );
    10451034}
    10461035
Note: See TracChangeset for help on using the changeset viewer.