Changeset 2377
- Timestamp:
- Jul 16, 2007, 7:57:34 PM (15 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/fastresume.c
r2348 r2377 234 234 235 235 static int 236 fastResumeLoadPriorities( tr_torrent_t * tor,237 236 loadPriorities( tr_torrent_t * tor, 237 FILE * file ) 238 238 { 239 239 const size_t n = tor->info.fileCount; 240 240 const size_t len = 2 * n; 241 int *dnd = NULL, dndCount = 0; 242 int *dl = NULL, dlCount = 0; 241 243 char * buf = tr_new0( char, len ); 242 244 char * walk = buf; … … 262 264 263 265 /* set the dnd flags */ 264 for( i=0; i<n; ++i ) { 265 int j; 266 const char ch = *walk++; 267 tr_file_t * file = &tor->info.files[i]; 268 file->dnd = ch == 't'; 269 for( j=file->firstPiece; j<=file->lastPiece; ++j ) 270 tor->info.pieces[j].dnd = file->dnd; 271 } 272 273 free( buf ); 266 dl = tr_new( int, len ); 267 dnd = tr_new( int, len ); 268 for( i=0; i<n; ++i ) 269 if( *walk++ == 't' ) /* 't' means the DND flag is true */ 270 dnd[dndCount++] = i; 271 else 272 dl[dlCount++] = i; 273 274 if( dndCount ) 275 tr_torrentSetFileDLs ( tor, dnd, dndCount, FALSE ); 276 if( dlCount ) 277 tr_torrentSetFileDLs ( tor, dl, dlCount, TRUE ); 278 279 tr_free( dnd ); 280 tr_free( dl ); 281 tr_free( buf ); 274 282 return TR_OK; 275 283 } … … 427 435 if( len == (uint32_t)(2 * tor->info.fileCount) ) 428 436 { 429 ret = fastResumeLoadPriorities( tor, file );437 ret = loadPriorities( tor, file ); 430 438 431 439 if( ret && ( feof(file) || ferror(file) ) ) -
trunk/libtransmission/internal.h
r2374 r2377 205 205 uint64_t startDate; 206 206 uint64_t stopDate; 207 int ioLoaded; 207 char ioLoaded; 208 char fastResumeDirty; 208 209 209 210 int peerCount; … … 218 219 uint8_t pexDisabled; 219 220 221 int8_t statCur; 220 222 tr_stat_t stats[2]; 221 int statCur;222 223 223 224 tr_torrent_t * next; -
trunk/libtransmission/torrent.c
r2374 r2377 993 993 /* sleep a little while */ 994 994 tr_wait( tor->runStatus == TR_RUN_STOPPED ? 1600 : 600 ); 995 996 if( tor->fastResumeDirty ) { 997 tor->fastResumeDirty = FALSE; 998 fastResumeSave( tor ); 999 } 995 1000 996 1001 /* if we're stopping... */ … … 1158 1163 1159 1164 1160 /*** 1161 **** 1162 **** File prioritization 1163 **** 1164 ***/ 1165 1166 static void 1167 tr_torrentSetFilePriorityImpl( tr_torrent_t * tor, 1168 int fileIndex, 1169 tr_priority_t priority, 1170 int doSave ) 1165 /** 1166 *** File priorities 1167 **/ 1168 1169 void 1170 tr_torrentSetFilePriority( tr_torrent_t * tor, 1171 int fileIndex, 1172 tr_priority_t priority ) 1171 1173 { 1172 1174 int i; … … 1188 1190 priority, tor->info.files[fileIndex].name ); 1189 1191 1190 if( doSave ) 1191 fastResumeSave( tor ); 1192 tor->fastResumeDirty = TRUE; 1192 1193 1193 1194 tr_torrentWriterUnlock( tor ); 1194 }1195 1196 void1197 tr_torrentSetFilePriority( tr_torrent_t * tor,1198 int fileIndex,1199 tr_priority_t priority )1200 {1201 tr_torrentSetFilePriorityImpl( tor, fileIndex, priority, TRUE );1202 1195 } 1203 1196 … … 1209 1202 { 1210 1203 int i; 1211 for( i=0; i<fileCount; ++i ) { 1212 const int fileIndex = files[i]; 1213 tr_torrentSetFilePriorityImpl( tor, fileIndex, priority, FALSE ); 1214 } 1215 fastResumeSave( tor ); 1204 for( i=0; i<fileCount; ++i ) 1205 tr_torrentSetFilePriority( tor, files[i], priority ); 1216 1206 } 1217 1207 … … 1246 1236 } 1247 1237 1238 /** 1239 *** File DND 1240 **/ 1241 1248 1242 int 1249 1243 tr_torrentGetFileDL( const tr_torrent_t * tor, 1250 1244 int file ) 1251 1245 { 1252 int do _download;1246 int doDownload; 1253 1247 tr_torrentReaderLock( tor ); 1254 1248 1255 1249 assert( 0<=file && file<tor->info.fileCount ); 1256 do _download = !tor->info.files[file].dnd;1250 doDownload = !tor->info.files[file].dnd; 1257 1251 1258 1252 tr_torrentReaderUnlock( tor ); 1259 return do _download != 0;1253 return doDownload != 0; 1260 1254 } 1261 1255 … … 1263 1257 tr_torrentSetFileDL( tr_torrent_t * tor, 1264 1258 int fileIndex, 1265 int do_download ) 1266 { 1259 int doDownload ) 1260 { 1261 const tr_file_t * file; 1262 const int dnd = !doDownload; 1263 int firstPiece, firstPieceDND; 1264 int lastPiece, lastPieceDND; 1267 1265 int i; 1268 tr_file_t * file;1269 const int dnd = !do_download;1270 1266 1271 1267 tr_torrentWriterLock( tor ); 1272 1268 1273 assert( 0<=fileIndex && fileIndex<tor->info.fileCount );1274 1269 file = &tor->info.files[fileIndex]; 1275 file->dnd = dnd; 1276 for( i=file->firstPiece; i<=file->lastPiece; ++i ) 1277 tor->info.pieces[i].dnd = dnd; 1278 fastResumeSave( tor ); 1270 firstPiece = file->firstPiece; 1271 lastPiece = file->lastPiece; 1272 1273 /* can't set the first piece to DND unless 1274 every file using that piece is DND */ 1275 firstPieceDND = dnd; 1276 for( i=fileIndex-1; firstPieceDND && i>=0; --i ) { 1277 if( tor->info.files[i].lastPiece != firstPiece ) 1278 break; 1279 firstPieceDND = tor->info.files[i].dnd; 1280 } 1281 1282 /* can't set the last piece to DND unless 1283 every file using that piece is DND */ 1284 lastPieceDND = dnd; 1285 for( i=fileIndex+1; lastPieceDND && i<tor->info.fileCount; ++i ) { 1286 if( tor->info.files[i].firstPiece != lastPiece ) 1287 break; 1288 lastPieceDND = tor->info.files[i].dnd; 1289 } 1290 1291 if( firstPiece == lastPiece ) 1292 { 1293 tor->info.pieces[firstPiece].dnd = firstPieceDND && lastPieceDND; 1294 } 1295 else 1296 { 1297 tor->info.pieces[firstPiece].dnd = firstPieceDND; 1298 tor->info.pieces[lastPiece].dnd = lastPieceDND; 1299 for( i=firstPiece+1; i<lastPiece-1; ++i ) 1300 tor->info.pieces[i].dnd = dnd; 1301 } 1302 1303 tor->fastResumeDirty = TRUE; 1279 1304 1280 1305 tr_torrentWriterUnlock( tor ); … … 1285 1310 int * files, 1286 1311 int fileCount, 1287 int do_download ) 1288 { 1289 int i, j; 1290 const int dnd = !do_download; 1291 1292 tr_torrentWriterLock( tor ); 1293 1294 for( i=0; i<fileCount; ++i ) { 1295 const int fileIndex = files[i]; 1296 tr_file_t * file = &tor->info.files[fileIndex]; 1297 file->dnd = dnd; 1298 for( j=file->firstPiece; j<=file->lastPiece; ++j ) 1299 tor->info.pieces[j].dnd = dnd; 1300 } 1301 1302 fastResumeSave( tor ); 1303 1304 tr_torrentWriterUnlock( tor ); 1305 } 1312 int doDownload ) 1313 { 1314 int i; 1315 for( i=0; i<fileCount; ++i ) 1316 tr_torrentSetFileDL( tor, files[i], doDownload ); 1317 }
Note: See TracChangeset
for help on using the changeset viewer.