Changeset 2430
- Timestamp:
- Jul 19, 2007, 11:54:37 AM (16 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/internal.h
r2428 r2430 86 86 #endif 87 87 88 /* Sometimes the system defines MAX/MIN, sometimes not. In the latter89 case, define those here since we will use them */90 #ifndef MAX91 #define MAX(a,b) ((a)>(b)?(a):(b))92 #endif93 #ifndef MIN94 #define MIN(a,b) ((a)>(b)?(b):(a))95 #endif96 97 88 #define TR_MAX_PEER_COUNT 60 98 89 99 90 typedef struct tr_completion_s tr_completion_t; 100 91 typedef struct tr_shared_s tr_shared_t; 101 typedef struct tr_bitfield_s tr_bitfield_t;102 92 103 93 typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t; … … 130 120 void tr_torrentWriterLock ( tr_torrent_t * ); 131 121 void tr_torrentWriterUnlock ( tr_torrent_t * ); 122 123 #define tr_blockPiece(a) _tr_blockPiece(tor,a) 124 int _tr_blockPiece( const tr_torrent_t * tor, int block ); 125 126 #define tr_blockSize(a) _tr_blockSize(tor,a) 127 int _tr_blockSize( const tr_torrent_t * tor, int block ); 128 129 #define tr_blockPosInPiece(a) _tr_blockPosInPiece(tor,a) 130 int _tr_blockPosInPiece( const tr_torrent_t * tor, int block ); 131 132 #define tr_pieceCountBlocks(a) _tr_pieceCountBlocks(tor,a) 133 int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece ); 134 135 #define tr_pieceStartBlock(a) _tr_pieceStartBlock(tor,a) 136 int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece ); 137 138 #define tr_pieceSize(a) _tr_pieceSize(tor,a) 139 int _tr_pieceSize( const tr_torrent_t * tor, int piece ); 140 141 #define tr_block(a,b) _tr_block(tor,a,b) 142 int _tr_block( const tr_torrent_t * tor, int index, int begin ); 143 132 144 133 145 typedef enum -
trunk/libtransmission/torrent.c
r2423 r2430 1335 1335 tr_torrentSetFileDL( tor, files[i], doDownload ); 1336 1336 } 1337 1338 /*** 1339 **** 1340 ***/ 1341 1342 int _tr_blockPiece( const tr_torrent_t * tor, int block ) 1343 { 1344 const tr_info_t * inf = &tor->info; 1345 return block / ( inf->pieceSize / tor->blockSize ); 1346 } 1347 1348 int _tr_blockSize( const tr_torrent_t * tor, int block ) 1349 { 1350 const tr_info_t * inf = &tor->info; 1351 int dummy; 1352 1353 if( block != tor->blockCount - 1 || 1354 !( dummy = inf->totalSize % tor->blockSize ) ) 1355 { 1356 return tor->blockSize; 1357 } 1358 1359 return dummy; 1360 } 1361 1362 int _tr_blockPosInPiece( const tr_torrent_t * tor, int block ) 1363 { 1364 const tr_info_t * inf = &tor->info; 1365 return tor->blockSize * 1366 ( block % ( inf->pieceSize / tor->blockSize ) ); 1367 } 1368 1369 int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece ) 1370 { 1371 const tr_info_t * inf = &tor->info; 1372 if( piece < inf->pieceCount - 1 || 1373 !( tor->blockCount % ( inf->pieceSize / tor->blockSize ) ) ) 1374 { 1375 return inf->pieceSize / tor->blockSize; 1376 } 1377 return tor->blockCount % ( inf->pieceSize / tor->blockSize ); 1378 } 1379 1380 int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece ) 1381 { 1382 const tr_info_t * inf = &tor->info; 1383 return piece * ( inf->pieceSize / tor->blockSize ); 1384 } 1385 1386 int _tr_pieceSize( const tr_torrent_t * tor, int piece ) 1387 { 1388 const tr_info_t * inf = &tor->info; 1389 if( piece < inf->pieceCount - 1 || 1390 !( inf->totalSize % inf->pieceSize ) ) 1391 { 1392 return inf->pieceSize; 1393 } 1394 return inf->totalSize % inf->pieceSize; 1395 } 1396 1397 int _tr_block( const tr_torrent_t * tor, int index, int begin ) 1398 { 1399 const tr_info_t * inf = &tor->info; 1400 return index * ( inf->pieceSize / tor->blockSize ) + 1401 begin / tor->blockSize; 1402 } -
trunk/libtransmission/utils.c
r2429 r2430 24 24 25 25 #include <ctype.h> 26 #include <errno.h> 26 27 #include <stdarg.h> 28 #include <stdio.h> 29 #include <stdlib.h> 30 #include <string.h> 31 27 32 #include <sys/time.h> 28 33 #include <sys/types.h> … … 32 37 #include "transmission.h" 33 38 #include "trcompat.h" 39 #include "utils.h" 40 #include "platform.h" 34 41 35 42 #define SPRINTF_BUFSIZE 100 … … 696 703 #endif 697 704 } 698 699 /***700 ****701 ***/702 703 int _tr_blockPiece( const tr_torrent_t * tor, int block )704 {705 const tr_info_t * inf = &tor->info;706 return block / ( inf->pieceSize / tor->blockSize );707 }708 709 int _tr_blockSize( const tr_torrent_t * tor, int block )710 {711 const tr_info_t * inf = &tor->info;712 int dummy;713 714 if( block != tor->blockCount - 1 ||715 !( dummy = inf->totalSize % tor->blockSize ) )716 {717 return tor->blockSize;718 }719 720 return dummy;721 }722 723 int _tr_blockPosInPiece( const tr_torrent_t * tor, int block )724 {725 const tr_info_t * inf = &tor->info;726 return tor->blockSize *727 ( block % ( inf->pieceSize / tor->blockSize ) );728 }729 730 int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece )731 {732 const tr_info_t * inf = &tor->info;733 if( piece < inf->pieceCount - 1 ||734 !( tor->blockCount % ( inf->pieceSize / tor->blockSize ) ) )735 {736 return inf->pieceSize / tor->blockSize;737 }738 return tor->blockCount % ( inf->pieceSize / tor->blockSize );739 }740 741 int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece )742 {743 const tr_info_t * inf = &tor->info;744 return piece * ( inf->pieceSize / tor->blockSize );745 }746 747 int _tr_pieceSize( const tr_torrent_t * tor, int piece )748 {749 const tr_info_t * inf = &tor->info;750 if( piece < inf->pieceCount - 1 ||751 !( inf->totalSize % inf->pieceSize ) )752 {753 return inf->pieceSize;754 }755 return inf->totalSize % inf->pieceSize;756 }757 758 int _tr_block( const tr_torrent_t * tor, int index, int begin )759 {760 const tr_info_t * inf = &tor->info;761 return index * ( inf->pieceSize / tor->blockSize ) +762 begin / tor->blockSize;763 } -
trunk/libtransmission/utils.h
r2399 r2430 27 27 28 28 #include <stdarg.h> 29 #include <stdint.h> 29 30 30 31 void tr_msgInit( void ); … … 33 34 #define tr_inf( a... ) tr_msg( TR_MSG_INF, ## a ) 34 35 #define tr_dbg( a... ) tr_msg( TR_MSG_DBG, ## a ) 35 void tr_msg ( int level, char * msg, ... ) PRINTF( 2, 3 );36 void tr_msg ( int level, char * msg, ... ); 36 37 37 38 int tr_rand ( int ); … … 62 63 **********************************************************************/ 63 64 int tr_sprintf( char ** buf, int * used, int * max, 64 const char * format, ... ) PRINTF( 4, 5 );65 const char * format, ... ); 65 66 /* gee, it sure would be nice if BeOS had va_copy() */ 66 67 int tr_vsprintf( char **, int *, int *, const char *, va_list, va_list ); … … 85 86 void tr_wait( uint64_t delay_milliseconds ); 86 87 87 #define tr_blockPiece(a) _tr_blockPiece(tor,a) 88 int _tr_blockPiece( const tr_torrent_t * tor, int block ); 88 /*** 89 **** 90 ***/ 89 91 90 #define tr_blockSize(a) _tr_blockSize(tor,a) 91 int _tr_blockSize( const tr_torrent_t * tor, int block ); 92 93 #define tr_blockPosInPiece(a) _tr_blockPosInPiece(tor,a) 94 int _tr_blockPosInPiece( const tr_torrent_t * tor, int block ); 95 96 #define tr_pieceCountBlocks(a) _tr_pieceCountBlocks(tor,a) 97 int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece ); 98 99 #define tr_pieceStartBlock(a) _tr_pieceStartBlock(tor,a) 100 int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece ); 101 102 #define tr_pieceSize(a) _tr_pieceSize(tor,a) 103 int _tr_pieceSize( const tr_torrent_t * tor, int piece ); 104 105 #define tr_block(a,b) _tr_block(tor,a,b) 106 int _tr_block( const tr_torrent_t * tor, int index, int begin ); 92 /* Sometimes the system defines MAX/MIN, sometimes not. In the latter 93 case, define those here since we will use them */ 94 #ifndef MAX 95 #define MAX(a,b) ((a)>(b)?(a):(b)) 96 #endif 97 #ifndef MIN 98 #define MIN(a,b) ((a)>(b)?(b):(a)) 99 #endif 107 100 108 101 /*** … … 129 122 ***/ 130 123 131 struct tr_bitfield_s124 typedef struct tr_bitfield_s 132 125 { 133 126 uint8_t * bits; 134 127 size_t len; 135 }; 128 } 129 tr_bitfield_t; 136 130 137 131 tr_bitfield_t* tr_bitfieldNew( size_t bitcount ); -
trunk/libtransmission/xml.c
r2311 r2430 23 23 *****************************************************************************/ 24 24 25 #include "transmission.h" 25 #include <assert.h> 26 #include <string.h> 27 #include <stdlib.h> 28 29 #include "utils.h" 26 30 #include "xml.h" 27 31
Note: See TracChangeset
for help on using the changeset viewer.