Changeset 7584
- Timestamp:
- Jan 2, 2009, 8:42:35 PM (14 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-msgs.c
r7578 r7584 1458 1458 } 1459 1459 updatePeerProgress( msgs ); 1460 tr_rcTransferred( msgs->torrent->swarmSpeed,1460 tr_rcTransferred( &msgs->torrent->swarmSpeed, 1461 1461 msgs->torrent->info.pieceSize ); 1462 1462 break; -
trunk/libtransmission/ratecontrol.c
r7069 r7584 30 30 #include "utils.h" 31 31 32 enum33 {34 INTERVAL_MSEC = TR_RATECONTROL_HISTORY_MSEC,35 36 GRANULARITY_MSEC = 250,37 38 HISTORY_SIZE = ( INTERVAL_MSEC / GRANULARITY_MSEC )39 };40 41 struct tr_transfer42 {43 uint64_t date;44 uint64_t size;45 };46 47 struct tr_ratecontrol48 {49 int newest;50 struct tr_transfer transfers[HISTORY_SIZE];51 };52 53 32 /* return the xfer rate over the last `interval' seconds in KiB/sec */ 54 33 static float … … 67 46 bytes += r->transfers[i].size; 68 47 69 if( --i == -1 ) i = HISTORY_SIZE - 1; /* circular history */48 if( --i == -1 ) i = TR_RC_HISTORY_SIZE - 1; /* circular history */ 70 49 if( i == r->newest ) break; /* we've come all the way around */ 71 50 } 72 51 73 52 return ( bytes / 1024.0 ) * ( 1000.0 / interval_msec ); 74 }75 76 /***77 ****78 ***/79 80 tr_ratecontrol*81 tr_rcInit( void )82 {83 return tr_new0( tr_ratecontrol, 1 );84 }85 86 void87 tr_rcClose( tr_ratecontrol * r )88 {89 memset( r, 0, sizeof( tr_ratecontrol ) );90 tr_free( r );91 53 } 92 54 … … 101 63 102 64 if( r ) 103 ret = rateForInterval( r, INTERVAL_MSEC );65 ret = rateForInterval( r, TR_RC_HISTORY_MSEC ); 104 66 105 67 return ret; … … 116 78 const uint64_t now = tr_date ( ); 117 79 118 if( r->transfers[r->newest].date + GRANULARITY_MSEC >= now )80 if( r->transfers[r->newest].date + TR_RC_GRANULARITY_MSEC >= now ) 119 81 r->transfers[r->newest].size += size; 120 82 else 121 83 { 122 if( ++r->newest == HISTORY_SIZE ) r->newest = 0;84 if( ++r->newest == TR_RC_HISTORY_SIZE ) r->newest = 0; 123 85 r->transfers[r->newest].date = now; 124 86 r->transfers[r->newest].size = size; -
trunk/libtransmission/ratecontrol.h
r7151 r7584 30 30 #define _TR_RATECONTROL_H_ 31 31 32 #include <string.h> /* memset() */ 33 34 #include "transmission.h" 35 36 /* these are PRIVATE IMPLEMENTATION details that should not be touched. 37 * it's included in the header for inlining and composition. */ 32 38 enum 33 39 { 34 TR_RATECONTROL_HISTORY_MSEC = 2000 40 TR_RC_HISTORY_MSEC = 2000, 41 TR_RC_GRANULARITY_MSEC = 250, 42 TR_RC_HISTORY_SIZE = ( TR_RC_HISTORY_MSEC / TR_RC_GRANULARITY_MSEC ) 35 43 }; 36 44 37 typedef struct tr_ratecontrol tr_ratecontrol; 45 /* these are PRIVATE IMPLEMENTATION details that should not be touched. 46 * it's included in the header for inlining and composition. */ 47 struct tr_transfer 48 { 49 uint64_t date; 50 uint64_t size; 51 }; 38 52 53 /* these are PRIVATE IMPLEMENTATION details that should not be touched. 54 * it's included in the header for inlining and composition. */ 55 typedef struct tr_ratecontrol 56 { 57 int newest; 58 struct tr_transfer transfers[TR_RC_HISTORY_SIZE]; 59 } 60 tr_ratecontrol; 39 61 40 tr_ratecontrol * tr_rcInit ( void ); 62 /*** 63 **** 64 ***/ 41 65 42 void tr_rcClose ( tr_ratecontrol * ratecontrol ); 66 static inline void tr_rcConstruct ( tr_ratecontrol * rc ) { memset( rc, 0, sizeof( tr_ratecontrol ) ); } 67 68 static inline void tr_rcDestruct ( tr_ratecontrol * rc ) { memset( rc, 0xDEAD, sizeof( tr_ratecontrol ) ); } 43 69 44 70 void tr_rcTransferred ( tr_ratecontrol * ratecontrol, -
trunk/libtransmission/torrent.c
r7578 r7584 502 502 tr_torrentInitFilePieces( tor ); 503 503 504 t or->swarmSpeed = tr_rcInit();504 tr_rcConstruct( &tor->swarmSpeed ); 505 505 506 506 tr_sha1( tor->obfuscatedHash, "req2", 4, … … 793 793 : 0.0; 794 794 795 s->swarmSpeed = tr_rcRate( tor->swarmSpeed );795 s->swarmSpeed = tr_rcRate( &tor->swarmSpeed ); 796 796 797 797 s->activityDate = tor->activityDate; … … 1035 1035 tr_cpDestruct( &tor->completion ); 1036 1036 1037 tr_rc Close(tor->swarmSpeed );1037 tr_rcDestruct( &tor->swarmSpeed ); 1038 1038 1039 1039 tr_trackerUnsubscribe( tor->tracker, tor->trackerSubscription ); -
trunk/libtransmission/torrent.h
r7578 r7584 31 31 32 32 #include "completion.h" /* tr_completion */ 33 #include "ratecontrol.h" /* tr_ratecontrol */ 33 34 #include "session.h" /* tr_globalLock(), tr_globalUnlock() */ 34 35 #include "utils.h" /* tr_bitfield */ … … 147 148 tr_speedlimit speedLimitMode[2]; 148 149 149 struct tr_ratecontrol *swarmSpeed;150 struct tr_ratecontrol swarmSpeed; 150 151 151 152 int error; -
trunk/libtransmission/webseed.c
r7549 r7584 41 41 uint32_t byteCount; 42 42 43 tr_ratecontrol *rateDown;43 tr_ratecontrol rateDown; 44 44 45 45 tr_session * session; … … 170 170 { 171 171 fireClientGotData( w, response_byte_count ); 172 tr_rcTransferred( w->rateDown, response_byte_count );172 tr_rcTransferred( &w->rateDown, response_byte_count ); 173 173 } 174 174 … … 257 257 const int isActive = tr_webseedIsActive( w ); 258 258 259 *setme_KiBs = isActive ? tr_rcRate( w->rateDown ) : 0.0f;259 *setme_KiBs = isActive ? tr_rcRate( &w->rateDown ) : 0.0f; 260 260 return isActive; 261 261 } … … 276 276 w->session = torrent->session; 277 277 w->content = evbuffer_new( ); 278 w->rateDown = tr_rcInit( );279 278 w->url = tr_strdup( url ); 280 279 w->callback = callback; 281 280 w->callback_userdata = callback_userdata; 281 tr_rcConstruct( &w->rateDown ); 282 282 /*fprintf( stderr, "w->callback_userdata is %p\n", w->callback_userdata );*/ 283 283 return w; … … 296 296 { 297 297 evbuffer_free( w->content ); 298 tr_rc Close(w->rateDown );298 tr_rcDestruct( &w->rateDown ); 299 299 tr_free( w->url ); 300 300 tr_free( w );
Note: See TracChangeset
for help on using the changeset viewer.