]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #2643 "Total UL/DL ratio reset when quitting abnormally" -- fixed.
authorCharles Kerr <charles@transmissionbt.com>
Tue, 8 Dec 2009 20:51:45 +0000 (20:51 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Tue, 8 Dec 2009 20:51:45 +0000 (20:51 +0000)
libtransmission/session.c
libtransmission/stats.c
libtransmission/stats.h

index 79e249a1597c2b5c8a2d8566f2f775ce4693843e..f180a1924fedc5f272352121ecedcde8b9526379 100644 (file)
@@ -482,6 +482,8 @@ onSaveTimer( int foo UNUSED, short bar UNUSED, void * vsession )
     while(( tor = tr_torrentNext( session, tor )))
         tr_torrentSave( tor );
 
+    tr_statsSaveDirty( session );
+
     tr_timerAdd( session->saveTimer, SAVE_INTERVAL_SECS, 0 );
 }
 
index 0c6b188e9021db0536776e7f73e00e3e1d5756ac..cd9600a1ee3ec65f8cfd470257d6688706fc2fee 100644 (file)
@@ -28,6 +28,7 @@ struct tr_stats_handle
     tr_session_stats    single;
     tr_session_stats    old;
     time_t              startTime;
+    tr_bool             isDirty;
 };
 
 static char*
@@ -117,24 +118,34 @@ tr_statsInit( tr_session * session )
     session->sessionStats = stats;
 }
 
+static struct tr_stats_handle *
+getStats( const tr_session * session )
+{
+    return session ? session->sessionStats : NULL;
+}
+
 void
-tr_statsClose( tr_session * session )
+tr_statsSaveDirty( tr_session * session )
 {
-    tr_session_stats cumulative = STATS_INIT;
+    struct tr_stats_handle * h = getStats( session );
+    if( ( h != NULL ) && h->isDirty )
+    {
+        tr_session_stats cumulative = STATS_INIT;
+        tr_sessionGetCumulativeStats( session, &cumulative );
+        saveCumulativeStats( session, &cumulative );
+        h->isDirty = FALSE;
+    }
+}
 
-    tr_sessionGetCumulativeStats( session, &cumulative );
-    saveCumulativeStats( session, &cumulative );
+void
+tr_statsClose( tr_session * session )
+{
+    tr_statsSaveDirty( session );
 
     tr_free( session->sessionStats );
     session->sessionStats = NULL;
 }
 
-static struct tr_stats_handle *
-getStats( const tr_session * session )
-{
-    return session ? session->sessionStats : NULL;
-}
-
 /***
 ****
 ***/
@@ -213,7 +224,10 @@ tr_statsAddUploaded( tr_session * session,
     struct tr_stats_handle * s;
 
     if( ( s = getStats( session ) ) )
+    {
         s->single.uploadedBytes += bytes;
+        s->isDirty = TRUE;
+    }
 }
 
 void
@@ -223,7 +237,10 @@ tr_statsAddDownloaded( tr_session * session,
     struct tr_stats_handle * s;
 
     if( ( s = getStats( session ) ) )
+    {
         s->single.downloadedBytes += bytes;
+        s->isDirty = TRUE;
+    }
 }
 
 void
index 5400bf1fe13c69de9b3a9b8f9307301996f9a666..720c6eea84a00209dc43148c0b1708f3ec50b4c6 100644 (file)
@@ -21,6 +21,8 @@ void tr_statsInit           ( tr_session  * session );
 
 void tr_statsClose          ( tr_session  * session );
 
+void tr_statsSaveDirty      ( tr_session  * session );
+
 void tr_statsAddUploaded    ( tr_session  * session,
                               uint32_t      bytes );