From 6f5c9dcafb442637f069d490f32fbda81e114c5c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 11 Jul 2010 20:49:19 +0000 Subject: [PATCH] (trunk libt) rename tr_date() as tr_time_msec() for clarity --- libtransmission/bandwidth.c | 4 ++-- libtransmission/crypto.c | 2 +- libtransmission/fdlimit.c | 6 +++--- libtransmission/history.c | 2 +- libtransmission/history.h | 4 ++-- libtransmission/peer-mgr.c | 18 +++++++++--------- libtransmission/peer-msgs.c | 10 +++++----- libtransmission/ratecontrol.c | 4 ++-- libtransmission/torrent.c | 2 +- libtransmission/utils.c | 2 +- libtransmission/utils.h | 2 +- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/libtransmission/bandwidth.c b/libtransmission/bandwidth.c index e8ccd349a..ff2e93a9f 100644 --- a/libtransmission/bandwidth.c +++ b/libtransmission/bandwidth.c @@ -34,7 +34,7 @@ static unsigned int getSpeed_Bps( const struct bratecontrol * r, unsigned int interval_msec, uint64_t now ) { uint64_t bytes = 0; - const uint64_t cutoff = (now?now:tr_date()) - interval_msec; + const uint64_t cutoff = (now?now:tr_time_msec()) - interval_msec; int i = r->newest; for( ;; ) @@ -381,5 +381,5 @@ tr_bandwidthUsed( tr_bandwidth * b, size_t byteCount, tr_bool isPieceData ) { - bandwidthUsedImpl( b, dir, byteCount, isPieceData, tr_date( ) ); + bandwidthUsedImpl( b, dir, byteCount, isPieceData, tr_time_msec( ) ); } diff --git a/libtransmission/crypto.c b/libtransmission/crypto.c index dce13face..5e8b01b3b 100644 --- a/libtransmission/crypto.c +++ b/libtransmission/crypto.c @@ -347,7 +347,7 @@ tr_cryptoWeakRandInt( int upperBound ) if( !init ) { - srand( tr_date( ) ); + srand( tr_time_msec( ) ); init = TRUE; } diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 51ab6dc94..7ca841515 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -474,7 +474,7 @@ tr_fdFileGetCached( tr_session * session, if( ( match != NULL ) && ( !doWrite || match->isWritable ) ) { - match->date = tr_date( ); + match->date = tr_time_msec( ); return match->fd; } @@ -532,7 +532,7 @@ tr_fdFileCheckout( tr_session * session, dbgmsg( "it's not already open. looking for an open slot or an old file." ); while( winner < 0 ) { - uint64_t date = tr_date( ) + 1; + uint64_t date = tr_time_msec( ) + 1; /* look for the file that's been open longest */ for( i=0; iopenFileLimit; ++i ) @@ -582,7 +582,7 @@ tr_fdFileCheckout( tr_session * session, dbgmsg( "checking out '%s' in slot %d", filename, winner ); o->torrentId = torrentId; o->fileNum = fileNum; - o->date = tr_date( ); + o->date = tr_time_msec( ); return o->fd; } diff --git a/libtransmission/history.c b/libtransmission/history.c index e0bd93e81..0106a0429 100644 --- a/libtransmission/history.c +++ b/libtransmission/history.c @@ -44,7 +44,7 @@ unsigned int tr_historyGet( const tr_recentHistory * h, uint64_t now, unsigned int msec ) { unsigned int n = 0; - const uint64_t cutoff = (now?now:tr_date()) - msec; + const uint64_t cutoff = (now?now:tr_time_msec()) - msec; int i = h->newest; for( ;; ) diff --git a/libtransmission/history.h b/libtransmission/history.h index 27c7de738..f0010006d 100644 --- a/libtransmission/history.h +++ b/libtransmission/history.h @@ -39,14 +39,14 @@ void tr_historyFree( tr_recentHistory * ); /** * @brief add a counter to the recent history object. - * @param when the current time in msec, such as from tr_date() + * @param when the current time in msec, such as from tr_time_msec() * @param n how many items to add to the history's counter */ void tr_historyAdd( tr_recentHistory *, uint64_t when, unsigned int n ); /** * @brief count how many events have occurred in the last N seconds. - * @param when the current time in msec, such as from tr_date() + * @param when the current time in msec, such as from tr_time_msec() * @param seconds how many seconds to count back through. */ unsigned int tr_historyGet( const tr_recentHistory *, uint64_t when, unsigned int seconds ); diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 2749cd9ba..79a691048 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1183,7 +1183,7 @@ refillUpkeep( int foo UNUSED, short bar UNUSED, void * vmgr ) managerLock( mgr ); now = tr_time( ); - now_msec = tr_date( ); + now_msec = tr_time_msec( ); too_old = now - REQUEST_TTL_SECS; tor = NULL; @@ -1437,7 +1437,7 @@ peerCallbackFunc( tr_peer * peer, const tr_peer_event * e, void * vt ) pieceListRemoveRequest( t, block ); if( peer != NULL ) - tr_historyAdd( peer->blocksSentToClient, tr_date( ), 1 ); + tr_historyAdd( peer->blocksSentToClient, tr_time_msec( ), 1 ); if( tr_cpBlockIsComplete( &tor->completion, block ) ) { @@ -2286,7 +2286,7 @@ tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor ) webseedCount = tr_ptrArraySize( &t->webseeds ); assert( webseedCount == tor->info.webseedCount ); ret = tr_new0( double, webseedCount ); - now = tr_date( ); + now = tr_time_msec( ); for( i=0; ipeers ); peers = (const tr_peer**) tr_ptrArrayBase( &t->peers ); ret = tr_new0( tr_peer_stat, size ); - now = tr_date( ); + now = tr_time_msec( ); for( i=0; ipeers ); @@ -2743,7 +2743,7 @@ rechokePulse( int foo UNUSED, short bar UNUSED, void * vmgr ) tr_peerMgr * mgr = vmgr; managerLock( mgr ); - now = tr_date( ); + now = tr_time_msec( ); while(( tor = tr_torrentNext( mgr->session, tor ))) { if( tor->isRunning ) { rechokeUploads( tor->torrentPeers, now ); @@ -2852,7 +2852,7 @@ getPeersToClose( Torrent * t, tr_close_type_t closeType, const time_t now, int * if( shouldPeerBeClosed( t, peers[i], peerCount, now ) == closeType ) ret[outsize++] = peers[i]; - sortPeersByLivelinessReverse ( ret, NULL, outsize, tr_date( ) ); + sortPeersByLivelinessReverse ( ret, NULL, outsize, tr_time_msec( ) ); *setmeSize = outsize; return ret; @@ -3100,7 +3100,7 @@ reconnectPulse( int foo UNUSED, short bar UNUSED, void * vmgr ) { tr_torrent * tor; tr_peerMgr * mgr = vmgr; - const uint64_t now = tr_date( ); + const uint64_t now = tr_time_msec( ); /** *** enforce the per-session and per-torrent peer limits @@ -3445,7 +3445,7 @@ getPeerCandidates( tr_session * session, int * candidateCount ) struct peer_candidate * candidates; struct peer_candidate * walk; const time_t now = tr_time( ); - const uint64_t now_msec = tr_date( ); + const uint64_t now_msec = tr_time_msec( ); /* leave 5% of connection slots for incoming connections -- ticket #2609 */ const int maxCandidates = tr_sessionGetPeerLimit( session ) * 0.95; diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 88d8fe1a9..9e9d77db8 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -1395,7 +1395,7 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ) case BT_UNCHOKE: dbgmsg( msgs, "got Unchoke" ); msgs->peer->clientIsChoked = 0; - updateDesiredRequestCount( msgs, tr_date( ) ); + updateDesiredRequestCount( msgs, tr_time_msec( ) ); break; case BT_INTERESTED: @@ -1455,7 +1455,7 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ) tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.index ); tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.offset ); tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.length ); - tr_historyAdd( msgs->peer->cancelsSentToClient, tr_date( ), 1 ); + tr_historyAdd( msgs->peer->cancelsSentToClient, tr_time_msec( ), 1 ); dbgmsg( msgs, "got a Cancel %u:%u->%u", r.index, r.offset, r.length ); for( i=0; ipeer->pendingReqsToClient; ++i ) { @@ -1929,7 +1929,7 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now ) tr_peerIoWriteBuf( io, out, TRUE ); bytesWritten += EVBUFFER_LENGTH( out ); msgs->clientSentAnythingAt = now; - tr_historyAdd( msgs->peer->blocksSentToPeer, tr_date( ), 1 ); + tr_historyAdd( msgs->peer->blocksSentToPeer, tr_time_msec( ), 1 ); } evbuffer_free( out ); @@ -1972,7 +1972,7 @@ peerPulse( void * vmsgs ) const time_t now = tr_time( ); if ( tr_isPeerIo( msgs->peer->io ) ) { - updateDesiredRequestCount( msgs, tr_date( ) ); + updateDesiredRequestCount( msgs, tr_time_msec( ) ); updateBlockRequests( msgs ); updateMetadataRequests( msgs, now ); } @@ -2360,7 +2360,7 @@ tr_peerMsgsNew( struct tr_torrent * torrent, } tr_peerIoSetIOFuncs( m->peer->io, canRead, didWrite, gotError, m ); - updateDesiredRequestCount( m, tr_date( ) ); + updateDesiredRequestCount( m, tr_time_msec( ) ); return m; } diff --git a/libtransmission/ratecontrol.c b/libtransmission/ratecontrol.c index 2fbc23ce6..af29ed10b 100644 --- a/libtransmission/ratecontrol.c +++ b/libtransmission/ratecontrol.c @@ -36,7 +36,7 @@ rateForInterval( const tr_ratecontrol * r, uint64_t now ) { uint64_t bytes = 0; - const uint64_t cutoff = (now?now:tr_date()) - interval_msec; + const uint64_t cutoff = (now?now:tr_time_msec()) - interval_msec; int i = r->newest; for( ; ; ) @@ -76,7 +76,7 @@ void tr_rcTransferred( tr_ratecontrol * r, size_t size ) { - const uint64_t now = tr_date ( ); + const uint64_t now = tr_time_msec ( ); if( r->transfers[r->newest].date + TR_RC_GRANULARITY_MSEC >= now ) r->transfers[r->newest].size += size; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 5e8d4dd71..ac4fbce5e 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -976,7 +976,7 @@ tr_torrentStat( tr_torrent * tor ) &s->peersGettingFromUs, s->peersFrom ); - now = tr_date( ); + now = tr_time_msec( ); d = tr_peerMgrGetWebseedSpeed_Bps( tor, now ); s->rawUploadSpeed_KBps = toSpeedKBps( tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_UP ) ); s->pieceUploadSpeed_KBps = toSpeedKBps( tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_UP ) ); diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 4acc3c448..5a54b3cfe 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -785,7 +785,7 @@ tr_str_has_suffix( const char *str, const char *suffix ) ****/ uint64_t -tr_date( void ) +tr_time_msec( void ) { struct timeval tv; diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 0c1ad757c..62e24843f 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -265,7 +265,7 @@ void tr_timerAddMsec( struct event * timer, int milliseconds ) TR_GNUC_NONNULL(1 /** @brief return the current date in milliseconds */ -uint64_t tr_date( void ); +uint64_t tr_time_msec( void ); /** @brief sleep the specified number of milliseconds */ void tr_wait_msec( long int delay_milliseconds );