changeset 2289:7b16b54ce64d draft

Merge pull request #959 from rebroad/LoadBlockIndexKillable Added ability to respond to signals during Block Loading stage.
author Pieter Wuille <pieter.wuille@gmail.com>
date Thu, 19 Apr 2012 04:33:04 -0700
parents 19bee101826d (current diff) ccef6e0f4b0a (diff)
children 6ab3faa85555 048775a1d8b2
files
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -529,7 +529,7 @@
         // Unserialize
         string strType;
         ssKey >> strType;
-        if (strType == "blockindex")
+        if (strType == "blockindex" && !fRequestShutdown)
         {
             CDiskBlockIndex diskindex;
             ssValue >> diskindex;
@@ -556,11 +556,14 @@
         }
         else
         {
-            break;
+            break; // if shutdown requested or finished loading block index
         }
     }
     pcursor->close();
 
+    if (fRequestShutdown)
+        return true;
+
     // Calculate bnChainWork
     vector<pair<int, CBlockIndex*> > vSortedByHeight;
     vSortedByHeight.reserve(mapBlockIndex.size());
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -353,6 +353,15 @@
     nStart = GetTimeMillis();
     if (!LoadBlockIndex())
         strErrors << _("Error loading blkindex.dat") << "\n";
+
+    // as LoadBlockIndex can take several minutes, it's possible the user
+    // requested to kill bitcoin-qt during the last operation. If so, exit.
+    // As the program has not fully started yet, Shutdown() is possibly overkill.
+    if (fRequestShutdown)
+    {
+        printf("Shutdown requested. Exiting.\n");
+        return false;
+    }
     printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);
 
     InitMessage(_("Loading wallet..."));