mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
misc cleanup.. ansification; fix my own typos, etc...
This commit is contained in:
parent
ab4a1cd2f7
commit
5401979ffa
5 changed files with 43 additions and 51 deletions
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
**/
|
||||
|
||||
|
|
|
@ -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; i<peer->inRequestCount; ++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; i<poolSize && peer->inRequestCount<OUR_REQUEST_COUNT; )
|
||||
|
@ -617,15 +617,15 @@ writeEnd:
|
|||
? tr_cpMostMissingBlockInPiece( tor->completion, 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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue