Changeset 3032


Ignore:
Timestamp:
Sep 10, 2007, 7:05:05 PM (15 years ago)
Author:
charles
Message:
  • get torrent-stopping working a little better.
  • tr_torrentStop() now works for torrents being checked or queued to be checked
File:
1 edited

Legend:

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

    r3028 r3032  
    149149***/
    150150
    151 static void tr_torrentHasStopped( tr_torrent * );
    152 
    153151static void
    154152onTrackerResponse( void * tracker UNUSED, void * vevent, void * user_data )
     
    180178
    181179        case TR_TRACKER_STOPPED:
    182             assert( tor->runStatus == TR_RUN_STOPPING_NET_WAIT );
    183             tr_torrentHasStopped( tor );
     180            assert( tor->runStatus == TR_RUN_STOPPING );
     181            tor->runStatus = TR_RUN_STOPPED;
    184182            break;
    185183    }
     
    786784        case TR_RUN_CHECKING_WAIT: s->status = TR_STATUS_CHECK_WAIT; break;
    787785        case TR_RUN_CHECKING: s->status = TR_STATUS_CHECK; break;
    788         case TR_RUN_STOPPING: /* fallthrough */
    789         case TR_RUN_STOPPING_NET_WAIT: s->status = TR_STATUS_STOPPING; break;
     786        case TR_RUN_STOPPING: s->status = TR_STATUS_STOPPING; break;
    790787        case TR_RUN_STOPPED: s->status = TR_STATUS_STOPPED; break;
    791788        case TR_RUN_RUNNING: switch( tor->cpStatus ) {
     
    10251022    tr_info_t * inf = &tor->info;
    10261023
     1024    assert( tor != NULL );
     1025    assert( tor->runStatus == TR_RUN_STOPPED );
     1026
    10271027    tr_sharedLock( h->shared );
    10281028
     
    10631063}
    10641064
    1065 static void
    1066 tr_torrentHasStopped( tr_torrent * tor )
    1067 {
    1068     /* close the IO */
    1069     tr_ioClose( tor );
    1070     saveFastResumeNow( tor );
    1071 
    1072     /* free everything */
    1073     if( tor->dieFlag )
    1074         tr_torrentFree( tor );
     1065static int
     1066freeWhenStopped( void * vtor )
     1067{
     1068    tr_torrent * tor = vtor;
     1069
     1070    if( tor->runStatus != TR_RUN_STOPPED ) /* keep waiting */
     1071        return TRUE;
     1072
     1073    tr_torrentFree( tor );
     1074    return FALSE;
    10751075}
    10761076
     
    10781078tr_torrentStop( tr_torrent * tor )
    10791079{
    1080     if( tor->runStatus==TR_RUN_STOPPING || tor->runStatus==TR_RUN_STOPPED )
    1081         return;
    1082 
    1083     /* close the peers */
    1084     tr_peerMgrStopTorrent( tor->handle->peerMgr, tor->info.hash );
    1085 
    1086     /* tell the tracker we're stopping */
    1087     tor->runStatus = TR_RUN_STOPPING_NET_WAIT;
    1088     tor->stopDate = tr_date();
    1089     tr_trackerStop( tor->tracker );
    1090 }
    1091 
    1092 void tr_torrentClose( tr_torrent * tor )
     1080    switch( tor->runStatus )
     1081    {
     1082        case TR_RUN_CHECKING_WAIT:
     1083        case TR_RUN_CHECKING:
     1084            tr_ioRecheckRemove( tor );
     1085            tr_torrentStop( tor );
     1086            break;
     1087
     1088        case TR_RUN_RUNNING:
     1089            saveFastResumeNow( tor );
     1090            tr_peerMgrStopTorrent( tor->handle->peerMgr, tor->info.hash );
     1091            tor->runStatus = TR_RUN_STOPPING;
     1092            tor->stopDate = tr_date( );
     1093            tr_trackerStop( tor->tracker );
     1094            tr_ioClose( tor );
     1095            break;
     1096
     1097        case TR_RUN_STOPPING:
     1098        case TR_RUN_STOPPED:
     1099            break;
     1100    }
     1101}
     1102
     1103void
     1104tr_torrentClose( tr_torrent * tor )
    10931105{
    10941106    tor->runStatusToSave = tor->runStatus;
     
    10961108    tor->dieFlag = TRUE;
    10971109    tr_torrentStop( tor );
     1110    tr_timerNew( tor->handle, freeWhenStopped, tor, NULL, 100 );
    10981111}
    10991112
Note: See TracChangeset for help on using the changeset viewer.