Changeset 7336
- Timestamp:
- Dec 9, 2008, 10:05:45 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bandwidth.c
r7265 r7336 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 … … 276 272 if( !b->band[dir].isLimited || ( b->band[dir].bytesLeft > 0 ) ) 277 273 { 278 int i, n=0; 279 short what = dir==TR_UP ? EV_WRITE : EV_READ; 280 struct tr_iobuf ** iobufs = (struct tr_iobuf**) tr_ptrArrayPeek( b->iobufs, &n ); 274 int i; 275 const int n = tr_ptrArraySize( b->iobufs ); 276 for( i=0; i<n; ++i ) 277 tr_ptrArrayAppend( addme_buffers, tr_ptrArrayNth( b->iobufs, i ) ); 278 } 279 281 280 #ifdef DEBUG_DIRECTION 282 281 if( ( dir == DEBUG_DIRECTION ) && ( n > 1 ) ) 283 282 fprintf( stderr, "bandwidth %p has %d iobufs\n", b, n ); 284 283 #endif 285 for( i=0; i<n; ++i )286 tr_iobuf_enable( iobufs[i], what );287 }288 284 289 285 /* all children should reallocate too */ … … 296 292 } 297 293 294 void 295 tr_bandwidthAllocate( tr_bandwidth * b, 296 tr_direction dir, 297 int period_msec ) 298 { 299 int n; 300 tr_ptrArray * tmp; 301 struct tr_iobuf ** buffers; 302 const short what = dir==TR_UP ? EV_WRITE : EV_READ; 303 304 tmp = tr_ptrArrayNew( ); 305 allocateBandwidth( b, dir, period_msec, tmp ); 306 buffers = (struct tr_iobuf**) tr_ptrArrayPeek( b->children, &n ); 307 308 /* notify the io buffers in a random order s.t. no 309 particular peer gets to hog all the bandwidth */ 310 while( n > 0 ) { 311 const int i = tr_cryptoRandInt( n ); 312 tr_iobuf_enable( buffers[i], what ); 313 buffers[i] = buffers[n-1]; 314 --n; 315 } 316 317 tr_ptrArrayFree( tmp, NULL ); 318 } 319 298 320 /*** 299 321 ****
Note: See TracChangeset
for help on using the changeset viewer.