Changeset 6906
- Timestamp:
- Oct 14, 2008, 8:44:41 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/configure.ac
r6881 r6906 61 61 AC_HEADER_TIME 62 62 AC_CHECK_FUNCS([lrintf strlcpy daemon dirname basename daemon strcasecmp]) 63 AC_CHECK_SIZEOF([void*])64 63 AC_PROG_INSTALL 65 64 AC_PROG_MAKE_SET -
trunk/libtransmission/fdlimit.c
r6899 r6906 53 53 #include "utils.h" 54 54 55 #if SIZEOF_VOIDP == 856 #define TR_UINT_TO_PTR( i ) (void*)( (uint64_t)i )57 #else58 #define TR_UINT_TO_PTR( i ) ( (void*)( (uint32_t)i ) )59 #endif60 61 55 #define dbgmsg( ... ) tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ) 62 56 … … 85 79 struct tr_fd_s 86 80 { 87 int reserved; 88 int normal; 89 int normalMax; 81 int socketCount; 82 int socketMax; 90 83 tr_lock * lock; 91 84 struct tr_openfile open[TR_MAX_OPEN_FILES]; … … 369 362 ***/ 370 363 371 static tr_list * reservedSockets = NULL;372 373 static void374 setSocketPriority( int fd,375 int isReserved )376 {377 if( isReserved )378 tr_list_append( &reservedSockets, TR_UINT_TO_PTR( fd ) );379 }380 381 static int382 socketWasReserved( int fd )383 {384 return tr_list_remove_data( &reservedSockets,385 TR_UINT_TO_PTR( fd ) ) != NULL;386 }387 388 364 static int 389 365 getSocketMax( struct tr_fd_s * gFd ) 390 366 { 391 return gFd-> normalMax;367 return gFd->socketMax; 392 368 } 393 369 394 370 int 395 tr_fdSocketCreate( int type, 396 int isReserved ) 371 tr_fdSocketCreate( int type ) 397 372 { 398 373 int s = -1; … … 400 375 tr_lockLock( gFd->lock ); 401 376 402 if( isReserved || ( gFd->normal < getSocketMax( gFd )) )377 if( gFd->socketCount < getSocketMax( gFd ) ) 403 378 if( ( s = socket( AF_INET, type, 0 ) ) < 0 ) 404 379 tr_err( _( "Couldn't create socket: %s" ), … … 406 381 407 382 if( s > -1 ) 408 { 409 setSocketPriority( s, isReserved ); 410 411 if( isReserved ) 412 ++gFd->reserved; 413 else 414 ++gFd->normal; 415 } 416 417 assert( gFd->reserved >= 0 ); 418 assert( gFd->normal >= 0 ); 383 ++gFd->socketCount; 384 385 assert( gFd->socketCount >= 0 ); 419 386 420 387 tr_lockUnlock( gFd->lock ); … … 435 402 436 403 tr_lockLock( gFd->lock ); 437 if( gFd-> normal< getSocketMax( gFd ) )404 if( gFd->socketCount < getSocketMax( gFd ) ) 438 405 { 439 406 len = sizeof( sock ); … … 442 409 if( s > -1 ) 443 410 { 444 setSocketPriority( s, FALSE );445 411 *addr = sock.sin_addr; 446 412 *port = sock.sin_port; 447 gFd->normal++;413 ++gFd->socketCount; 448 414 } 449 415 tr_lockUnlock( gFd->lock ); … … 470 436 { 471 437 socketClose( s ); 472 if( socketWasReserved( s ) ) 473 --gFd->reserved; 474 else 475 --gFd->normal; 476 } 477 478 assert( gFd->reserved >= 0 ); 479 assert( gFd->normal >= 0 ); 438 --gFd->socketCount; 439 } 440 441 assert( gFd->socketCount >= 0 ); 480 442 481 443 tr_lockUnlock( gFd->lock ); … … 504 466 (rlim_t)( globalPeerLimit + NOFILE_BUFFER ) ); 505 467 setrlimit( RLIMIT_NOFILE, &rlim ); 506 gFd-> normalMax = rlim.rlim_cur - NOFILE_BUFFER;468 gFd->socketMax = rlim.rlim_cur - NOFILE_BUFFER; 507 469 tr_dbg( "setrlimit( RLIMIT_NOFILE, %d )", (int)rlim.rlim_cur ); 508 470 } 509 471 #else 510 gFd-> normalMax = globalPeerLimit;472 gFd->socketMax = globalPeerLimit; 511 473 #endif 512 474 tr_dbg( "%d usable file descriptors", globalPeerLimit ); … … 527 489 tr_lockFree( gFd->lock ); 528 490 529 tr_list_free( &reservedSockets, NULL );530 491 tr_free( gFd ); 531 492 } … … 535 496 { 536 497 assert( gFd != NULL && "tr_fdInit() must be called first!" ); 537 gFd-> normalMax = n;498 gFd->socketMax = n; 538 499 } 539 500 … … 541 502 tr_fdGetPeerLimit( void ) 542 503 { 543 return gFd ? gFd-> normalMax : -1;544 } 545 504 return gFd ? gFd->socketMax : -1; 505 } 506 -
trunk/libtransmission/fdlimit.h
r6842 r6906 80 80 * Sockets 81 81 **********************************************************************/ 82 int tr_fdSocketCreate( int type, 83 int priority ); 82 int tr_fdSocketCreate( int type ); 84 83 85 84 int tr_fdSocketAccept( int b, -
trunk/libtransmission/net.c
r6795 r6906 118 118 119 119 static int 120 createSocket( int type, 121 int priority ) 122 { 123 int fd; 124 125 fd = tr_fdSocketCreate( type, priority ); 120 createSocket( int type ) 121 { 122 int fd = tr_fdSocketCreate( type ); 126 123 127 124 if( fd >= 0 ) … … 141 138 int 142 139 tr_netOpenTCP( const struct in_addr * addr, 143 tr_port_t port, 144 int priority ) 140 tr_port_t port ) 145 141 { 146 142 int s; … … 148 144 const int type = SOCK_STREAM; 149 145 150 if( ( s = createSocket( type , priority) ) < 0 )146 if( ( s = createSocket( type ) ) < 0 ) 151 147 return -1; 152 148 … … 188 184 #endif 189 185 190 if( ( s = createSocket( type , 1) ) < 0 )186 if( ( s = createSocket( type ) ) < 0 ) 191 187 return -1; 192 188 -
trunk/libtransmission/net.h
r6795 r6906 71 71 **********************************************************************/ 72 72 int tr_netOpenTCP( const struct in_addr * addr, 73 tr_port_t port, 74 int priority ); 73 tr_port_t port ); 75 74 76 75 int tr_netBindTCP( int port ); -
trunk/libtransmission/peer-io.c
r6894 r6906 345 345 assert( torrentHash ); 346 346 347 socket = tr_netOpenTCP( in_addr, port , 0);347 socket = tr_netOpenTCP( in_addr, port ); 348 348 349 349 return socket < 0 … … 452 452 tr_netClose( io->socket ); 453 453 454 io->socket = tr_netOpenTCP( &io->in_addr, io->port , 0);454 io->socket = tr_netOpenTCP( &io->in_addr, io->port ); 455 455 456 456 if( io->socket >= 0 ) -
trunk/libtransmission/peer-mgr.c
r6895 r6906 2505 2505 Torrent * t = torrents[i]; 2506 2506 const size_t used = countPeerBandwidth( t->peers, direction ); 2507 +countHandshakeBandwidth( t->outgoingHandshakes, 2508 direction ); 2507 countHandshakeBandwidth( t->outgoingHandshakes, direction ); 2509 2508 2510 2509 /* add this torrent's bandwidth use to allBytesUsed */
Note: See TracChangeset
for help on using the changeset viewer.