Changeset 7375
- Timestamp:
- Dec 14, 2008, 2:44:00 AM (12 years ago)
- Location:
- branches/1.4x/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.4x/libtransmission/bandwidth.c
r7365 r7375 18 18 #include "transmission.h" 19 19 #include "bandwidth.h" 20 #include "crypto.h" 20 21 #include "iobuf.h" 21 22 #include "ptrarray.h" … … 245 246 #endif 246 247 247 void 248 tr_bandwidthAllocate( tr_bandwidth * b, 249 tr_direction dir, 250 int period_msec ) 248 static void 249 allocateBandwidth( tr_bandwidth * b, 250 tr_direction dir, 251 int period_msec, 252 tr_ptrArray * addme_buffers ) 251 253 { 252 254 assert( isBandwidth( b ) ); … … 256 258 { 257 259 const double desiredSpeed = b->band[dir].desiredSpeed; 258 #if 0259 const double currentSpeed = getSpeed( &b->band[dir].piece, HISTORY_MSEC - period_msec );260 const double pulseCount = ( HISTORY_MSEC - period_msec ) / (double)period_msec;261 const double nextPulseSpeed = desiredSpeed * ( pulseCount + 1 ) - ( currentSpeed * pulseCount );262 #else263 260 const double nextPulseSpeed = desiredSpeed; 264 #endif265 261 b->band[dir].bytesLeft = MAX( 0.0, nextPulseSpeed * 1024.0 * period_msec / 1000.0 ); 266 262 … … 275 271 /* notify the io buffers that there's more bandwidth available */ 276 272 { 277 int i, n=0; 278 short what = dir==TR_UP ? EV_WRITE : EV_READ; 279 struct tr_iobuf ** iobufs = (struct tr_iobuf**) tr_ptrArrayPeek( b->iobufs, &n ); 273 int i; 274 const int n = tr_ptrArraySize( b->iobufs ); 275 for( i=0; i<n; ++i ) 276 tr_ptrArrayAppend( addme_buffers, tr_ptrArrayNth( b->iobufs, i ) ); 277 } 278 280 279 #ifdef DEBUG_DIRECTION 281 280 if( ( dir == DEBUG_DIRECTION ) && ( n > 1 ) ) 282 281 fprintf( stderr, "bandwidth %p has %d iobufs\n", b, n ); 283 282 #endif 284 for( i=0; i<n; ++i )285 tr_iobuf_enable( iobufs[i], what );286 }287 283 288 284 /* all children should reallocate too */ … … 295 291 } 296 292 293 void 294 tr_bandwidthAllocate( tr_bandwidth * b, 295 tr_direction dir, 296 int period_msec ) 297 { 298 int n; 299 tr_ptrArray * tmp; 300 struct tr_iobuf ** buffers; 301 const short what = dir==TR_UP ? EV_WRITE : EV_READ; 302 303 tmp = tr_ptrArrayNew( ); 304 allocateBandwidth( b, dir, period_msec, tmp ); 305 buffers = (struct tr_iobuf**) tr_ptrArrayPeek( tmp, &n ); 306 307 /* notify the io buffers in a random order s.t. no 308 particular peer gets to hog all the bandwidth */ 309 while( n > 0 ) { 310 const int i = tr_cryptoRandInt( n ); 311 tr_iobuf_enable( buffers[i], what ); 312 buffers[i] = buffers[n-1]; 313 --n; 314 } 315 316 tr_ptrArrayFree( tmp, NULL ); 317 } 318 297 319 /*** 298 320 **** -
branches/1.4x/libtransmission/platform.c
r7372 r7375 11 11 */ 12 12 13 #include <event.h> 14 13 15 #ifdef __BEOS__ 14 16 #include <signal.h> … … 103 105 return tr_areThreadsEqual( tr_getCurrentThread( ), t->thread ); 104 106 } 105 106 #include <event.h>107 107 108 108 #ifdef WIN32
Note: See TracChangeset
for help on using the changeset viewer.