mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge pull request #2625 from gavinandresen/walletlock_asio
Use boost::asio::deadline_timer for walletpassphrase timeout
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user