Changeset 7813
- Timestamp:
- Jan 29, 2009, 6:18:24 PM (12 years ago)
- Location:
- branches/1.5x
- Files:
-
- 35 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.5x/daemon/daemon.c
r7689 r7813 67 67 { 'u', "username", "Set username for authentication", "u", 1, "<username>" }, 68 68 { 'v', "password", "Set password for authentication", "v", 1, "<password>" }, 69 { 'V', "version", "Show version number and exit", "V", 0, NULL }, 69 70 { 'w', "download-dir", "Where to save downloaded data", "w", 1, "<path>" }, 70 71 { 'P', "peerport", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "P", 1, "<port>" }, … … 216 217 case 'g': /* handled above */ 217 218 break; 219 case 'V': /* version */ 220 fprintf(stderr, "Transmission %s\n", LONG_VERSION_STRING); 221 exit( 0 ); 218 222 case 'p': tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_PORT, atoi( optarg ) ); 219 223 break; -
branches/1.5x/daemon/remote.c
r7767 r7813 23 23 24 24 #include <libevent/event.h> 25 26 #define CURL_DISABLE_TYPECHECK /* otherwise -Wunreachable-code goes insane */ 25 27 #include <curl/curl.h> 26 28 … … 37 39 #define DEFAULT_PORT atoi(TR_DEFAULT_RPC_PORT_STR) 38 40 39 enum { TAG_ LIST, TAG_DETAILS, TAG_FILES, TAG_PEERS };41 enum { TAG_SESSION, TAG_LIST, TAG_DETAILS, TAG_FILES, TAG_PEERS }; 40 42 41 43 static const char* … … 80 82 { 'r', "remove", "Remove the current torrent(s)", "r", 0, NULL }, 81 83 { 'R', "remove-and-delete", "Remove the current torrent(s) and delete local data", NULL, 0, NULL }, 84 { 920, "session", "Print session information", NULL, 0, NULL }, 82 85 { 's', "start", "Start the current torrent(s)", "s", 0, NULL }, 83 86 { 'S', "stop", "Stop the current torrent(s)", "S", 0, NULL }, … … 86 89 { 'U', "no-uplimit", "Don't limit the global upload speed", "U", 0, NULL }, 87 90 { 'v', "verify", "Verify the current torrent(s)", "v", 0, NULL }, 91 { 'V', "version", "Show version number and exit", "V", 0, NULL }, 88 92 { 'w', "download-dir", "Set the default download folder", "w", 1, "<path>" }, 89 93 { 'x', "pex", "Enable peer exchange (PEX)", "x", 0, NULL }, … … 436 440 break; 437 441 442 case 'V': 443 fprintf(stderr, "Transmission %s\n", LONG_VERSION_STRING); 444 exit(0); 445 break; 446 438 447 case 'w': { 439 448 char * path = absolutify( optarg ); … … 493 502 tr_bencDictAddStr( &top, "method", "session-set" ); 494 503 tr_bencDictAddStr( args, "encryption", "tolerated" ); 504 break; 505 506 case 920: 507 tr_bencDictAddStr( &top, "method", "session-get" ); 508 tr_bencDictAddInt( &top, "tag", TAG_SESSION ); 495 509 break; 496 510 … … 712 726 } 713 727 return str; 728 } 729 730 static void 731 printSession( tr_benc * top ) 732 { 733 tr_benc *args; 734 if( ( tr_bencDictFindDict( top, "arguments", &args ) ) ) 735 { 736 const char * str; 737 int64_t i; 738 739 printf( "VERSION\n" ); 740 if( tr_bencDictFindStr( args, "version", &str ) ) 741 printf( " Daemon version: %s\n", str ); 742 if( tr_bencDictFindInt( args, "rpc-version", &i ) ) 743 printf( " RPC version: %" PRId64 "\n", i ); 744 if( tr_bencDictFindInt( args, "rpc-version-minimum", &i ) ) 745 printf( " RPC minimum version: %" PRId64 "\n", i ); 746 printf( "\n" ); 747 748 printf( "TRANSFER\n" ); 749 if( tr_bencDictFindStr( args, "download-dir", &str ) ) 750 printf( " Download directory: %s\n", str ); 751 if( tr_bencDictFindInt( args, "port", &i ) ) 752 printf( " Listenport: %" PRId64 "\n", i ); 753 if( tr_bencDictFindInt( args, "port-forwarding-enabled", &i ) ) 754 printf( " Portforwarding enabled: %s\n", ( i ? "Yes" : "No" ) ); 755 if( tr_bencDictFindInt( args, "pex-allowed", &i ) ) 756 printf( " Peer exchange allowed: %s\n", ( i ? "Yes" : "No" ) ); 757 if( tr_bencDictFindStr( args, "encryption", &str ) ) 758 printf( " Encryption: %s\n", str ); 759 printf( "\n" ); 760 761 printf( "LIMITS\n" ); 762 if( tr_bencDictFindInt( args, "peer-limit", &i ) ) 763 printf( " Peer limit: %" PRId64 "\n", i ); 764 if( tr_bencDictFindInt( args, "speed-limit-down-enabled", &i ) ) 765 printf( " Downloadlimit enabled: %s\n", ( i ? "Yes" : "No" ) ); 766 if( tr_bencDictFindInt( args, "speed-limit-down", &i ) ) 767 printf( " Downloadlimit: %6" PRId64 " KB/sec\n", i ); 768 if( tr_bencDictFindInt( args, "speed-limit-up-enabled", &i ) ) 769 printf( " Uploadlimit enabled: %s\n", ( i ? "Yes" : "No" ) ); 770 if( tr_bencDictFindInt( args, "speed-limit-up", &i ) ) 771 printf( " Uploadlimit: %6" PRId64 " KB/sec\n", i ); 772 773 } 714 774 } 715 775 … … 1087 1147 switch( tag ) 1088 1148 { 1149 case TAG_SESSION: 1150 printSession( &top ); break; 1151 1089 1152 case TAG_FILES: 1090 1153 printFileList( &top ); break; -
branches/1.5x/daemon/transmission-daemon.1
r7664 r7813 24 24 .Op Fl L Ar limit 25 25 .Op Fl er | ep | et 26 .Op Fl V 26 27 .Op Fl w Ar download-dir 27 28 .Ek … … 98 99 Used for client authentication. 99 100 101 .It Fl V Fl -version 102 Show version number and exit 103 100 104 .It Fl w Fl -download-dir 101 105 Where to store downloaded data. -
branches/1.5x/daemon/transmission-remote.1
r7767 r7813 34 34 .Op Fl u Ar number | Fl U 35 35 .Op Fl v 36 .Op Fl V 36 37 .Op Fl w Ar download-dir 37 38 .Op Fl x | X … … 162 163 .It Fl v Fl -verify 163 164 Verify the current torrent(s) 165 166 .It Fl V Fl -version 167 Show version number and exit 164 168 165 169 .It Fl w Fl -download-dir Ar directory -
branches/1.5x/gtk/blocklist.c
r6978 r7813 6 6 #include <glib/gi18n.h> 7 7 8 #define CURL_DISABLE_TYPECHECK /* otherwise -Wunreachable-code goes insane */ 8 9 #include <curl/curl.h> 9 10 -
branches/1.5x/libtransmission/bandwidth.c
r7767 r7813 104 104 tr_bandwidthSetParent( b, NULL ); 105 105 tr_ptrArrayDestruct( &b->children, NULL ); 106 b->magicNumber = 0xDEAD; 107 106 107 memset( b, ~0, sizeof( tr_bandwidth ) ); 108 108 return b; 109 109 } … … 208 208 for( i=0; i<peerCount; ++i ) 209 209 tr_peerIoRef( peers[i] ); 210 211 /* Stop all peers from listening for the socket to be ready for IO.212 * See "Second phase of IO" lower in this function for more info. */213 for( i=0; i<peerCount; ++i )214 tr_peerIoSetEnabled( peers[i], dir, FALSE );215 210 216 211 /* First phase of IO. Tries to distribute bandwidth fairly to keep faster … … 247 242 * or (2) the next tr_bandwidthAllocate() call, when we start over again. */ 248 243 for( i=0; i<peerCount; ++i ) 249 if( tr_peerIoHasBandwidthLeft( peers[i], dir ) ) 250 tr_peerIoSetEnabled( peers[i], dir, TRUE ); 244 tr_peerIoSetEnabled( peers[i], dir, tr_peerIoHasBandwidthLeft( peers[i], dir ) ); 251 245 252 246 for( i=0; i<peerCount; ++i ) -
branches/1.5x/libtransmission/bencode-test.c
r7664 r7813 11 11 #include "utils.h" /* tr_free */ 12 12 13 # define VERBOSE 013 #undef VERBOSE 14 14 15 15 static int test = 0; 16 16 17 #define check( A ) \ 17 #ifdef VERBOSE 18 #define check( A ) \ 18 19 { \ 19 20 ++test; \ 20 21 if( A ){ \ 21 if( VERBOSE ) \ 22 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ 23 __LINE__ );\ 22 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 24 23 } else { \ 25 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ 26 __LINE__ ); \ 24 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 27 25 return test; \ 28 26 } \ 29 27 } 28 #else 29 #define check( A ) \ 30 { \ 31 ++test; \ 32 if( !( A ) ){ \ 33 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 34 return test; \ 35 } \ 36 } 37 #endif 30 38 31 39 static int -
branches/1.5x/libtransmission/blocklist-test.c
r7664 r7813 7 7 #include "utils.h" 8 8 9 # define VERBOSE 09 #undef VERBOSE 10 10 11 #define check( A ) \ 11 #ifdef VERBOSE 12 #define check( A ) \ 12 13 { \ 13 14 ++test; \ 14 15 if( A ){ \ 15 if( VERBOSE ) \ 16 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ 17 __LINE__ );\ 16 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 18 17 } else { \ 19 if( VERBOSE ) \ 20 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ 21 __LINE__ );\ 18 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 22 19 return test; \ 23 20 } \ 24 21 } 22 #else 23 #define check( A )\ 24 { \ 25 ++test; \ 26 if( !( A ) ){ \ 27 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 28 return test; \ 29 } \ 30 } 31 #endif 25 32 26 33 static void … … 46 53 { 47 54 #ifndef WIN32 48 c har *tmpfile_txt = "/tmp/transmission-blocklist-test.txt";49 c har *tmpfile_bin = "/tmp/transmission-blocklist-test.bin";55 const char * tmpfile_txt = "/tmp/transmission-blocklist-test.txt"; 56 const char * tmpfile_bin = "/tmp/transmission-blocklist-test.bin"; 50 57 #else 51 c har *tmpfile_txt = "transmission-blocklist-test.txt";52 c har *tmpfile_bin = "transmission-blocklist-test.bin";58 const char * tmpfile_txt = "transmission-blocklist-test.txt"; 59 const char * tmpfile_bin = "transmission-blocklist-test.bin"; 53 60 #endif 54 61 struct tr_address addr; -
branches/1.5x/libtransmission/clients-test.c
r6822 r7813 5 5 #include "clients.h" 6 6 7 # define VERBOSE 07 #undef VERBOSE 8 8 9 #define check( A ) \ 9 #ifdef VERBOSE 10 #define check( A ) \ 10 11 { \ 11 12 ++test; \ 12 13 if( A ){ \ 13 if( VERBOSE ) \ 14 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ 15 __LINE__ );\ 14 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 16 15 } else { \ 17 if( VERBOSE ) \ 18 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ 19 __LINE__ );\ 16 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 20 17 return test; \ 21 18 } \ 22 19 } 20 #else 21 #define check( A ) \ 22 { \ 23 ++test; \ 24 if( !( A ) ){ \ 25 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 26 return test; \ 27 } \ 28 } 29 #endif 23 30 24 31 #define TEST_CLIENT( A, B ) \ -
branches/1.5x/libtransmission/completion.c
r7722 r7813 325 325 const tr_file * file = &tor->info.files[fileIndex]; 326 326 const tr_block_index_t firstBlock = file->offset / tor->blockSize; 327 const tr_block_index_t lastBlock = ( file->offset + file->length - 1 ) / tor->blockSize; 328 329 assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece ); 330 assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece ); 327 const tr_block_index_t lastBlock = file->length ? ( ( file->offset + file->length - 1 ) / tor->blockSize ) : firstBlock; 328 329 tr_assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece, 330 "file->offset %"PRIu64"; file->length %"PRIu64"; " 331 "pieceSize %"PRIu32"; blockSize %"PRIu32"; " 332 "firstBlock %"PRIu64"; lastBlock %"PRIu64, 333 file->offset, file->length, 334 tor->info.pieceSize, tor->blockSize, 335 firstBlock, lastBlock ); 336 337 tr_assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece, 338 "file->offset %"PRIu64"; file->length %"PRIu64"; " 339 "pieceSize %"PRIu32"; blockSize %"PRIu32"; " 340 "firstBlock %"PRIu64"; lastBlock %"PRIu64, 341 file->offset, file->length, 342 tor->info.pieceSize, tor->blockSize, 343 firstBlock, lastBlock ); 331 344 332 345 for( block=firstBlock; block<=lastBlock; ++block ) -
branches/1.5x/libtransmission/fdlimit.c
r7767 r7813 27 27 #endif 28 28 29 #ifdef HAVE_POSIX_FADVISE 30 #ifdef _XOPEN_SOURCE 31 #undef _XOPEN_SOURCE 32 #endif 33 #define _XOPEN_SOURCE 600 34 #endif 35 29 36 #include <assert.h> 30 37 #include <errno.h> … … 48 55 #endif 49 56 #include <unistd.h> 50 #include <fcntl.h> /* O_LARGEFILE */ 51 52 #include <event.h> 57 #include <fcntl.h> /* O_LARGEFILE posix_fadvise */ 58 53 59 #include <evutil.h> 54 60 … … 74 80 NOFILE_BUFFER = 512, /* the process' number of open files is 75 81 globalMaxPeers + NOFILE_BUFFER */ 82 83 SYNC_INTERVAL = 15 /* (arbitrary number) how many seconds to go 84 between fsync calls for files in heavy use */ 76 85 }; 77 86 … … 84 93 int fd; 85 94 uint64_t date; 95 time_t syncAt; 86 96 }; 87 97 … … 232 242 /* open the file */ 233 243 flags = doWrite ? ( O_RDWR | O_CREAT ) : O_RDONLY; 244 #ifdef O_RANDOM 245 flags |= O_RANDOM 246 #endif 234 247 #ifdef O_LARGEFILE 235 248 flags |= O_LARGEFILE; … … 249 262 if( doWrite && !alreadyExisted && ( preallocationMode == TR_PREALLOCATE_SPARSE ) ) 250 263 preallocateFileSparse( file->fd, desiredFileSize ); 264 265 #if defined( SYS_DARWIN ) 266 fcntl( file->fd, F_NOCACHE, 1 ); 267 fcntl( file->fd, F_RDAHEAD, 0 ); 268 #elif defined( HAVE_POSIX_FADVISE ) 269 posix_fadvise( file->fd, 0, 0, POSIX_FADV_RANDOM ); 270 #endif 251 271 252 272 tr_free( filename ); … … 372 392 else 373 393 { 374 dbgmsg( 375 "everything's full! waiting for someone else to finish something" ); 394 dbgmsg( "everything's full! waiting for someone else to finish something" ); 376 395 tr_lockUnlock( gFd->lock ); 377 396 tr_wait( 200 ); … … 395 414 tr_strlcpy( o->filename, filename, sizeof( o->filename ) ); 396 415 o->isWritable = doWrite; 416 o->syncAt = time( NULL ) + SYNC_INTERVAL; 397 417 } 398 418 … … 422 442 if( o->closeWhenDone ) 423 443 TrCloseFile( i ); 444 else if( o->syncAt <= time( NULL ) ) { 445 dbgmsg( "fsync()ing file '%s' in slot #%d", o->filename, i ); 446 fsync( o->fd ); 447 #ifdef HAVE_POSIX_FADVISE 448 /* TODO: test performance with and without this */ 449 posix_fadvise( o->fd, 0, 0, POSIX_FADV_DONTNEED ); 450 #endif 451 o->syncAt = time( NULL ) + SYNC_INTERVAL; 452 } 424 453 425 454 break; -
branches/1.5x/libtransmission/handshake.c
r7771 r7813 229 229 230 230 static int tr_handshakeDone( tr_handshake * handshake, 231 intisConnected );231 tr_bool isConnected ); 232 232 233 233 enum … … 1079 1079 static int 1080 1080 fireDoneFunc( tr_handshake * handshake, 1081 intisConnected )1081 tr_bool isConnected ) 1082 1082 { 1083 1083 const uint8_t * peer_id = isConnected && handshake->havePeerID … … 1105 1105 static int 1106 1106 tr_handshakeDone( tr_handshake * handshake, 1107 intisOK )1107 tr_bool isOK ) 1108 1108 { 1109 1109 tr_bool success; -
branches/1.5x/libtransmission/handshake.h
r7664 r7813 27 27 typedef tr_bool ( *handshakeDoneCB )( struct tr_handshake * handshake, 28 28 struct tr_peerIo * io, 29 intisConnected,29 tr_bool isConnected, 30 30 const uint8_t * peerId, 31 31 void * userData ); -
branches/1.5x/libtransmission/json-test.c
r7664 r7813 6 6 #include "utils.h" /* tr_free */ 7 7 8 # define VERBOSE 08 #undef VERBOSE 9 9 10 10 static int test = 0; 11 11 12 #define check( A ) \ 12 #ifdef VERBOSE 13 #define check( A ) \ 13 14 { \ 14 15 ++test; \ 15 16 if( A ){ \ 16 if( VERBOSE ) \ 17 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ 18 __LINE__ );\ 17 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 19 18 } else { \ 20 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ 21 __LINE__ ); \ 19 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 22 20 return test; \ 23 21 } \ 24 22 } 23 #else 24 #define check( A ) \ 25 { \ 26 ++test; \ 27 if( !( A ) ){ \ 28 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 29 return test; \ 30 } \ 31 } 32 #endif 25 33 26 34 #include "ConvertUTF.h" -
branches/1.5x/libtransmission/list.c
r7664 r7813 15 15 #include "utils.h" 16 16 17 /***18 ****19 ***/20 21 static tr_list * _unusedNodes = NULL;22 23 static const tr_list TR_LIST_INIT = { NULL, NULL, NULL };24 25 17 static tr_list* 26 18 node_alloc( void ) 27 19 { 28 tr_list * node; 29 30 if( _unusedNodes == NULL ) 31 node = tr_new( tr_list, 1 ); 32 else { 33 node = _unusedNodes; 34 _unusedNodes = node->next; 35 } 36 37 *node = TR_LIST_INIT; 38 return node; 20 return tr_new0( tr_list, 1 ); 39 21 } 40 22 … … 42 24 node_free( tr_list* node ) 43 25 { 44 if( node ) 45 { 46 *node = TR_LIST_INIT; 47 node->next = _unusedNodes; 48 _unusedNodes = node; 49 } 26 tr_free( node ); 50 27 } 51 28 -
branches/1.5x/libtransmission/peer-io.c
r7771 r7813 171 171 return ( io != NULL ) 172 172 && ( io->magicNumber == MAGIC_NUMBER ) 173 && ( io->refCount > 0 )173 && ( io->refCount >= 0 ) 174 174 && ( tr_isBandwidth( &io->bandwidth ) ) 175 175 && ( tr_isAddress( &io->addr ) ); … … 192 192 193 193 io->hasFinishedConnecting = TRUE; 194 io->pendingEvents &= ~EV_READ; 194 195 195 196 curlen = EVBUFFER_LENGTH( io->inbuf ); … … 274 275 275 276 io->hasFinishedConnecting = TRUE; 277 io->pendingEvents &= ~EV_WRITE; 276 278 277 279 dbgmsg( io, "libevent says this peer is ready to write" ); … … 344 346 { 345 347 tr_peerIo * io; 348 349 assert( session != NULL ); 350 assert( session->events != NULL ); 351 assert( tr_amInEventThread( session ) ); 346 352 347 353 if( socket >= 0 ) … … 420 426 tr_peerIo * io = vio; 421 427 428 assert( tr_isPeerIo( io ) ); 429 assert( tr_amInEventThread( io->session ) ); 430 assert( io->session->events != NULL ); 431 432 dbgmsg( io, "in tr_peerIo destructor" ); 422 433 event_del( &io->event_read ); 423 434 event_del( &io->event_write ); … … 429 440 __tr_list_destroy( &io->outbuf_datatypes, trDatatypeFree ); 430 441 431 io->magicNumber = 0xDEAD;442 memset( io, ~0, sizeof( tr_peerIo ) ); 432 443 tr_free( io ); 433 444 } … … 438 449 if( io ) 439 450 { 451 dbgmsg( io, "in tr_peerIoFree" ); 440 452 io->canRead = NULL; 441 453 io->didWrite = NULL; … … 446 458 447 459 void 448 tr_peerIoRef( tr_peerIo * io ) 449 { 450 assert( tr_isPeerIo( io ) ); 460 tr_peerIoRefImpl( const char * file, int line, tr_peerIo * io ) 461 { 462 assert( tr_isPeerIo( io ) ); 463 464 dbgmsg( io, "%s:%d is incrementing the IO's refcount from %d to %d", 465 file, line, io->refCount, io->refCount+1 ); 451 466 452 467 ++io->refCount; … … 454 469 455 470 void 456 tr_peerIoUnref( tr_peerIo * io ) 457 { 458 assert( tr_isPeerIo( io ) ); 471 tr_peerIoUnrefImpl( const char * file, int line, tr_peerIo * io ) 472 { 473 assert( tr_isPeerIo( io ) ); 474 475 dbgmsg( io, "%s:%d is decrementing the IO's refcount from %d to %d", 476 file, line, io->refCount, io->refCount-1 ); 459 477 460 478 if( !--io->refCount ) … … 463 481 464 482 const tr_address* 465 tr_peerIoGetAddress( const tr_peerIo * io, 466 tr_port * port ) 483 tr_peerIoGetAddress( const tr_peerIo * io, tr_port * port ) 467 484 { 468 485 assert( tr_isPeerIo( io ) ); … … 824 841 } 825 842 826 dbgmsg( io, "flushing peer-io, direction %d, limit %zu, bytesUsed %d", (int)dir, limit, bytesUsed );843 dbgmsg( io, "flushing peer-io, hasFinishedConnecting %d, direction %d, limit %zu, bytesUsed %d", (int)io->hasFinishedConnecting, (int)dir, limit, bytesUsed ); 827 844 return bytesUsed; 828 845 } … … 835 852 event_enable( tr_peerIo * io, short event ) 836 853 { 837 if( event & EV_READ ) 854 assert( tr_amInEventThread( io->session ) ); 855 assert( io->session != NULL ); 856 assert( io->session->events != NULL ); 857 assert( event_initialized( &io->event_read ) ); 858 assert( event_initialized( &io->event_write ) ); 859 860 if( ( event & EV_READ ) && ! ( io->pendingEvents & EV_READ ) ) 861 { 862 dbgmsg( io, "enabling libevent ready-to-read polling" ); 838 863 event_add( &io->event_read, NULL ); 839 840 if( event & EV_WRITE ) 864 io->pendingEvents |= EV_READ; 865 } 866 867 if( ( event & EV_WRITE ) && ! ( io->pendingEvents & EV_WRITE ) ) 868 { 869 dbgmsg( io, "enabling libevent ready-to-write polling" ); 841 870 event_add( &io->event_write, NULL ); 871 io->pendingEvents |= EV_WRITE; 872 } 842 873 } 843 874 … … 845 876 event_disable( struct tr_peerIo * io, short event ) 846 877 { 847 if( event & EV_READ ) 878 assert( tr_amInEventThread( io->session ) ); 879 assert( io->session != NULL ); 880 assert( io->session->events != NULL ); 881 assert( event_initialized( &io->event_read ) ); 882 assert( event_initialized( &io->event_write ) ); 883 884 if( ( event & EV_READ ) && ( io->pendingEvents & EV_READ ) ) 885 { 886 dbgmsg( io, "disabling libevent ready-to-read polling" ); 848 887 event_del( &io->event_read ); 849 850 if( event & EV_WRITE ) 888 io->pendingEvents &= ~EV_READ; 889 } 890 891 if( ( event & EV_WRITE ) && ( io->pendingEvents & EV_WRITE ) ) 892 { 893 dbgmsg( io, "disabling libevent ready-to-write polling" ); 851 894 event_del( &io->event_write ); 895 io->pendingEvents &= ~EV_WRITE; 896 } 852 897 } 853 898 … … 862 907 assert( tr_isPeerIo( io ) ); 863 908 assert( tr_isDirection( dir ) ); 909 assert( tr_amInEventThread( io->session ) ); 910 assert( io->session->events != NULL ); 864 911 865 912 if( isEnabled ) -
branches/1.5x/libtransmission/peer-io.h
r7771 r7813 70 70 tr_bool hasFinishedConnecting; 71 71 72 int pendingEvents; 73 72 74 int magicNumber; 73 75 … … 119 121 int socket ); 120 122 121 void tr_peerIoRef ( tr_peerIo * io ); 122 123 void tr_peerIoUnref ( tr_peerIo * io ); 123 void tr_peerIoRefImpl ( const char * file, 124 int line, 125 tr_peerIo * io ); 126 127 #define tr_peerIoRef(io) tr_peerIoRefImpl( __FILE__, __LINE__, (io) ); 128 129 void tr_peerIoUnrefImpl ( const char * file, 130 int line, 131 tr_peerIo * io ); 132 133 #define tr_peerIoUnref(io) tr_peerIoUnrefImpl( __FILE__, __LINE__, (io) ); 124 134 125 135 tr_bool tr_isPeerIo ( const tr_peerIo * io ); … … 328 338 329 339 static TR_INLINE void tr_peerIoSetParent( tr_peerIo * io, 330 struct tr_bandwidth * parent )340 struct tr_bandwidth * parent ) 331 341 { 332 342 assert( tr_isPeerIo( io ) ); … … 341 351 342 352 static TR_INLINE tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io, 343 tr_direction dir ) 344 { 345 assert( tr_isPeerIo( io ) ); 346 347 return tr_bandwidthClamp( &io->bandwidth, dir, 1024 ) > 0; 353 tr_direction dir ) 354 { 355 assert( tr_isPeerIo( io ) ); 356 357 return !io->hasFinishedConnecting 358 || ( tr_bandwidthClamp( &io->bandwidth, dir, 1024 ) > 0 ); 348 359 } 349 360 -
branches/1.5x/libtransmission/peer-mgr.c
r7767 r7813 1161 1161 myHandshakeDoneCB( tr_handshake * handshake, 1162 1162 tr_peerIo * io, 1163 intisConnected,1163 tr_bool isConnected, 1164 1164 const uint8_t * peer_id, 1165 1165 void * vmanager ) … … 1174 1174 1175 1175 assert( io ); 1176 assert( isConnected == 0 || isConnected == 1);1176 assert( tr_isBool( ok ) ); 1177 1177 1178 1178 t = tr_peerIoHasTorrentHash( io ) -
branches/1.5x/libtransmission/peer-msgs-test.c
r7664 r7813 5 5 #include "utils.h" 6 6 7 # define VERBOSE 07 #undef VERBOSE 8 8 9 #define check( A ) \ 9 #ifdef VERBOSE 10 #define check( A ) \ 10 11 { \ 11 12 ++test; \ 12 13 if( A ){ \ 13 if( VERBOSE ) \ 14 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ 15 __LINE__ );\ 14 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 16 15 } else { \ 17 if( VERBOSE ) \ 18 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ 19 __LINE__ );\ 16 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 20 17 return test; \ 21 18 } \ 22 19 } 20 #else 21 #define check( A ) \ 22 { \ 23 ++test; \ 24 if( !( A ) ){ \ 25 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 26 return test; \ 27 } \ 28 } 29 #endif 23 30 24 31 int -
branches/1.5x/libtransmission/request-list-test.c
r7664 r7813 3 3 #include "request-list.h" 4 4 5 # define VERBOSE 05 #undef VERBOSE 6 6 7 7 static int test = 0; 8 8 9 #define check( A ) \ 9 #ifdef VERBOSE 10 #define check( A ) \ 10 11 { \ 11 12 ++test; \ 12 13 if( A ){ \ 13 if( VERBOSE ) \ 14 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ 15 __LINE__ );\ 14 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 16 15 } else { \ 17 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ 18 __LINE__ ); \ 16 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 19 17 return test; \ 20 18 } \ 21 19 } 20 #else 21 #define check( A ) \ 22 { \ 23 ++test; \ 24 if( !( A ) ){ \ 25 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 26 return test; \ 27 } \ 28 } 29 #endif 22 30 23 31 static int -
branches/1.5x/libtransmission/rpc-test.c
r6944 r7813 6 6 #include "utils.h" 7 7 8 # define VERBOSE 08 #undef VERBOSE 9 9 10 10 static int test = 0; 11 11 12 #define check( A ) \ 12 #ifdef VERBOSE 13 #define check( A ) \ 13 14 { \ 14 15 ++test; \ 15 16 if( A ){ \ 16 if( VERBOSE ) \ 17 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ 18 __LINE__ );\ 17 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 19 18 } else { \ 20 if( VERBOSE ) \ 21 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ 22 __LINE__ );\ 19 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 23 20 return test; \ 24 21 } \ 25 22 } 23 #else 24 #define check( A ) \ 25 { \ 26 ++test; \ 27 if( !( A ) ){ \ 28 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 29 return test; \ 30 } \ 31 } 32 #endif 26 33 27 34 static int -
branches/1.5x/libtransmission/rpcimpl.c
r7767 r7813 511 511 tr_benc * list = tr_bencDictAddList( args_out, "torrents", torrentCount ); 512 512 tr_benc * fields; 513 c har *msg = NULL;513 const char * msg = NULL; 514 514 515 515 assert( idle_data == NULL ); -
branches/1.5x/libtransmission/session.c
r7722 r7813 358 358 359 359 static void metainfoLookupRescan( tr_session * ); 360 static void tr_sessionInitImpl( void * ); 360 361 361 362 tr_session * … … 379 380 session->lock = tr_lockNew( ); 380 381 session->tag = tr_strdup( tag ); 382 session->magicNumber = SESSION_MAGIC_NUMBER; 383 381 384 dbgmsg( "tr_sessionInit: the session's top-level bandwidth object is %p", session->bandwidth ); 382 385 … … 456 459 457 460 tr_netInit( ); /* must go before tr_eventInit */ 458 459 461 tr_eventInit( session ); 460 while( !session->events ) 461 tr_wait( 50 ); 462 assert( session->events != NULL ); 462 463 463 464 session->peerMgr = tr_peerMgrNew( session ); … … 517 518 tr_sessionSetSpeedLimit( session, TR_DOWN, i ); 518 519 tr_sessionSetSpeedLimitEnabled( session, TR_DOWN, j ); 519 520 /* first %s is the application name521 second %s is the version number */522 tr_inf( _( "%s %s started" ), TR_NAME, LONG_VERSION_STRING );523 520 524 521 /* initialize the blocklist */ … … 531 528 loadBlocklists( session ); 532 529 530 session->rpcServer = tr_rpcInit( session, &settings ); 531 532 tr_bencFree( &settings ); 533 534 session->isWaiting = TRUE; 535 tr_runInEventThread( session, tr_sessionInitImpl, session ); 536 while( session->isWaiting ) 537 tr_wait( 100 ); 538 539 return session; 540 } 541 static void 542 tr_sessionInitImpl( void * vsession ) 543 { 544 tr_session * session = vsession; 545 546 assert( tr_isSession( session ) ); 547 548 /* first %s is the application name 549 second %s is the version number */ 550 tr_inf( _( "%s %s started" ), TR_NAME, LONG_VERSION_STRING ); 551 533 552 tr_statsInit( session ); 534 535 553 session->web = tr_webInit( session ); 536 session->rpcServer = tr_rpcInit( session, &settings );537 538 554 metainfoLookupRescan( session ); 539 540 tr_bencFree( &settings ); 541 return session; 555 session->isWaiting = FALSE; 542 556 } 543 557 … … 549 563 tr_sessionSetDownloadDir( tr_session * session, const char * dir ) 550 564 { 565 assert( tr_isSession( session ) ); 566 551 567 if( session->downloadDir != dir ) 552 568 { … … 559 575 tr_sessionGetDownloadDir( const tr_session * session ) 560 576 { 577 assert( tr_isSession( session ) ); 578 561 579 return session->downloadDir; 562 580 } … … 569 587 tr_globalLock( tr_session * session ) 570 588 { 589 assert( tr_isSession( session ) ); 590 571 591 tr_lockLock( session->lock ); 572 592 } … … 575 595 tr_globalUnlock( tr_session * session ) 576 596 { 597 assert( tr_isSession( session ) ); 598 577 599 tr_lockUnlock( session->lock ); 578 600 } … … 581 603 tr_globalIsLocked( const tr_session * session ) 582 604 { 583 return session&& tr_lockHave( session->lock );605 return tr_isSession( session ) && tr_lockHave( session->lock ); 584 606 } 585 607 … … 612 634 setPortImpl( tr_session * session, tr_port port ) 613 635 { 614 struct bind_port_data * data = tr_new( struct bind_port_data, 1 ); 636 struct bind_port_data * data; 637 638 assert( tr_isSession( session ) ); 639 640 data = tr_new( struct bind_port_data, 1 ); 615 641 data->session = session; 616 642 data->port = port; … … 622 648 tr_port port ) 623 649 { 650 assert( tr_isSession( session ) ); 651 624 652 session->isPortRandom = FALSE; 625 653 session->peerPort = port; … … 630 658 tr_sessionSetPeerPortRandom( tr_session * session ) 631 659 { 660 assert( tr_isSession( session ) ); 661 632 662 session->isPortRandom = TRUE; 633 663 session->peerPort = getRandomPort( session ); … … 639 669 tr_sessionGetPeerPort( const tr_session * session ) 640 670 { 641 assert( session);671 assert( tr_isSession( session ) ); 642 672 643 673 return session->peerPort; … … 647 677 tr_sessionGetPortForwarding( const tr_session * session ) 648 678 { 679 assert( tr_isSession( session ) ); 680 649 681 return tr_sharedTraversalStatus( session->shared ); 650 682 } … … 657 689 updateBandwidth( tr_session * session, tr_direction dir ) 658 690 { 659 const tr_bool zeroCase = session->speedLimit[dir] < 1 && session->isSpeedLimited[dir]; 691 tr_bool zeroCase; 692 693 assert( tr_isSession( session ) ); 694 695 zeroCase = session->speedLimit[dir] < 1 && session->isSpeedLimited[dir]; 660 696 661 697 tr_bandwidthSetLimited( session->bandwidth, dir, session->isSpeedLimited[dir] && !zeroCase ); … … 669 705 tr_bool isLimited ) 670 706 { 671 assert( session);707 assert( tr_isSession( session ) ); 672 708 assert( tr_isDirection( dir ) ); 673 709 … … 681 717 int desiredSpeed ) 682 718 { 683 assert( session);719 assert( tr_isSession( session ) ); 684 720 assert( tr_isDirection( dir ) ); 685 721 … … 692 728 tr_direction dir ) 693 729 { 694 assert( session);730 assert( tr_isSession( session ) ); 695 731 assert( tr_isDirection( dir ) ); 696 732 … … 702 738 tr_direction dir ) 703 739 { 704 assert( session);740 assert( tr_isSession( session ) ); 705 741 assert( tr_isDirection( dir ) ); 706 742 … … 713 749 714 750 void 715 tr_sessionSetPeerLimit( tr_session * session UNUSED,751 tr_sessionSetPeerLimit( tr_session * session, 716 752 uint16_t maxGlobalPeers ) 717 753 { 754 assert( tr_isSession( session ) ); 755 718 756 tr_fdSetPeerLimit( maxGlobalPeers ); 719 757 } 720 758 721 759 uint16_t 722 tr_sessionGetPeerLimit( const tr_session * session UNUSED ) 723 { 760 tr_sessionGetPeerLimit( const tr_session * session ) 761 { 762 assert( tr_isSession( session ) ); 763 724 764 return tr_fdGetPeerLimit( ); 725 765 } … … 728 768 tr_sessionSetPeerLimitPerTorrent( tr_session * session, uint16_t n ) 729 769 { 770 assert( tr_isSession( session ) ); 771 730 772 session->peerLimitPerTorrent = n; 731 773 } … … 734 776 tr_sessionGetPeerLimitPerTorrent( const tr_session * session ) 735 777 { 778 assert( tr_isSession( session ) ); 779 736 780 return session->peerLimitPerTorrent; 737 781 } … … 744 788 tr_sessionGetPieceSpeed( const tr_session * session, tr_direction dir ) 745 789 { 746 return session? tr_bandwidthGetPieceSpeed( session->bandwidth, 0, dir ) : 0.0;790 return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed( session->bandwidth, 0, dir ) : 0.0; 747 791 } 748 792 … … 750 794 tr_sessionGetRawSpeed( const tr_session * session, tr_direction dir ) 751 795 { 752 return session? tr_bandwidthGetPieceSpeed( session->bandwidth, 0, dir ) : 0.0;796 return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed( session->bandwidth, 0, dir ) : 0.0; 753 797 } 754 798 … … 756 800 tr_sessionCountTorrents( const tr_session * session ) 757 801 { 758 return session->torrentCount;802 return tr_isSession( session ) ? session->torrentCount : 0; 759 803 } 760 804 … … 780 824 int i, n; 781 825 tr_torrent ** torrents; 826 827 assert( tr_isSession( session ) ); 782 828 783 829 tr_statsClose( session ); … … 822 868 const int maxwait_msec = SHUTDOWN_MAX_SECONDS * 1000; 823 869 const uint64_t deadline = tr_date( ) + maxwait_msec; 870 871 assert( tr_isSession( session ) ); 824 872 825 873 dbgmsg( "shutting down transmission session %p", session ); … … 884 932 tr_torrent ** torrents; 885 933 tr_list * l = NULL, *list = NULL; 934 935 assert( tr_isSession( session ) ); 886 936 887 937 tr_ctorSetSave( ctor, FALSE ); /* since we already have them */ … … 934 984 tr_bool enabled ) 935 985 { 986 assert( tr_isSession( session ) ); 987 936 988 session->isPexEnabled = enabled != 0; 937 989 } … … 940 992 tr_sessionIsPexEnabled( const tr_session * session ) 941 993 { 994 assert( tr_isSession( session ) ); 995 942 996 return session->isPexEnabled; 943 997 } … … 951 1005 tr_bool enabled ) 952 1006 { 1007 assert( tr_isSession( session ) ); 1008 953 1009 session->useLazyBitfield = enabled != 0; 954 1010 } … … 957 1013 tr_sessionIsLazyBitfieldEnabled( const tr_session * session ) 958 1014 { 1015 assert( tr_isSession( session ) ); 1016 959 1017 return session->useLazyBitfield; 960 1018 } … … 968 1026 tr_bool enabled ) 969 1027 { 1028 assert( tr_isSession( session ) ); 1029 970 1030 tr_globalLock( session ); 971 1031 tr_sharedTraversalEnable( session->shared, enabled ); … … 976 1036 tr_sessionIsPortForwardingEnabled( const tr_session * session ) 977 1037 { 1038 assert( tr_isSession( session ) ); 1039 978 1040 return tr_sharedTraversalIsEnabled( session->shared ); 979 1041 } … … 989 1051 tr_list * l; 990 1052 1053 assert( tr_isSession( session ) ); 1054 991 1055 for( l = session->blocklists; l; l = l->next ) 992 1056 n += _tr_blocklistGetRuleCount( l->data ); … … 997 1061 tr_blocklistIsEnabled( const tr_session * session ) 998 1062 { 1063 assert( tr_isSession( session ) ); 1064 999 1065 return session->isBlocklistEnabled; 1000 1066 } … … 1006 1072 tr_list * l; 1007 1073 1074 assert( tr_isSession( session ) ); 1075 1008 1076 session->isBlocklistEnabled = isEnabled != 0; 1009 1077 … … 1015 1083 tr_blocklistExists( const tr_session * session ) 1016 1084 { 1085 assert( tr_isSession( session ) ); 1086 1017 1087 return session->blocklists != NULL; 1018 1088 } … … 1025 1095 tr_blocklist * b; 1026 1096 const char * defaultName = "level1.bin"; 1097 1098 assert( tr_isSession( session ) ); 1027 1099 1028 1100 for( b = NULL, l = session->blocklists; !b && l; l = l->next ) … … 1048 1120 tr_list * l; 1049 1121 1122 assert( tr_isSession( session ) ); 1123 1050 1124 for( l = session->blocklists; l; l = l->next ) 1051 1125 if( _tr_blocklistHasAddress( l->data, addr ) ) … … 1059 1133 1060 1134 static int 1061 compareLookupEntries( const void * va, 1062 const void * vb ) 1135 compareLookupEntries( const void * va, const void * vb ) 1063 1136 { 1064 1137 const struct tr_metainfo_lookup * a = va; … … 1071 1144 metainfoLookupResort( tr_session * session ) 1072 1145 { 1146 assert( tr_isSession( session ) ); 1147 1073 1148 qsort( session->metainfoLookup, 1074 1149 session->metainfoLookupCount, … … 1078 1153 1079 1154 static int 1080 compareHashStringToLookupEntry( const void * va, 1081 const void * vb ) 1155 compareHashStringToLookupEntry( const void * va, const void * vb ) 1082 1156 { 1083 1157 const char * a = va; … … 1110 1184 tr_ctor * ctor = NULL; 1111 1185 tr_list * list = NULL; 1186 1187 assert( tr_isSession( session ) ); 1112 1188 1113 1189 /* walk through the directory and find the mappings */ … … 1193 1269 tr_torrent * tor ) 1194 1270 { 1271 assert( tr_isSession( session ) ); 1272 1195 1273 return tor ? tor->next : session->torrentList; 1196 1274 } … … 1204 1282 tr_bool isEnabled ) 1205 1283 { 1284 assert( tr_isSession( session ) ); 1285 1206 1286 tr_rpcSetEnabled( session->rpcServer, isEnabled ); 1207 1287 } … … 1210 1290 tr_sessionIsRPCEnabled( const tr_session * session ) 1211 1291 { 1292 assert( tr_isSession( session ) ); 1293 1212 1294 return tr_rpcIsEnabled( session->rpcServer ); 1213 1295 } … … 1217 1299 tr_port port ) 1218 1300 { 1301 assert( tr_isSession( session ) ); 1302 1219 1303 tr_rpcSetPort( session->rpcServer, port ); 1220 1304 } … … 1223 1307 tr_sessionGetRPCPort( const tr_session * session ) 1224 1308 { 1309 assert( tr_isSession( session ) ); 1310 1225 1311 return tr_rpcGetPort( session->rpcServer ); 1226 1312 } … … 1231 1317 void * user_data ) 1232 1318 { 1319 assert( tr_isSession( session ) ); 1320 1233 1321 session->rpc_func = func; 1234 1322 session->rpc_func_user_data = user_data; … … 1239 1327 const char * whitelist ) 1240 1328 { 1329 assert( tr_isSession( session ) ); 1330 1241 1331 tr_rpcSetWhitelist( session->rpcServer, whitelist ); 1242 1332 } … … 1245 1335 tr_sessionGetRPCWhitelist( const tr_session * session ) 1246 1336 { 1337 assert( tr_isSession( session ) ); 1338 1247 1339 return tr_rpcGetWhitelist( session->rpcServer ); 1248 1340 } … … 1252 1344 tr_bool isEnabled ) 1253 1345 { 1346 assert( tr_isSession( session ) ); 1347 1254 1348 tr_rpcSetWhitelistEnabled( session->rpcServer, isEnabled ); 1255 1349 } … … 1258 1352 tr_sessionGetRPCWhitelistEnabled( const tr_session * session ) 1259 1353 { 1354 assert( tr_isSession( session ) ); 1355 1260 1356 return tr_rpcGetWhitelistEnabled( session->rpcServer ); 1261 1357 } … … 1266 1362 const char * password ) 1267 1363 { 1364 assert( tr_isSession( session ) ); 1365 1268 1366 tr_rpcSetPassword( session->rpcServer, password ); 1269 1367 } … … 1272 1370 tr_sessionGetRPCPassword( const tr_session * session ) 1273 1371 { 1372 assert( tr_isSession( session ) ); 1373 1274 1374 return tr_rpcGetPassword( session->rpcServer ); 1275 1375 } … … 1279 1379 const char * username ) 1280 1380 { 1381 assert( tr_isSession( session ) ); 1382 1281 1383 tr_rpcSetUsername( session->rpcServer, username ); 1282 1384 } … … 1285 1387 tr_sessionGetRPCUsername( const tr_session * session ) 1286 1388 { 1389 assert( tr_isSession( session ) ); 1390 1287 1391 return tr_rpcGetUsername( session->rpcServer ); 1288 1392 } … … 1292 1396 tr_bool isEnabled ) 1293 1397 { 1398 assert( tr_isSession( session ) ); 1399 1294 1400 tr_rpcSetPasswordEnabled( session->rpcServer, isEnabled ); 1295 1401 } … … 1298 1404 tr_sessionIsRPCPasswordEnabled( const tr_session * session ) 1299 1405 { 1406 assert( tr_isSession( session ) ); 1407 1300 1408 return tr_rpcIsPasswordEnabled( session->rpcServer ); 1301 1409 } … … 1308 1416 tr_sessionIsProxyEnabled( const tr_session * session ) 1309 1417 { 1418 assert( tr_isSession( session ) ); 1419 1310 1420 return session->isProxyEnabled; 1311 1421 } … … 1315 1425 tr_bool isEnabled ) 1316 1426 { 1427 assert( tr_isSession( session ) ); 1428 1317 1429 session->isProxyEnabled = isEnabled != 0; 1318 1430 } … … 1321 1433 tr_sessionGetProxyType( const tr_session * session ) 1322 1434 { 1435 assert( tr_isSession( session ) ); 1436 1323 1437 return session->proxyType; 1324 1438 } … … 1328 1442 tr_proxy_type type ) 1329 1443 { 1444 assert( tr_isSession( session ) ); 1445 1330 1446 session->proxyType = type; 1331 1447 } … … 1334 1450 tr_sessionGetProxy( const tr_session * session ) 1335 1451 { 1452 assert( tr_isSession( session ) ); 1453 1336 1454 return session->proxy; 1337 1455 } … … 1340 1458 tr_sessionGetProxyPort( const tr_session * session ) 1341 1459 { 1460 assert( tr_isSession( session ) ); 1461 1342 1462 return session->proxyPort; 1343 1463 } … … 1347 1467 const char * proxy ) 1348 1468 { 1469 assert( tr_isSession( session ) ); 1470 1349 1471 if( proxy != session->proxy ) 1350 1472 { … … 1358 1480 tr_port port ) 1359 1481 { 1482 assert( tr_isSession( session ) ); 1483 1360 1484 session->proxyPort = port; 1361 1485 } … … 1364 1488 tr_sessionIsProxyAuthEnabled( const tr_session * session ) 1365 1489 { 1490 assert( tr_isSession( session ) ); 1491 1366 1492 return session->isProxyAuthEnabled; 1367 1493 } … … 1371 1497 tr_bool isEnabled ) 1372 1498 { 1499 assert( tr_isSession( session ) ); 1500 1373 1501 session->isProxyAuthEnabled = isEnabled != 0; 1374 1502 } … … 1377 1505 tr_sessionGetProxyUsername( const tr_session * session ) 1378 1506 { 1507 assert( tr_isSession( session ) ); 1508 1379 1509 return session->proxyUsername; 1380 1510 } … … 1384 1514 const char * username ) 1385 1515 { 1516 assert( tr_isSession( session ) ); 1517 1386 1518 if( username != session->proxyUsername ) 1387 1519 { … … 1394 1526 tr_sessionGetProxyPassword( const tr_session * session ) 1395 1527 { 1528 assert( tr_isSession( session ) ); 1529 1396 1530 return session->proxyPassword; 1397 1531 } … … 1401 1535 const char * password ) 1402 1536 { 1537 assert( tr_isSession( session ) ); 1538 1403 1539 if( password != session->proxyPassword ) 1404 1540 { … … 1413 1549 int ret = 0; 1414 1550 tr_torrent * tor = NULL; 1551 1552 assert( tr_isSession( session ) ); 1415 1553 1416 1554 while(( tor = tr_torrentNext( session, tor ))) -
branches/1.5x/libtransmission/session.h
r7722 r7813 65 65 tr_bool isProxyAuthEnabled; 66 66 tr_bool isClosed; 67 tr_bool isWaiting; 67 68 tr_bool useLazyBitfield; 68 69 69 70 tr_bool isSpeedLimited[2]; 70 71 int speedLimit[2]; 72 int magicNumber; 71 73 72 74 tr_encryption_mode encryptionMode; … … 147 149 tr_bool tr_globalIsLocked( const tr_session * ); 148 150 151 enum 152 { 153 SESSION_MAGIC_NUMBER = 3845 154 }; 155 156 static inline tr_bool tr_isSession( const tr_session * session ) 157 { 158 return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER ); 159 } 160 149 161 #endif -
branches/1.5x/libtransmission/test-peer-id.c
r7664 r7813 6 6 #include "utils.h" 7 7 8 # define VERBOSE 08 #undef VERBOSE 9 9 10 #define check( A ) \ 10 #ifdef VERBOSE 11 #define check( A ) \ 11 12 { \ 12 13 ++test; \ 13 14 if( A ){ \ 14 if( VERBOSE ) \ 15 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ 16 __LINE__ );\ 15 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 17 16 } else { \ 18 if( VERBOSE ) \ 19 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ 20 __LINE__ );\ 17 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 21 18 return test; \ 22 19 } \ 23 20 } 21 #else 22 #define check( A ) \ 23 { \ 24 ++test; \ 25 if( !( A ) ){ \ 26 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 27 return test; \ 28 } \ 29 } 30 #endif 24 31 25 32 int -
branches/1.5x/libtransmission/torrent.c
r7776 r7813 447 447 tor->session = session; 448 448 tor->uniqueId = nextUniqueId++; 449 tor->magicNumber = TORRENT_MAGIC_NUMBER; 449 450 450 451 randomizeTiers( info ); … … 634 635 const char * path ) 635 636 { 637 assert( tr_isTorrent( tor ) ); 638 636 639 if( !path || !tor->downloadDir || strcmp( path, tor->downloadDir ) ) 637 640 { … … 645 648 tr_torrentGetDownloadDir( const tr_torrent * tor ) 646 649 { 650 assert( tr_isTorrent( tor ) ); 651 647 652 return tor->downloadDir; 648 653 } … … 651 656 tr_torrentChangeMyPort( tr_torrent * tor ) 652 657 { 658 assert( tr_isTorrent( tor ) ); 659 653 660 if( tor->tracker ) 654 661 tr_trackerChangeMyPort( tor->tracker ); … … 660 667 tr_torrent * tor = vtor; 661 668 669 assert( tr_isTorrent( tor ) ); 670 662 671 if( tor->isRunning ) 663 672 tr_trackerReannounce( tor->tracker ); … … 667 676 tr_torrentManualUpdate( tr_torrent * tor ) 668 677 { 678 assert( tr_isTorrent( tor ) ); 679 669 680 tr_runInEventThread( tor->session, tr_torrentManualUpdateImpl, tor ); 670 681 } … … 673 684 tr_torrentCanManualUpdate( const tr_torrent * tor ) 674 685 { 675 return ( t or)676 677 686 return ( tr_isTorrent( tor ) ) 687 && ( tor->isRunning ) 688 && ( tr_trackerCanManualAnnounce( tor->tracker ) ); 678 689 } 679 690 … … 681 692 tr_torrentInfo( const tr_torrent * tor ) 682 693 { 683 return t or? &tor->info : NULL;694 return tr_isTorrent( tor ) ? &tor->info : NULL; 684 695 } 685 696 … … 689 700 const time_t now = time( NULL ); 690 701 691 return tor && ( now == tor->lastStatTime ) ? &tor->stats 692 : tr_torrentStat( tor ); 702 return tr_isTorrent( tor ) && ( now == tor->lastStatTime ) 703 ? &tor->stats 704 : tr_torrentStat( tor ); 693 705 } 694 706 … … 696 708 tr_torrentGetActivity( tr_torrent * tor ) 697 709 { 710 assert( tr_isTorrent( tor ) ); 711 698 712 tr_torrentRecheckCompleteness( tor ); 699 713 … … 722 736 return NULL; 723 737 738 assert( tr_isTorrent( tor ) ); 724 739 tr_torrentLock( tor ); 725 740 … … 845 860 uint64_t haveBytes = 0; 846 861 847 assert( t or);862 assert( tr_isTorrent( tor ) ); 848 863 assert( fileIndex < tor->info.fileCount ); 849 864 assert( file->offset + file->length <= tor->info.totalSize ); … … 888 903 tr_file_stat * walk = files; 889 904 905 assert( tr_isTorrent( tor ) ); 906 890 907 for( i = 0; i < n; ++i, ++walk ) 891 908 { … … 915 932 tr_torrentWebSpeeds( const tr_torrent * tor ) 916 933 { 917 return tor ? tr_peerMgrWebSpeeds( tor ) : NULL; 934 return tr_isTorrent( tor ) 935 ? tr_peerMgrWebSpeeds( tor ) 936 : NULL; 918 937 } 919 938 … … 924 943 tr_peer_stat * ret = NULL; 925 944 926 if( t or)945 if( tr_isTorrent( tor ) ) 927 946 ret = tr_peerMgrPeerStats( tor, peerCount ); 928 947 … … 950 969 int size ) 951 970 { 971 assert( tr_isTorrent( tor ) ); 972 952 973 tr_torrentLock( tor ); 953 974 tr_cpGetAmountDone( &tor->completion, tab, size ); … … 958 979 tr_torrentResetTransferStats( tr_torrent * tor ) 959 980 { 981 assert( tr_isTorrent( tor ) ); 982 960 983 tr_torrentLock( tor ); 961 984 … … 975 998 tr_bool has ) 976 999 { 1000 assert( tr_isTorrent( tor ) ); 1001 assert( pieceIndex < tor->info.pieceCount ); 1002 977 1003 tr_torrentLock( tor ); 978 979 assert( tor );980 assert( pieceIndex < tor->info.pieceCount );981 1004 982 1005 if( has ) … … 999 1022 tr_info * inf = &tor->info; 1000 1023 1001 assert( t or);1024 assert( tr_isTorrent( tor ) ); 1002 1025 assert( !tor->isRunning ); 1003 1026 … … 1047 1070 { 1048 1071 tr_torrent * tor = vtor; 1072 1073 assert( tr_isTorrent( tor ) ); 1049 1074 1050 1075 tr_globalLock( tor->session ); … … 1065 1090 checkAndStartCB( tr_torrent * tor ) 1066 1091 { 1092 assert( tr_isTorrent( tor ) ); 1093 assert( tr_isSession( tor->session ) ); 1094 1067 1095 tr_runInEventThread( tor->session, checkAndStartImpl, tor ); 1068 1096 } … … 1072 1100 int reloadProgress ) 1073 1101 { 1102 assert( tr_isTorrent( tor ) ); 1103 1074 1104 tr_globalLock( tor->session ); 1075 1105 … … 1093 1123 tr_torrentStart( tr_torrent * tor ) 1094 1124 { 1095 if( t or)1125 if( tr_isTorrent( tor ) ) 1096 1126 torrentStart( tor, TRUE ); 1097 1127 } … … 1100 1130 torrentRecheckDoneImpl( void * vtor ) 1101 1131 { 1102 tr_torrentRecheckCompleteness( vtor ); 1132 tr_torrent * tor = vtor; 1133 1134 assert( tr_isTorrent( tor ) ); 1135 tr_torrentRecheckCompleteness( tor ); 1103 1136 } 1104 1137 … … 1106 1139 torrentRecheckDoneCB( tr_torrent * tor ) 1107 1140 { 1141 assert( tr_isTorrent( tor ) ); 1142 1108 1143 tr_runInEventThread( tor->session, torrentRecheckDoneImpl, tor ); 1109 1144 } … … 1112 1147 tr_torrentVerify( tr_torrent * tor ) 1113 1148 { 1149 assert( tr_isTorrent( tor ) ); 1150 1114 1151 tr_verifyRemove( tor ); 1115 1152 … … 1127 1164 tr_file_index_t i; 1128 1165 struct evbuffer * buf = evbuffer_new( ); 1166 1167 assert( tr_isTorrent( tor ) ); 1129 1168 1130 1169 for( i=0; i<tor->info.fileCount; ++i ) … … 1145 1184 tr_torrent * tor = vtor; 1146 1185 1186 assert( tr_isTorrent( tor ) ); 1187 1147 1188 tr_verifyRemove( tor ); 1148 1189 tr_peerMgrStopTorrent( tor ); … … 1155 1196 tr_torrentStop( tr_torrent * tor ) 1156 1197 { 1157 if( t or)1198 if( tr_isTorrent( tor ) ) 1158 1199 { 1159 1200 tr_globalLock( tor->session ); … … 1173 1214 tr_torrent * tor = vtor; 1174 1215 1216 assert( tr_isTorrent( tor ) ); 1217 1175 1218 tr_torrentSaveResume( tor ); 1176 1219 tor->isRunning = 0; … … 1187 1230 tr_torrentFree( tr_torrent * tor ) 1188 1231 { 1189 if( t or)1232 if( tr_isTorrent( tor ) ) 1190 1233 { 1191 1234 tr_session * session = tor->session; 1235 assert( tr_isSession( session ) ); 1192 1236 tr_globalLock( session ); 1193 1237 … … 1202 1246 tr_torrentRemove( tr_torrent * tor ) 1203 1247 { 1248 assert( tr_isTorrent( tor ) ); 1249 1204 1250 tor->isDeleting = 1; 1205 1251 tr_torrentFree( tor ); … … 1235 1281 tr_completeness status ) 1236 1282 { 1237 assert( t or);1283 assert( tr_isTorrent( tor ) ); 1238 1284 assert( ( status == TR_LEECH ) 1239 1285 || ( status == TR_SEED ) … … 1249 1295 void * user_data ) 1250 1296 { 1251 assert( tor ); 1297 assert( tr_isTorrent( tor ) ); 1298 1252 1299 tor->completeness_func = func; 1253 1300 tor->completeness_func_user_data = user_data; … … 1264 1311 { 1265 1312 tr_completeness completeness; 1313 1314 assert( tr_isTorrent( tor ) ); 1266 1315 1267 1316 tr_torrentLock( tor ); … … 1309 1358 tr_file * file; 1310 1359 1311 assert( t or);1360 assert( tr_isTorrent( tor ) ); 1312 1361 assert( fileIndex < tor->info.fileCount ); 1313 assert( 1314 priority == TR_PRI_LOW || priority == TR_PRI_NORMAL || priority == 1315 TR_PRI_HIGH ); 1362 assert( priority == TR_PRI_LOW || priority == TR_PRI_NORMAL || priority == TR_PRI_HIGH ); 1316 1363 1317 1364 file = &tor->info.files[fileIndex]; … … 1330 1377 tr_file_index_t i; 1331 1378 1379 assert( tr_isTorrent( tor ) ); 1380 1332 1381 tr_torrentLock( tor ); 1333 1382 … … 1344 1393 { 1345 1394 tr_priority_t ret; 1395 1396 assert( tr_isTorrent( tor ) ); 1346 1397 1347 1398 tr_torrentLock( tor ); … … 1360 1411 tr_priority_t * p; 1361 1412 1413 assert( tr_isTorrent( tor ) ); 1414 1362 1415 tr_torrentLock( tor ); 1363 1416 p = tr_new0( tr_priority_t, tor->info.fileCount ); … … 1379 1432 int doDownload; 1380 1433 1434 assert( tr_isTorrent( tor ) ); 1435 1381 1436 tr_torrentLock( tor ); 1382 1437 … … 1398 1453 tr_piece_index_t lastPiece, lastPieceDND; 1399 1454 tr_file_index_t i; 1455 1456 assert( tr_isTorrent( tor ) ); 1400 1457 1401 1458 file = &tor->info.files[fileIndex]; … … 1451 1508 tr_file_index_t i; 1452 1509 1510 assert( tr_isTorrent( tor ) ); 1511 1453 1512 tr_torrentLock( tor ); 1454 1513 … … 1466 1525 tr_bool doDownload ) 1467 1526 { 1527 assert( tr_isTorrent( tor ) ); 1528 1468 1529 tr_torrentLock( tor ); 1469 1530 tr_torrentInitFileDLs( tor, files, fileCount, doDownload ); … … 1480 1541 uint16_t maxConnectedPeers ) 1481 1542 { 1543 assert( tr_isTorrent( tor ) ); 1544 1482 1545 tor->maxConnectedPeers = maxConnectedPeers; 1483 1546 } … … 1486 1549 tr_torrentGetPeerLimit( const tr_torrent * tor ) 1487 1550 { 1551 assert( tr_isTorrent( tor ) ); 1552 1488 1553 return tor->maxConnectedPeers; 1489 1554 } … … 1498 1563 uint32_t offset ) 1499 1564 { 1500 const tr_info * inf = &tor->info;1501 1565 tr_block_index_t ret; 1502 1566 1567 assert( tr_isTorrent( tor ) ); 1568 1503 1569 ret = index; 1504 ret *= ( inf->pieceSize / tor->blockSize );1570 ret *= ( tor->info.pieceSize / tor->blockSize ); 1505 1571 ret += offset / tor->blockSize; 1506 1572 return ret; … … 1514 1580 { 1515 1581 int err = 0; 1582 1583 assert( tr_isTorrent( tor ) ); 1516 1584 1517 1585 if( index >= tor->info.pieceCount ) … … 1542 1610 uint64_t ret; 1543 1611 1612 assert( tr_isTorrent( tor ) ); 1613 1544 1614 ret = tor->info.pieceSize; 1545 1615 ret *= index; … … 1558 1628 tr_bool isChecked ) 1559 1629 { 1630 assert( tr_isTorrent( tor ) ); 1631 1560 1632 if( isChecked ) 1561 1633 tr_bitfieldAdd( &tor->checkedPieces, piece ); … … 1572 1644 const tr_piece_index_t begin = file->firstPiece; 1573 1645 const tr_piece_index_t end = file->lastPiece + 1; 1646 1647 assert( tr_isTorrent( tor ) ); 1574 1648 1575 1649 if( isChecked ) … … 1589 1663 tr_bool isChecked = TRUE; 1590 1664 1665 assert( tr_isTorrent( tor ) ); 1666 1591 1667 for( i = begin; isChecked && i < end; ++i ) 1592 1668 if( !tr_torrentIsPieceChecked( tor, i ) ) … … 1599 1675 tr_torrentUncheck( tr_torrent * tor ) 1600 1676 { 1677 assert( tr_isTorrent( tor ) ); 1678 1601 1679 tr_bitfieldRemRange ( &tor->checkedPieces, 0, tor->info.pieceCount ); 1602 1680 } … … 1605 1683 tr_torrentCountUncheckedPieces( const tr_torrent * tor ) 1606 1684 { 1685 assert( tr_isTorrent( tor ) ); 1686 1607 1687 return tor->info.pieceCount - tr_bitfieldCountTrueBits( &tor->checkedPieces ); 1608 1688 } … … 1615 1695 const size_t n = tor->info.fileCount; 1616 1696 time_t * m = tr_new0( time_t, n ); 1697 1698 assert( tr_isTorrent( tor ) ); 1617 1699 1618 1700 for( i = 0; i < n; ++i ) … … 1646 1728 tr_benc metainfo; 1647 1729 1730 assert( tr_isTorrent( tor ) ); 1731 1648 1732 /* save to the .torrent file */ 1649 1733 if( !tr_bencLoadFile( tor->info.torrent, &metainfo ) ) … … 1702 1786 time_t t ) 1703 1787 { 1788 assert( tr_isTorrent( tor ) ); 1789 1704 1790 tor->addedDate = t; 1705 1791 } … … 1710 1796 time_t t ) 1711 1797 { 1798 assert( tr_isTorrent( tor ) ); 1799 1712 1800 tor->activityDate = t; 1713 1801 } … … 1718 1806 time_t t ) 1719 1807 { 1808 assert( tr_isTorrent( tor ) ); 1809 1720 1810 tor->doneDate = t; 1721 1811 } … … 1732 1822 struct stat sb; 1733 1823 uint64_t bytesLeft = 0; 1824 1825 assert( tr_isTorrent( tor ) ); 1734 1826 1735 1827 for( it=tor->info.files, end=it+tor->info.fileCount; it!=end; ++it ) … … 1810 1902 struct stat sb; 1811 1903 char * buf; 1904 1905 assert( tr_isTorrent( tor ) ); 1812 1906 1813 1907 buf = tr_buildPath( dir, base, NULL ); … … 1853 1947 char * root = tr_buildPath( tor->downloadDir, tmp, NULL ); 1854 1948 1949 assert( tr_isTorrent( tor ) ); 1950 1855 1951 for( f=0; f<tor->info.fileCount; ++f ) 1856 1952 tr_ptrArrayInsertSorted( &torrentFiles, tor->info.files[f].name, vstrcmp ); … … 1898 1994 tr_torrentDeleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc ) 1899 1995 { 1996 assert( tr_isTorrent( tor ) ); 1997 1900 1998 if( fileFunc == NULL ) 1901 1999 fileFunc = remove; -
branches/1.5x/libtransmission/torrent.h
r7722 r7813 134 134 struct tr_ratecontrol swarmSpeed; 135 135 136 int magicNumber; 137 136 138 int error; 137 139 char errorString[128]; … … 278 280 } 279 281 282 /*** 283 **** 284 ***/ 285 286 enum 287 { 288 TORRENT_MAGIC_NUMBER = 95549 289 }; 290 291 static inline tr_bool tr_isTorrent( const tr_torrent * tor ) 292 { 293 return ( tor != NULL ) 294 && ( tor->magicNumber == TORRENT_MAGIC_NUMBER ) 295 && ( tr_isSession( tor->session ) ); 296 } 297 280 298 #endif -
branches/1.5x/libtransmission/tr-getopt.c
r7664 r7813 8 8 * the Transmission project. 9 9 * 10 * $Id: tr-getopt.c 7 658 2009-01-10 23:09:07Z charles $10 * $Id: tr-getopt.c 7783 2009-01-23 18:44:15Z charles $ 11 11 */ 12 12 … … 26 26 getArgName( const tr_option * opt ) 27 27 { 28 c har * arg;28 const char * arg; 29 29 30 30 if( !opt->has_arg ) -
branches/1.5x/libtransmission/tr-getopt.h
r7664 r7813 31 31 { 32 32 int val; /* the value to return from tr_getopt() */ 33 c har * longName; /* --long-form */34 c har * description; /* option's description for tr_getopt_usage() */35 c har * shortName; /* short form */33 const char * longName; /* --long-form */ 34 const char * description; /* option's description for tr_getopt_usage() */ 35 const char * shortName; /* short form */ 36 36 int has_arg; /* 0 for no argument, 1 for argument */ 37 c har * argName; /* argument's description for tr_getopt_usage() */37 const char * argName; /* argument's description for tr_getopt_usage() */ 38 38 } 39 39 tr_option; -
branches/1.5x/libtransmission/trevent.c
r7664 r7813 233 233 { 234 234 tr_event_handle * eh = veh; 235 236 235 tr_dbg( "Starting libevent thread" ); 237 236 … … 241 240 #endif 242 241 242 eh->base = event_init( ); 243 243 eh->session->events = eh; 244 244 245 245 /* listen to the pipe's read fd */ 246 event_set( &eh->pipeEvent, eh->fds[0], EV_READ | EV_PERSIST, 247 readFromPipe, 248 veh ); 246 event_set( &eh->pipeEvent, eh->fds[0], EV_READ | EV_PERSIST, readFromPipe, veh ); 249 247 event_add( &eh->pipeEvent, NULL ); 250 248 event_set_log_callback( logFunc ); 249 250 /* loop until all the events are done */ 251 251 event_dispatch( ); 252 252 253 /* shut down the thread */ 253 254 tr_lockFree( eh->lock ); 254 255 event_base_free( eh->base ); … … 263 264 tr_event_handle * eh; 264 265 266 session->events = NULL; 267 265 268 eh = tr_new0( tr_event_handle, 1 ); 266 269 eh->lock = tr_lockNew( ); 267 270 pipe( eh->fds ); 268 271 eh->session = session; 269 eh->base = event_init( );270 272 eh->thread = tr_threadNew( libeventThreadFunc, eh ); 273 274 /* wait until the libevent thread is running */ 275 while( session->events == NULL ) 276 tr_wait( 100 ); 271 277 } 272 278 … … 274 280 tr_eventClose( tr_session * session ) 275 281 { 282 assert( tr_isSession( session ) ); 283 276 284 session->events->die = TRUE; 277 285 tr_deepLog( __FILE__, __LINE__, NULL, "closing trevent pipe" ); … … 286 294 tr_amInEventThread( tr_session * session ) 287 295 { 288 assert( session);296 assert( tr_isSession( session ) ); 289 297 assert( session->events ); 290 298 … … 341 349 tr_timer * timer; 342 350 343 assert( session);344 assert( session->events );351 assert( tr_isSession( session ) ); 352 assert( session->events != NULL ); 345 353 346 354 timer = tr_new0( tr_timer, 1 ); … … 374 382 void func( void* ), void * user_data ) 375 383 { 376 assert( session);377 assert( session->events );384 assert( tr_isSession( session ) ); 385 assert( session->events != NULL ); 378 386 379 387 if( tr_amInThread( session->events->thread ) ) … … 400 408 tr_eventGetBase( tr_session * session ) 401 409 { 410 assert( tr_isSession( session ) ); 411 402 412 return session->events->base; 403 413 } -
branches/1.5x/libtransmission/utils-test.c
r7767 r7813 7 7 #include "crypto.h" 8 8 9 # define VERBOSE 09 #undef VERBOSE 10 10 #define NUM_LOOPS 1 11 11 #define SPEED_TEST 0 12 12 13 13 #if SPEED_TEST 14 #undef VERBOSE 15 #define VERBOSE 0 14 #define VERBOSE 16 15 #undef NUM_LOOPS 17 16 #define NUM_LOOPS 200 … … 20 19 static int test = 0; 21 20 22 #define check( A ) \ 21 #ifdef VERBOSE 22 #define check( A ) \ 23 23 { \ 24 24 ++test; \ 25 25 if( A ){ \ 26 if( VERBOSE ) \ 27 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ 28 __LINE__ );\ 26 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 29 27 } else { \ 30 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ 31 __LINE__ ); \ 28 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 32 29 return test; \ 33 30 } \ 34 31 } 32 #else 33 #define check( A ) \ 34 { \ 35 ++test; \ 36 if( !( A ) ){ \ 37 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ 38 return test; \ 39 } \ 40 } 41 #endif 35 42 36 43 static int … … 188 195 189 196 /* base64 */ 190 in = "YOYO!"; 191 out = tr_base64_encode( in, -1, &len ); 197 out = tr_base64_encode( "YOYO!", -1, &len ); 192 198 check( out ); 193 199 check( !strcmp( out, "WU9ZTyE=\n" ) ); -
branches/1.5x/libtransmission/utils.c
r7767 r7813 37 37 #include "utils.h" 38 38 #include "platform.h" 39 #include "version.h" 39 40 40 41 static tr_lock * messageLock = NULL; … … 192 193 193 194 char* 194 tr_getLogTimeStr( char * buf, 195 int buflen ) 195 tr_getLogTimeStr( char * buf, int buflen ) 196 196 { 197 197 char tmp[64]; … … 211 211 return buf; 212 212 } 213 214 void 215 tr_assertImpl( const char * file, int line, const char * test, const char * fmt, ... ) 216 { 217 char buf[64]; 218 fprintf( stderr, "[%s] Transmission %s Assertion \"%s\" failed at %s:%d. ", 219 tr_getLogTimeStr( buf, sizeof( buf ) ), 220 LONG_VERSION_STRING, test, file, line ); 221 if( fmt && *fmt ) { 222 va_list args; 223 fputc( '(', stderr ); 224 va_start( args, fmt ); 225 vfprintf( stderr, fmt, args ); 226 va_end( args ); 227 fputs( ") ", stderr ); 228 } 229 fputs( "Please report this bug at <http://trac.transmissionbt.com/newticket>; Thank you.\n", stderr ); 230 abort( ); 231 } 232 213 233 214 234 tr_bool -
branches/1.5x/libtransmission/utils.h
r7767 r7813 104 104 ****/ 105 105 106 void tr_assertImpl( const char * file, int line, const char * test, const char * fmt, ... ) TR_GNUC_PRINTF( 4, 5 ); 107 108 #ifdef NDEBUG 109 #define tr_assert( test, fmt, ... ) 110 #else 111 #define tr_assert( test, fmt, ... ) \ 112 do { if( ! ( test ) ) tr_assertImpl( __FILE__, __LINE__, #test, fmt, __VA_ARGS__ ); } while( 0 ) 113 #endif 114 106 115 int tr_msgLoggingIsActive( int level ); 107 116 -
branches/1.5x/libtransmission/verify.c
r7664 r7813 35 35 36 36 static void 37 fireCheckDone( tr_torrent * torrent, 38 tr_verify_done_cb verify_done_cb ) 39 { 37 fireCheckDone( tr_torrent * tor, tr_verify_done_cb verify_done_cb ) 38 { 39 assert( tr_isTorrent( tor ) ); 40 40 41 if( verify_done_cb ) 41 verify_done_cb( tor rent);42 verify_done_cb( tor ); 42 43 } 43 44 44 45 static struct verify_node currentNode; 45 46 static tr_list * verifyList = NULL; 47 48 static tr_thread * verifyThread = NULL; 49 50 static int stopCurrent = FALSE; 46 static tr_list * verifyList = NULL; 47 static tr_thread * verifyThread = NULL; 48 static int stopCurrent = FALSE; 51 49 52 50 static tr_lock* … … 145 143 146 144 tr_torinf( tor, _( "Verifying torrent" ) ); 145 assert( tr_isTorrent( tor ) ); 147 146 tor->verifyState = TR_VERIFY_NOW; 148 147 buffer = tr_new( uint8_t, tor->info.pieceSize ); … … 151 150 tr_free( buffer ); 152 151 tor->verifyState = TR_VERIFY_NONE; 152 assert( tr_isTorrent( tor ) ); 153 153 154 154 if( !stopCurrent ) … … 169 169 { 170 170 const int uncheckedCount = tr_torrentCountUncheckedPieces( tor ); 171 172 assert( tr_isTorrent( tor ) ); 171 173 172 174 if( !uncheckedCount ) … … 211 213 tr_lockLock( lock ); 212 214 215 assert( tr_isTorrent( tor ) ); 216 213 217 found = ( tor == currentNode.torrent ) 214 218 || ( tr_list_find( verifyList, tor, compareVerifyByTorrent ) != NULL ); … … 222 226 { 223 227 tr_lock * lock = getVerifyLock( ); 224 225 228 tr_lockLock( lock ); 229 230 assert( tr_isTorrent( tor ) ); 226 231 227 232 if( tor == currentNode.torrent ) -
branches/1.5x/libtransmission/web.c
r7741 r7813 15 15 16 16 #include <event.h> 17 18 #define CURL_DISABLE_TYPECHECK /* otherwise -Wunreachable-code goes insane */ 17 19 #include <curl/curl.h> 18 20 … … 245 247 { 246 248 struct timeval interval; 249 250 assert( tr_amInEventThread( g->session ) ); 251 assert( g->session != NULL ); 252 assert( g->session->events != NULL ); 253 247 254 stop_timer( g ); 248 255 dbgmsg( "adding a timeout for %ld seconds from now", g->timer_ms/1000L ); … … 356 363 | (( action & CURL_POLL_IN ) ? EV_READ : 0 ) 357 364 | (( action & CURL_POLL_OUT ) ? EV_WRITE : 0 ); 365 366 assert( tr_amInEventThread( g->session ) ); 367 assert( g->session != NULL ); 368 assert( g->session->events != NULL ); 369 358 370 dbgmsg( "setsock: fd is %d, curl action is %d, libevent action is %d", 359 371 sockfd, action, kind );
Note: See TracChangeset
for help on using the changeset viewer.