]> granicus.if.org Git - transmission/commitdiff
(trunk libT) another possible fix for #1894: Crash when download finishes and seed...
authorCharles Kerr <charles@transmissionbt.com>
Thu, 9 Apr 2009 14:10:31 +0000 (14:10 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 9 Apr 2009 14:10:31 +0000 (14:10 +0000)
libtransmission/peer-mgr.c
libtransmission/session.c
libtransmission/torrent.c
libtransmission/torrent.h
libtransmission/transmission.h

index 250719ac43ccab78d0ff6a68ca924354f2aacc56..c869b07c805dba257f99e0f7703cb506ef125394 100644 (file)
@@ -995,13 +995,6 @@ peerSuggestedPiece( Torrent            * t UNUSED,
 #endif
 }
 
-static int
-checkRatioIdle( void * tor )
-{
-    tr_torrentCheckSeedRatio( tor );
-    return 0; /* one-shot timer */
-}
-
 static void
 peerCallbackFunc( void * vpeer, void * vevent, void * vt )
 {
@@ -1050,11 +1043,7 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
                     a->piece_data_time = now;
             }
 
-            /* we can't check the stop ratio here because the code calling
-             * this function requires that the torrent not be stopped.
-             * so instead, add an idle timer to check the ratio as soon
-             * as the calling code is done.  (ticket #1894) */
-            tr_timerNew( tor->session, checkRatioIdle, tor, 1 );
+            tor->needsSeedRatioCheck = TRUE;
 
             break;
         }
@@ -2431,6 +2420,7 @@ pumpAllPeers( tr_peerMgr * mgr )
 static int
 bandwidthPulse( void * vmgr )
 {
+    tr_torrent * tor = NULL;
     tr_peerMgr * mgr = vmgr;
     managerLock( mgr );
 
@@ -2441,6 +2431,14 @@ bandwidthPulse( void * vmgr )
     tr_bandwidthAllocate( mgr->session->bandwidth, TR_UP, BANDWIDTH_PERIOD_MSEC );
     tr_bandwidthAllocate( mgr->session->bandwidth, TR_DOWN, BANDWIDTH_PERIOD_MSEC );
 
+    /* possibly stop torrents that have seeded enough */
+    while(( tor = tr_torrentNext( mgr->session, tor ))) {
+        if( tor->needsSeedRatioCheck ) {
+            tor->needsSeedRatioCheck = FALSE;
+            tr_torrentCheckSeedRatio( tor );
+        }
+    }
+
     managerUnlock( mgr );
     return TRUE;
 }
index a7c324ff8ed3813adb18e44181215418c738b84c..a58b910e922191e1fd4d7a82dcb6ac5f13fd1230 100644 (file)
@@ -865,7 +865,7 @@ updateSeedRatio( tr_session * session )
     tr_torrent * tor = NULL;
 
     while(( tor = tr_torrentNext( session, tor )))
-        tr_torrentCheckSeedRatio( tor );
+        tor->needsSeedRatioCheck = TRUE;
 }
 
 void
index 485d2f0cea3eb5585ba1e1aa3fb485b75afec400..41a11feebcc919f050c0ae96744e910071ee174c 100644 (file)
@@ -172,8 +172,7 @@ tr_torrentSetRatioMode( tr_torrent *  tor, tr_ratiolimit mode )
     assert( mode==TR_RATIOLIMIT_GLOBAL || mode==TR_RATIOLIMIT_SINGLE || mode==TR_RATIOLIMIT_UNLIMITED  );
 
     tor->ratioLimitMode = mode;
-
-    tr_torrentCheckSeedRatio( tor );
+    tor->needsSeedRatioCheck = TRUE;
 }
 
 tr_ratiolimit
@@ -185,14 +184,13 @@ tr_torrentGetRatioMode( const tr_torrent * tor )
 }
 
 void
-tr_torrentSetRatioLimit( tr_torrent * tor,
-                         double       desiredRatio )
+tr_torrentSetRatioLimit( tr_torrent * tor, double desiredRatio )
 {
     assert( tr_isTorrent( tor ) );
 
     tor->desiredRatio = desiredRatio;
 
-    tr_torrentCheckSeedRatio( tor );
+    tor->needsSeedRatioCheck = TRUE;
 }
 
 double
@@ -1192,7 +1190,8 @@ checkAndStartImpl( void * vtor )
 
     tr_globalLock( tor->session );
 
-    tor->isRunning = 1;
+    tor->isRunning = TRUE;
+    tor->needsSeedRatioCheck = TRUE;
     *tor->errorString = '\0';
     tr_torrentResetTransferStats( tor );
     tor->completeness = tr_cpGetStatus( &tor->completion );
@@ -1200,7 +1199,6 @@ checkAndStartImpl( void * vtor )
     tor->startDate = tor->anyDate = time( NULL );
     tr_trackerStart( tor->tracker );
     tr_peerMgrStartTorrent( tor );
-    tr_torrentCheckSeedRatio( tor );
 
     tr_globalUnlock( tor->session );
 }
@@ -1470,6 +1468,7 @@ tr_torrentRecheckCompleteness( tr_torrent * tor )
         }
 
         tor->completeness = completeness;
+        tor->needsSeedRatioCheck = TRUE;
         tr_torrentCloseLocalFiles( tor );
         fireCompletenessChange( tor, completeness );
 
@@ -1481,7 +1480,6 @@ tr_torrentRecheckCompleteness( tr_torrent * tor )
         }
 
         tr_torrentSaveResume( tor );
-        tr_torrentCheckSeedRatio( tor );
     }
 
     tr_torrentUnlock( tor );
@@ -1654,7 +1652,7 @@ tr_torrentInitFileDLs( tr_torrent      * tor,
     for( i=0; i<fileCount; ++i )
         setFileDND( tor, files[i], doDownload );
     tr_cpInvalidateDND( &tor->completion );
-    tr_torrentCheckSeedRatio( tor );
+    tor->needsSeedRatioCheck = TRUE;
 
     tr_torrentUnlock( tor );
 }
index 1690b60140c311b3d33e6272a91b3dd495609fa3..c2e92d9777aacff7c049a2f51da28712fab83e04 100644 (file)
@@ -199,6 +199,7 @@ struct tr_torrent
 
     tr_bool                    isRunning;
     tr_bool                    isDeleting;
+    tr_bool                    needsSeedRatioCheck;
 
     uint16_t                   maxConnectedPeers;
 
index 8c637ce9d6da6a64fbf5dc5a56209fe94e0995db..aa54d1baced1042a534506a6e1dbc3613a6c4762 100644 (file)
@@ -169,8 +169,6 @@ static TR_INLINE tr_bool tr_isEncryptionMode( tr_encryption_mode m )
 #define TR_PREFS_KEY_ALT_SPEED_TIME_DAY         "alt-speed-time-day"
 #define TR_PREFS_KEY_BLOCKLIST_ENABLED          "blocklist-enabled"
 #define TR_PREFS_KEY_DOWNLOAD_DIR               "download-dir"
-#define TR_PREFS_KEY_DSPEED                     "download-limit"
-#define TR_PREFS_KEY_DSPEED_ENABLED             "download-limit-enabled"
 #define TR_PREFS_KEY_ENCRYPTION                 "encryption"
 #define TR_PREFS_KEY_LAZY_BITFIELD              "lazy-bitfield-enabled"
 #define TR_PREFS_KEY_MSGLEVEL                   "message-level"
@@ -201,8 +199,10 @@ static TR_INLINE tr_bool tr_isEncryptionMode( tr_encryption_mode m )
 #define TR_PREFS_KEY_RPC_USERNAME               "rpc-username"
 #define TR_PREFS_KEY_RPC_WHITELIST_ENABLED      "rpc-whitelist-enabled"
 #define TR_PREFS_KEY_RPC_WHITELIST              "rpc-whitelist"
-#define TR_PREFS_KEY_USPEED_ENABLED             "upload-limit-enabled"
-#define TR_PREFS_KEY_USPEED                     "upload-limit"
+#define TR_PREFS_KEY_DSPEED                     "speed-limit-down"
+#define TR_PREFS_KEY_DSPEED_ENABLED             "speed-limit-down-enabled"
+#define TR_PREFS_KEY_USPEED_ENABLED             "speed-limit-up-enabled"
+#define TR_PREFS_KEY_USPEED                     "speed-limit-up"
 #define TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT   "upload-slots-per-torrent"
 
 struct tr_benc;