1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

add extra state change checks

This commit is contained in:
Charles Kerr 2007-07-19 03:48:27 +00:00
parent ad63c84b47
commit 615afaa445

View file

@ -981,6 +981,27 @@ tr_torrentFree( tr_torrent_t * tor )
tr_sharedUnlock( h->shared );
}
static void
recheckCpState( tr_torrent_t * tor )
{
cp_status_t cpStatus;
tr_torrentWriterLock( tor );
cpStatus = tr_cpGetStatus( tor->completion );
if( cpStatus != tor->cpStatus ) {
tor->cpStatus = cpStatus;
tor->hasChangedState = tor->cpStatus; /* tell the client... */
if( (cpStatus == TR_CP_COMPLETE) /* ...and if we're complete */
&& tor->tracker!=NULL /* and we have a tracker */
&& tor->downloadedCur ) { /* and it just happened */
tr_trackerCompleted( tor->tracker ); /* tell the tracker */
}
tr_ioSync( tor->io );
}
tr_torrentWriterUnlock( tor );
}
static void
torrentThreadLoop ( void * _tor )
{
@ -997,14 +1018,14 @@ torrentThreadLoop ( void * _tor )
/* loop until the torrent is being deleted */
while( ! ( tor->dieFlag && (tor->runStatus == TR_RUN_STOPPED) ) )
{
cp_status_t cpStatus;
/* sleep a little while */
tr_wait( tor->runStatus == TR_RUN_STOPPED ? 1600 : 600 );
if( tor->fastResumeDirty ) {
if( tor->fastResumeDirty )
{
tor->fastResumeDirty = FALSE;
fastResumeSave( tor );
recheckCpState( tor );
}
/* if we're stopping... */
@ -1108,19 +1129,7 @@ torrentThreadLoop ( void * _tor )
}
/* refresh our completion state */
tr_torrentWriterLock( tor );
cpStatus = tr_cpGetStatus( tor->completion );
if( cpStatus != tor->cpStatus ) {
tor->cpStatus = cpStatus;
tor->hasChangedState = tor->cpStatus; /* tell the client... */
if( (cpStatus == TR_CP_COMPLETE) /* ...and if we're complete */
&& tor->tracker!=NULL /* and we have a tracker */
&& tor->downloadedCur ) { /* and it just happened */
tr_trackerCompleted( tor->tracker ); /* tell the tracker */
}
tr_ioSync( tor->io );
}
tr_torrentWriterUnlock( tor );
recheckCpState( tor );
/* ping the tracker... */
tr_trackerPulse( tor->tracker, &peerCount, &peerCompact );