1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

let fastresume remember which torrents are stopped and which are running.

This commit is contained in:
Charles Kerr 2007-08-13 16:43:33 +00:00
parent ab57bfb2d2
commit 7254a96ce8
2 changed files with 39 additions and 4 deletions

View file

@ -92,7 +92,12 @@ enum
* uint32_t: ul speed rate to use when the mode is single
* uint32_t: ul's tr_speedlimit_t
*/
FR_ID_SPEED = 8
FR_ID_SPEED = 8,
/* active
* char: 't' if running, 'f' if paused
*/
FR_ID_RUN = 9
};
@ -148,8 +153,12 @@ getMTimes( const tr_torrent_t * tor, int * setme_n )
return m;
}
static void fastResumeWriteData( uint8_t id, void * data, uint32_t size,
uint32_t count, FILE * file )
static void
fastResumeWriteData( uint8_t id,
const void * data,
uint32_t size,
uint32_t count,
FILE * file )
{
uint32_t datalen = size * count;
@ -261,6 +270,11 @@ tr_fastResumeSave( const tr_torrent_t * tor )
tr_free( buf );
}
if( TRUE ) /* FR_ID_RUN */
{
const char is_running = (tor->runStatus == TR_RUN_RUNNING) ? 't' : 'f';
fastResumeWriteData( FR_ID_RUN, &is_running, 1, 1, file );
}
/* Write download and upload totals */
total = tor->downloadedCur + tor->downloadedPrev;
@ -556,6 +570,19 @@ fastResumeLoadImpl ( tr_torrent_t * tor,
}
break;
case FR_ID_RUN:
{
char ch;
if( fread( &ch, 1, 1, file ) != 1 )
{
fclose( file );
return ret;
}
tor->runStatus = ch=='f' ? TR_RUN_STOPPED : TR_RUN_RUNNING;
ret |= TR_FR_RUN;
continue;
}
case FR_ID_DOWNLOADED:
/* read download total */
if( 8 == len)

View file

@ -288,10 +288,18 @@ torrentRealInit( tr_handle_t * h,
assert( !tor->uploadedCur );
tor->error = TR_OK;
tor->runStatus = flags & TR_FLAG_PAUSED ? TR_RUN_STOPPED : TR_RUN_RUNNING;
uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount );
loaded = tr_fastResumeLoad( tor, uncheckedPieces );
/* the `paused' flag has highest precedence...
after that, the fastresume setting is used...
if that's not found, default to RUNNING */
if( flags & TR_FLAG_PAUSED )
tor->runStatus = TR_RUN_STOPPED;
else if( !(loaded & TR_FR_RUN ) )
tor->runStatus = TR_RUN_RUNNING;
if( tr_bitfieldIsEmpty( uncheckedPieces ) )
tr_bitfieldFree( uncheckedPieces );
else