aboutsummaryrefslogtreecommitdiff
path: root/src/httpserver.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-08-28 16:46:20 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-09-03 10:59:19 +0200
commitbe33f3f50b7358bbad9e16bf730fac2ab3c4886b (patch)
tree534b59ec81e5baf95c85980013304eb31b24d0c8 /src/httpserver.cpp
parent57d85d9bee20edb6c3070504f23b6a2be2802654 (diff)
Implement RPCTimerHandler for Qt RPC console
Implement RPCTimerHandler for Qt RPC console, so that `walletpassphrase` works with GUI and `-server=0`. Also simplify HTTPEvent-related code by using boost::function directly.
Diffstat (limited to 'src/httpserver.cpp')
-rw-r--r--src/httpserver.cpp33
1 files changed, 8 insertions, 25 deletions
diff --git a/src/httpserver.cpp b/src/httpserver.cpp
index 89366b2e4e..13f8705678 100644
--- a/src/httpserver.cpp
+++ b/src/httpserver.cpp
@@ -412,18 +412,15 @@ struct event_base* EventBase()
static void httpevent_callback_fn(evutil_socket_t, short, void* data)
{
- // Static handler simply passes through execution flow to _handle method
- ((HTTPEvent*)data)->_handle();
+ // Static handler: simply call inner handler
+ HTTPEvent *self = ((HTTPEvent*)data);
+ self->handler();
+ if (self->deleteWhenTriggered)
+ delete self;
}
-void HTTPEvent::_handle()
-{
- (*handler)();
- if (deleteWhenTriggered)
- delete this;
-}
-
-HTTPEvent::HTTPEvent(struct event_base* base, bool deleteWhenTriggered, HTTPClosure* handler) : deleteWhenTriggered(deleteWhenTriggered), handler(handler)
+HTTPEvent::HTTPEvent(struct event_base* base, bool deleteWhenTriggered, const boost::function<void(void)>& handler):
+ deleteWhenTriggered(deleteWhenTriggered), handler(handler)
{
ev = event_new(base, -1, 0, httpevent_callback_fn, this);
assert(ev);
@@ -496,20 +493,6 @@ void HTTPRequest::WriteHeader(const std::string& hdr, const std::string& value)
* Replies must be sent in the main loop in the main http thread,
* this cannot be done from worker threads.
*/
-struct HTTPSendReplyHandler : HTTPClosure {
-public:
- HTTPSendReplyHandler(struct evhttp_request* req, int nStatus) : req(req), nStatus(nStatus)
- {
- }
- void operator()()
- {
- evhttp_send_reply(req, nStatus, NULL, NULL);
- }
-private:
- struct evhttp_request* req;
- int nStatus;
-};
-
void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
{
assert(!replySent && req);
@@ -518,7 +501,7 @@ void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
assert(evb);
evbuffer_add(evb, strReply.data(), strReply.size());
HTTPEvent* ev = new HTTPEvent(eventBase, true,
- new HTTPSendReplyHandler(req, nStatus));
+ boost::bind(evhttp_send_reply, req, nStatus, (const char*)NULL, (struct evbuffer *)NULL));
ev->trigger(0);
replySent = true;
req = 0; // transferred back to main thread