Changeset 7403
- Timestamp:
- Dec 15, 2008, 9:22:11 PM (13 years ago)
- Location:
- branches/1.4x/libtransmission
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.4x/libtransmission/bandwidth.c
r7375 r7403 250 250 tr_direction dir, 251 251 int period_msec, 252 tr_ptrArray * addme_buffers)252 tr_ptrArray * iobuf_pool ) 253 253 { 254 254 assert( isBandwidth( b ) ); … … 269 269 } 270 270 271 /* notify the io buffers that there's more bandwidth available */272 271 { 273 272 int i; 274 273 const int n = tr_ptrArraySize( b->iobufs ); 275 274 for( i=0; i<n; ++i ) 276 tr_ptrArrayAppend( addme_buffers, tr_ptrArrayNth( b->iobufs, i ) );275 tr_ptrArrayAppend( iobuf_pool, tr_ptrArrayNth( b->iobufs, i ) ); 277 276 } 278 277 … … 287 286 struct tr_bandwidth ** children = (struct tr_bandwidth**) tr_ptrArrayPeek( b->children, &n ); 288 287 for( i=0; i<n; ++i ) 289 tr_bandwidthAllocate( children[i], dir, period_msec);288 allocateBandwidth( children[i], dir, period_msec, iobuf_pool ); 290 289 } 291 290 } … … 299 298 tr_ptrArray * tmp; 300 299 struct tr_iobuf ** buffers; 301 const s hort what = dir==TR_UP ? EV_WRITE : EV_READ;300 const size_t chunkSize = 1024; /* arbitrary */ 302 301 303 302 tmp = tr_ptrArrayNew( ); … … 305 304 buffers = (struct tr_iobuf**) tr_ptrArrayPeek( tmp, &n ); 306 305 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 306 /* loop through all the peers, reading and writing in small chunks, 307 * until we run out of bandwidth or peers. we do it this way to 308 * prevent one peer from using up all the bandwidth */ 309 while( n > 0 ) 310 { 311 int i; 312 for( i=0; i<n; ) 313 { 314 int byteCount; 315 if( dir == TR_UP ) 316 byteCount = tr_iobuf_flush_output_buffer( buffers[i], chunkSize ); 317 else 318 byteCount = tr_iobuf_tryread( buffers[i], chunkSize ); 319 if( byteCount == (int)chunkSize ) 320 ++i; 321 else 322 buffers[i] = buffers[--n]; 323 } 324 } 325 326 /* cleanup */ 316 327 tr_ptrArrayFree( tmp, NULL ); 317 328 } -
branches/1.4x/libtransmission/iobuf.c
r7177 r7403 70 70 int magicNumber; 71 71 72 int fd; 73 72 74 int timeout_read; /* in seconds */ 73 75 int timeout_write; /* in seconds */ … … 89 91 90 92 static int 91 tr_evbuffer_write( struct evbuffer *buffer, int fd, size_t maxlen)92 { 93 int n = MIN( EVBUFFER_LENGTH( buffer ), maxlen);93 tr_evbuffer_write( struct evbuffer *buffer, int fd, size_t howmuch ) 94 { 95 int n = MIN( EVBUFFER_LENGTH( buffer ), howmuch ); 94 96 95 97 #ifdef WIN32 … … 107 109 } 108 110 111 int 112 tr_iobuf_flush_output_buffer( struct tr_iobuf * b, size_t howmuch ) 113 { 114 int res; 115 116 assert( isBuf( b ) ); 117 118 howmuch = tr_bandwidthClamp( b->bandwidth, TR_UP, howmuch ); 119 howmuch = MIN( howmuch, EVBUFFER_LENGTH( b->output ) ); 120 121 res = howmuch ? tr_evbuffer_write( b->output, b->fd, howmuch ) : 0; 122 123 if( ( res > 0 ) && ( b->writecb != NULL ) ) 124 (*b->writecb)( b, (size_t)res, b->cbarg ); 125 126 if( ( res < 0 ) && ( b->errorcb != NULL ) && ( errno != EAGAIN && errno != EINTR && errno != EINPROGRESS ) ) 127 (*b->errorcb)( b, (short)res, b->cbarg ); 128 129 return res; 130 } 131 132 int 133 tr_iobuf_tryread( struct tr_iobuf * b, size_t howmuch ) 134 { 135 int res; 136 137 assert( isBuf( b ) ); 138 139 howmuch = tr_bandwidthClamp( b->bandwidth, TR_DOWN, howmuch ); 140 141 res = howmuch ? evbuffer_read( b->input, b->fd, howmuch ) : 0; 142 143 if( ( res > 0 ) && ( b->readcb != NULL ) ) 144 (*b->readcb)( b, (size_t)res, b->cbarg ); 145 146 if( ( res < 0 ) && ( b->errorcb != NULL ) && ( errno != EAGAIN && errno != EINTR ) ) 147 (*b->errorcb)( b, (short)res, b->cbarg ); 148 149 return res; 150 } 151 152 109 153 static int 110 154 tr_iobuf_add(struct event *ev, int timeout) … … 259 303 b = tr_new0( struct tr_iobuf, 1 ); 260 304 b->magicNumber = MAGIC_NUMBER; 305 b->fd = fd; 261 306 b->session = session; 262 307 b->bandwidth = bandwidth; -
branches/1.4x/libtransmission/iobuf.h
r7177 r7403 45 45 * 2. the up/down speeds are directly constrained by our `bandwidth' object 46 46 * 3. the implementation is hidden in the .c file 47 * 48 * 4. a late addition nasty hack to read/write on demand, called from 49 * bandwidth. this actually seems to make a lot of this class redundant 50 * and probably should be refactored. 47 51 */ 48 52 struct tr_iobuf; … … 105 109 int tr_iobuf_disable( struct tr_iobuf * iobuf, short event ); 106 110 111 int tr_iobuf_flush_output_buffer( struct tr_iobuf * iobuf, size_t max ); 112 113 int tr_iobuf_tryread( struct tr_iobuf * iobuf, size_t max ); 114 107 115 #endif -
branches/1.4x/libtransmission/peer-io.c
r7176 r7403 534 534 { 535 535 /* this is all kind of arbitrary, but what seems to work well is 536 * being large enough to hold the next 15seconds' worth of input,537 * or two and a halfblocks, whichever is bigger.536 * being large enough to hold the next 20 seconds' worth of input, 537 * or a few blocks, whichever is bigger. 538 538 * It's okay to tweak this as needed */ 539 539 const double maxBlockSize = 16 * 1024; /* 16 KiB is from BT spec */ 540 540 const double currentSpeed = tr_bandwidthGetPieceSpeed( io->bandwidth, TR_UP ); 541 541 const double period = 20; /* arbitrary */ 542 return MAX( maxBlockSize* 2.5, currentSpeed*1024*period );542 return MAX( maxBlockSize*5.5, currentSpeed*1024*period ); 543 543 } 544 544
Note: See TracChangeset
for help on using the changeset viewer.