From f010687d81c2ada2ce0f401a20025145465e7b5c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 25 Jan 2010 05:19:54 +0000 Subject: [PATCH] (trunk libT) #2792 "Since 1.80 update downloads failing" -- a better fix than r10015... --- libtransmission/peer-mgr.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 9f85f0418..8def3d3c7 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -714,6 +714,14 @@ countBlockRequests( Torrent * t, tr_block_index_t block ) return n; } +static void +decrementPendingReqCount( const struct block_request * b ) +{ + if( b->peer != NULL ) + if( b->peer->pendingReqsToPeer > 0 ) + --b->peer->pendingReqsToPeer; +} + static void requestListRemove( Torrent * t, tr_block_index_t block, const tr_peer * peer ) { @@ -723,11 +731,7 @@ requestListRemove( Torrent * t, tr_block_index_t block, const tr_peer * peer ) const int pos = b - t->requests; assert( pos < t->requestCount ); - if( b->peer != NULL ) - { - --b->peer->pendingReqsToPeer; - assert( b->peer->pendingReqsToPeer >= 0 ); - } + decrementPendingReqCount( b ); memmove( t->requests + pos, t->requests + pos + 1, @@ -1143,8 +1147,7 @@ refillUpkeep( int foo UNUSED, short bar UNUSED, void * vmgr ) for( it=cancel, end=it+cancelCount; it!=end; ++it ) { if( ( it->peer != NULL ) && ( it->peer->msgs != NULL ) ) { tr_peerMsgsCancel( it->peer->msgs, it->block ); - if( t->requestCount > 0 ) - --t->requestCount; + decrementPendingReqCount( it ); } }