Skip to content

Commit

Permalink
Move json::to_string to http thread pool
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Mar 7, 2019
1 parent 12ab91c commit 97b385c
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions plugins/chain_api_plugin/chain_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ chain_api_plugin::~chain_api_plugin(){}
void chain_api_plugin::set_program_options(options_description&, options_description&) {}
void chain_api_plugin::plugin_initialize(const variables_map&) {}

struct async_result_visitor : public fc::visitor<std::string> {
struct async_result_visitor : public fc::visitor<fc::variant> {
template<typename T>
std::string operator()(const T& v) const {
return fc::json::to_string(v);
fc::variant operator()(const T& v) const {
return fc::variant(v);
}
};

Expand All @@ -41,8 +41,8 @@ struct async_result_visitor : public fc::visitor<std::string> {
api_handle.validate(); \
try { \
if (body.empty()) body = "{}"; \
auto result = api_handle.call_name(fc::json::from_string(body).as<api_namespace::call_name ## _params>()); \
cb(http_response_code, fc::json::to_string(result)); \
fc::variant result( api_handle.call_name(fc::json::from_string(body).as<api_namespace::call_name ## _params>()) ); \
cb(http_response_code, std::move(result)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
Expand Down
2 changes: 1 addition & 1 deletion plugins/db_size_api_plugin/db_size_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace eosio;
try { \
if (body.empty()) body = "{}"; \
INVOKE \
cb(http_response_code, fc::json::to_string(result)); \
cb(http_response_code, fc::variant(result)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
Expand Down
2 changes: 1 addition & 1 deletion plugins/faucet_testnet_plugin/faucet_testnet_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ using results_pair = std::pair<uint32_t,fc::variant>;
try { \
if (body.empty()) body = "{}"; \
const auto result = api_handle->invoke_cb(body); \
response_cb(result.first, fc::json::to_string(result.second)); \
response_cb(result.first, fc::variant(result.second)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, response_cb); \
} \
Expand Down
4 changes: 2 additions & 2 deletions plugins/history_api_plugin/history_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void history_api_plugin::plugin_initialize(const variables_map&) {}
[api_handle](string, string body, url_response_callback cb) mutable { \
try { \
if (body.empty()) body = "{}"; \
auto result = api_handle.call_name(fc::json::from_string(body).as<api_namespace::call_name ## _params>()); \
cb(200, fc::json::to_string(result)); \
fc::variant result( api_handle.call_name(fc::json::from_string(body).as<api_namespace::call_name ## _params>()) ); \
cb(200, std::move(result)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
Expand Down
4 changes: 2 additions & 2 deletions plugins/login_plugin/login_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void login_plugin::plugin_initialize(const variables_map& options) {
try { \
if (body.empty()) \
body = "{}"; \
auto result = call_name(fc::json::from_string(body).as<login_plugin::call_name##_params>()); \
cb(http_response_code, fc::json::to_string(result)); \
fc::variant result( call_name(fc::json::from_string(body).as<login_plugin::call_name##_params>()) ); \
cb(http_response_code, std::move(result)); \
} catch (...) { \
http_plugin::handle_exception("login", #call_name, body, cb); \
} \
Expand Down
2 changes: 1 addition & 1 deletion plugins/net_api_plugin/net_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace eosio;
try { \
if (body.empty()) body = "{}"; \
INVOKE \
cb(http_response_code, fc::json::to_string(result)); \
cb(http_response_code, fc::variant(result)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
Expand Down
2 changes: 1 addition & 1 deletion plugins/producer_api_plugin/producer_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace eosio;
try { \
if (body.empty()) body = "{}"; \
INVOKE \
cb(http_response_code, fc::json::to_string(result)); \
cb(http_response_code, fc::variant(result)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
Expand Down
4 changes: 2 additions & 2 deletions plugins/test_control_api_plugin/test_control_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct async_result_visitor : public fc::visitor<std::string> {
[api_handle](string, string body, url_response_callback cb) mutable { \
try { \
if (body.empty()) body = "{}"; \
auto result = api_handle.call_name(fc::json::from_string(body).as<api_namespace::call_name ## _params>()); \
cb(http_response_code, fc::json::to_string(result)); \
fc::variant result( api_handle.call_name(fc::json::from_string(body).as<api_namespace::call_name ## _params>()) ); \
cb(http_response_code, std::move(result)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
Expand Down
4 changes: 2 additions & 2 deletions plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using io_work_t = boost::asio::executor_work_guard<boost::asio::io_context::exec
try { \
if (body.empty()) body = "{}"; \
INVOKE \
cb(http_response_code, fc::json::to_string(result)); \
cb(http_response_code, fc::variant(result)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
Expand Down Expand Up @@ -77,7 +77,7 @@ using io_work_t = boost::asio::executor_work_guard<boost::asio::io_context::exec
http_plugin::handle_exception(#api_name, #call_name, body, cb);\
}\
} else {\
cb(http_response_code, fc::json::to_string(eosio::detail::txn_test_gen_empty())); \
cb(http_response_code, fc::variant(eosio::detail::txn_test_gen_empty())); \
}\
};\
INVOKE \
Expand Down
2 changes: 1 addition & 1 deletion plugins/wallet_api_plugin/wallet_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace eosio;
try { \
if (body.empty()) body = "{}"; \
INVOKE \
cb(http_response_code, fc::json::to_string(result)); \
cb(http_response_code, fc::variant(result)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
Expand Down
2 changes: 1 addition & 1 deletion programs/keosd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char** argv)
if(!app().initialize<wallet_plugin, wallet_api_plugin, http_plugin>(argc, argv))
return -1;
auto& http = app().get_plugin<http_plugin>();
http.add_handler("/v1/keosd/stop", [](string, string, url_response_callback cb) { cb(200, "{}"); std::raise(SIGTERM); } );
http.add_handler("/v1/keosd/stop", [](string, string, url_response_callback cb) { cb(200, fc::variant(fc::variant_object())); std::raise(SIGTERM); } );
app().startup();
app().exec();
} catch (const fc::exception& e) {
Expand Down

0 comments on commit 97b385c

Please sign in to comment.