From 5401979ffa1dd0c0fbd8abf884f7ea7b291b0208 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 22 Jun 2007 04:30:39 +0000 Subject: [PATCH] misc cleanup.. ansification; fix my own typos, etc... --- libtransmission/makemeta.c | 8 +++++--- libtransmission/makemeta.h | 2 +- libtransmission/peer.c | 36 +++++++++++++----------------------- libtransmission/platform.c | 18 ++++++++++++++++++ libtransmission/platform.h | 30 ++++++------------------------ 5 files changed, 43 insertions(+), 51 deletions(-) diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index 72b35e626..51c792fad 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -142,7 +142,7 @@ tr_metaInfoBuilderCreate( tr_handle_t * handle, const char * topFile ) for( walk=files; walk!=NULL; walk=walk->next ) ++ret->fileCount; - ret->files = tr_calloc( ret->fileCount, sizeof(tr_metainfo_builder_file_t) ); + ret->files = tr_calloc(ret->fileCount, sizeof(tr_metainfo_builder_file_t)); for( i=0, walk=files; walk!=NULL; ++i ) { @@ -206,14 +206,16 @@ getHashInfo ( tr_metainfo_builder_t * b ) while ( totalRemain ) { uint8_t *bufptr = buf; - const uint64_t thisPieceSize = MIN( (uint32_t)b->pieceSize, totalRemain ); + const uint64_t thisPieceSize = + MIN( (uint32_t)b->pieceSize, totalRemain ); uint64_t pieceRemain = thisPieceSize; assert( b->pieceIndex < b->pieceCount ); while( pieceRemain ) { - const uint64_t n_this_pass = MIN( (b->files[fileIndex].size - off), pieceRemain ); + const uint64_t n_this_pass = + MIN( (b->files[fileIndex].size - off), pieceRemain ); fread( bufptr, 1, n_this_pass, fp ); bufptr += n_this_pass; off += n_this_pass; diff --git a/libtransmission/makemeta.h b/libtransmission/makemeta.h index a04cddf83..4284ea628 100644 --- a/libtransmission/makemeta.h +++ b/libtransmission/makemeta.h @@ -21,7 +21,7 @@ tr_metainfo_builder_file_t; typedef struct tr_metainfo_builder_s { /** - *** These are set by tr_makeMetaInfo() + *** These are set by tr_makeMetaInfoBuilderCreate() *** and cleaned up by tr_metaInfoBuilderFree() **/ diff --git a/libtransmission/peer.c b/libtransmission/peer.c index 935d0d898..8fe76bbe9 100644 --- a/libtransmission/peer.c +++ b/libtransmission/peer.c @@ -56,7 +56,7 @@ static const int SWIFT_INITIAL_CREDIT = 64 * 1024; /* 64 KiB */ /** * We expend a fraction of our torrent's total upload speed - * on on largesse by uniformly distributing free credit to + * on largesse by uniformly distributing free credit to * all of our peers. This too helps prevent gridlock. */ static const double SWIFT_LARGESSE = 0.05; /* 5% of our UL */ @@ -602,11 +602,11 @@ writeEnd: int * pool = getPreferredPieces ( tor, peer, &poolSize, &endgame ); /* TODO: add some asserts to see if this bitfield is really necessary */ - tr_bitfield_t * blocksAlreadyRequested = tr_bitfieldNew( tor->blockCount ); + tr_bitfield_t * requestedBlocks = tr_bitfieldNew( tor->blockCount ); for( i=0; iinRequestCount; ++i) { const tr_request_t * r = &peer->inRequests[i]; const int block = tr_block( r->index, r->begin ); - tr_bitfieldAdd( blocksAlreadyRequested, block ); + tr_bitfieldAdd( requestedBlocks, block ); } for( i=0; iinRequestCountcompletion, piece, &unused) : tr_cpMissingBlockInPiece ( tor->completion, piece ); - if( block>=0 && (endgame || !tr_bitfieldHas( blocksAlreadyRequested, block ) ) ) + if( block>=0 && (endgame || !tr_bitfieldHas( requestedBlocks, block ) ) ) { - tr_bitfieldAdd( blocksAlreadyRequested, block ); + tr_bitfieldAdd( requestedBlocks, block ); sendRequest( tor, peer, block ); } else ++i; } - tr_bitfieldFree( blocksAlreadyRequested ); + tr_bitfieldFree( requestedBlocks ); free( pool ); } @@ -659,21 +659,11 @@ int tr_peerIsInterested( const tr_peer_t * peer ) return peer->peerInterested; } -/*********************************************************************** - * tr_peerProgress - *********************************************************************** - * - **********************************************************************/ float tr_peerProgress( const tr_peer_t * peer ) { return peer->progress; } -/*********************************************************************** - * tr_peerPort - *********************************************************************** - * Returns peer's listening port in host byte order - **********************************************************************/ int tr_peerPort( const tr_peer_t * peer ) { return ntohs( peer->port ); @@ -880,13 +870,13 @@ void tr_swiftPulse( tr_handle_t * h ) { static time_t lastPulseTime = 0; - const time_t now = time (NULL); - tr_torrent_t * tor; - if( lastPulseTime + SWIFT_REFRESH_INTERVAL_SEC > now ) - return; - lastPulseTime = now; + if( lastPulseTime + SWIFT_REFRESH_INTERVAL_SEC <= time( NULL ) ) + { + tr_torrent_t * tor; + for( tor=h->torrentList; tor; tor=tor->next ) + tr_torrentSwiftPulse( tor ); - for( tor=h->torrentList; tor; tor=tor->next ) - tr_torrentSwiftPulse( tor ); + lastPulseTime = time( NULL ); + } } diff --git a/libtransmission/platform.c b/libtransmission/platform.c index 77ac74109..2b42dbd6b 100644 --- a/libtransmission/platform.c +++ b/libtransmission/platform.c @@ -264,6 +264,24 @@ void tr_lockClose( tr_lock_t * l ) #endif } +void tr_lockLock( tr_lock_t * l ) +{ +#ifdef SYS_BEOS + acquire_sem( *l ); +#else + pthread_mutex_lock( l ); +#endif +} + +void tr_lockUnlock( tr_lock_t * l ) +{ +#ifdef SYS_BEOS + release_sem( *l ); +#else + pthread_mutex_unlock( l ); +#endif +} + void tr_condInit( tr_cond_t * c ) { diff --git a/libtransmission/platform.h b/libtransmission/platform.h index 5b7920c7e..daf99ef05 100644 --- a/libtransmission/platform.h +++ b/libtransmission/platform.h @@ -44,9 +44,7 @@ typedef struct tr_thread_s } tr_thread_t; -/* only for debugging purposes */ const char * tr_getHomeDirectory( void ); - const char * tr_getCacheDirectory( void ); const char * tr_getTorrentsDirectory( void ); @@ -61,29 +59,13 @@ void tr_threadCreate ( tr_thread_t *, void (*func)(void *), void tr_threadJoin ( tr_thread_t * ); void tr_lockInit ( tr_lock_t * ); void tr_lockClose ( tr_lock_t * ); +void tr_lockLock ( tr_lock_t * ); +void tr_lockUnlock ( tr_lock_t * ); -static inline void tr_lockLock( tr_lock_t * l ) -{ -#ifdef SYS_BEOS - acquire_sem( *l ); -#else - pthread_mutex_lock( l ); -#endif -} - -static inline void tr_lockUnlock( tr_lock_t * l ) -{ -#ifdef SYS_BEOS - release_sem( *l ); -#else - pthread_mutex_unlock( l ); -#endif -} - -void tr_condInit( tr_cond_t * ); -void tr_condWait( tr_cond_t *, tr_lock_t * ); -void tr_condSignal( tr_cond_t * ); -void tr_condClose( tr_cond_t * ); +void tr_condInit ( tr_cond_t * ); +void tr_condWait ( tr_cond_t *, tr_lock_t * ); +void tr_condSignal ( tr_cond_t * ); +void tr_condClose ( tr_cond_t * ); struct in_addr; /* forward declaration to calm gcc down */ int