aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.cpp
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@bitpay.com>2013-05-30 08:01:22 -0700
committerJeff Garzik <jgarzik@bitpay.com>2013-05-30 08:01:22 -0700
commit9c95a2e836f7f92b6e446e4dfd3362aa7274bec9 (patch)
tree3628dc2161b3fd447d23753b0b51892a5900be4f /src/bitcoinrpc.cpp
parente2f42142a03fa817a7fe6529fc1d55ef2d016352 (diff)
parent92f2c1fe0fe2905540b0435188988851145f92be (diff)
Merge pull request #2625 from gavinandresen/walletlock_asio
Use boost::asio::deadline_timer for walletpassphrase timeout
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r--src/bitcoinrpc.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 2c4744a579..5d64fb767f 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -11,17 +11,17 @@
#include "bitcoinrpc.h"
#include "db.h"
+#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ip/v6_only.hpp>
+#include <boost/asio/ssl.hpp>
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
+#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream.hpp>
-#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
-#include <boost/asio/ssl.hpp>
-#include <boost/filesystem/fstream.hpp>
#include <boost/shared_ptr.hpp>
#include <list>
@@ -38,6 +38,7 @@ static std::string strRPCUserColonPass;
// These are created by StartRPCThreads, destroyed in StopRPCThreads
static asio::io_service* rpc_io_service = NULL;
+static map<string, boost::shared_ptr<deadline_timer> > deadlineTimers;
static ssl::context* rpc_ssl_context = NULL;
static boost::thread_group* rpc_worker_group = NULL;
@@ -852,6 +853,7 @@ void StopRPCThreads()
if (rpc_io_service == NULL) return;
+ deadlineTimers.clear();
rpc_io_service->stop();
rpc_worker_group->join_all();
delete rpc_worker_group; rpc_worker_group = NULL;
@@ -859,6 +861,26 @@ void StopRPCThreads()
delete rpc_io_service; rpc_io_service = NULL;
}
+void RPCRunHandler(const boost::system::error_code& err, boost::function<void(void)> func)
+{
+ if (!err)
+ func();
+}
+
+void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64 nSeconds)
+{
+ assert(rpc_io_service != NULL);
+
+ if (deadlineTimers.count(name) == 0)
+ {
+ deadlineTimers.insert(make_pair(name,
+ boost::shared_ptr<deadline_timer>(new deadline_timer(*rpc_io_service))));
+ }
+ deadlineTimers[name]->expires_from_now(posix_time::seconds(nSeconds));
+ deadlineTimers[name]->async_wait(boost::bind(RPCRunHandler, _1, func));
+}
+
+
class JSONRequest
{
public: