Changeset 2388 for trunk/libtransmission/fastresume.c
- Timestamp:
- Jul 18, 2007, 5:27:45 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/fastresume.c
r2387 r2388 51 51 typedef uint64_t tr_time_t; 52 52 53 /* deprecated */ 54 #define FR_ID_PROGRESS_SLOTS 0x01 55 /* number of bytes downloaded */ 56 #define FR_ID_DOWNLOADED 0x02 57 /* number of bytes uploaded */ 58 #define FR_ID_UPLOADED 0x03 59 /* IPs and ports of connectable peers */ 60 #define FR_ID_PEERS 0x04 61 /* progress data: 62 * - 4 bytes * number of files: mtimes of files 63 * - 1 bit * number of blocks: whether we have the block or not 64 */ 65 #define FR_ID_PROGRESS 0x05 66 /* dnd and priority 67 * char * number of files: l,n,h for low, normal, high priority 68 * char * number of files: t,f for DND flags 69 */ 70 #define FR_ID_PRIORITY 0x06 53 enum 54 { 55 /* deprecated */ 56 FR_ID_PROGRESS_SLOTS = 1, 57 58 /* number of bytes downloaded */ 59 FR_ID_DOWNLOADED = 2, 60 61 /* number of bytes uploaded */ 62 FR_ID_UPLOADED = 3, 63 64 /* IPs and ports of connectable peers */ 65 FR_ID_PEERS = 4, 66 67 /* progress data: 68 * - 4 bytes * number of files: mtimes of files 69 * - 1 bit * number of blocks: whether we have the block or not */ 70 FR_ID_PROGRESS = 5, 71 72 /* dnd and priority 73 * char * number of files: l,n,h for low, normal, high priority 74 * char * number of files: t,f for DND flags */ 75 FR_ID_PRIORITY = 6, 76 77 /* transfer speeds 78 * uint32_t: the dl speed rate to use when the flag is true 79 * char: t,f for whether or not dl speed is capped 80 * uint32_t: the ul speed rate to use when the flag is true 81 * char: t,f for whether or not ul speed is capped 82 */ 83 FR_ID_SPEED = 7 84 }; 85 71 86 72 87 /* macros for the length of various pieces of the progress data */ … … 210 225 211 226 227 /* Write the torrent ul/dl speed caps */ 228 if( TRUE ) 229 { 230 const int len = ( sizeof(uint32_t) + sizeof(char) ) * 2; 231 char * buf = tr_new0( char, len ); 232 char * walk = buf; 233 char enabled; 234 uint32_t i; 235 236 i = (uint32_t) tr_torrentGetMaxSpeedDL( tor ); 237 memcpy( walk, &i, 4 ); walk += 4; 238 enabled = tr_torrentIsMaxSpeedEnabledDL( tor ) ? 't' : 'f'; 239 *walk++ = enabled; 240 241 i = (uint32_t) tr_torrentGetMaxSpeedUL( tor ); 242 memcpy( walk, &i, 4 ); walk += 4; 243 enabled = tr_torrentIsMaxSpeedEnabledUL( tor ) ? 't' : 'f'; 244 *walk++ = enabled; 245 246 assert( walk - buf == len ); 247 fastResumeWriteData( FR_ID_SPEED, buf, 1, walk-buf, file ); 248 } 249 250 212 251 /* Write download and upload totals */ 213 252 total = tor->downloadedCur + tor->downloadedPrev; … … 232 271 tr_dbg( "Resume file '%s' written", path ); 233 272 } 273 274 static int 275 loadSpeeds( tr_torrent_t * tor, FILE * file ) 276 { 277 const size_t len = 2 * (sizeof(uint32_t) + sizeof(char)); 278 char * buf = tr_new0( char, len ); 279 char * walk = buf; 280 uint32_t rate; 281 char enabled; 282 283 if( len != fread( buf, 1, len, file ) ) { 284 tr_inf( "Couldn't read from resume file" ); 285 free( buf ); 286 return TR_ERROR_IO_OTHER; 287 } 288 289 memcpy( &rate, walk, 4 ); walk += 4; 290 memcpy( &enabled, walk, 1 ); walk += 1; 291 tr_torrentSetMaxSpeedDL( tor, rate ); 292 tr_torrentEnableMaxSpeedDL( tor, enabled=='t' ); 293 294 memcpy( &rate, walk, 4 ); walk += 4; 295 memcpy( &enabled, walk, 1 ); walk += 1; 296 tr_torrentSetMaxSpeedUL( tor, rate ); 297 tr_torrentEnableMaxSpeedUL( tor, enabled=='t' ); 298 299 tr_free( buf ); 300 return TR_OK; 301 } 302 234 303 235 304 static int … … 436 505 { 437 506 ret = loadPriorities( tor, file ); 507 508 if( ret && ( feof(file) || ferror(file) ) ) 509 { 510 fclose( file ); 511 return 1; 512 } 513 514 continue; 515 } 516 break; 517 518 case FR_ID_SPEED: 519 /* read speed data */ 520 if( len == (uint32_t)(2*sizeof(uint32_t)+2) ) 521 { 522 ret = loadSpeeds( tor, file ); 438 523 439 524 if( ret && ( feof(file) || ferror(file) ) )
Note: See TracChangeset
for help on using the changeset viewer.