mirror of
https://github.com/monero-project/monero.git
synced 2025-01-28 18:56:31 +02:00
Fixed problem in Json_rpc_http_server due to C-like nature of net_skeleton
This commit is contained in:
parent
edfaa2e484
commit
ac662269cf
@ -4,12 +4,16 @@
|
|||||||
|
|
||||||
namespace RPC
|
namespace RPC
|
||||||
{
|
{
|
||||||
Json_rpc_http_server::Json_rpc_http_server(const std::string &ip, const std::string &port)
|
Json_rpc_http_server::Json_rpc_http_server(const std::string &ip, const std::string &port,
|
||||||
|
void (*ev_handler)(struct ns_connection *nc, int ev, void *ev_data),
|
||||||
|
const char **method_names, ns_rpc_handler_t *handlers) :
|
||||||
|
m_method_names(method_names), m_handlers(handlers)
|
||||||
{
|
{
|
||||||
m_ip = ip;
|
m_ip = ip;
|
||||||
m_port = port;
|
m_port = port;
|
||||||
m_is_running = false;
|
m_is_running = false;
|
||||||
m_method_count = 0;
|
m_method_count = 0;
|
||||||
|
m_ev_handler = ev_handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json_rpc_http_server::~Json_rpc_http_server()
|
Json_rpc_http_server::~Json_rpc_http_server()
|
||||||
@ -17,17 +21,21 @@ namespace RPC
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Json_rpc_http_server::start()
|
bool Json_rpc_http_server::start()
|
||||||
{
|
{
|
||||||
m_is_running = true;
|
m_is_running = true;
|
||||||
|
ns_mgr_init(&mgr, NULL);
|
||||||
|
nc = ns_bind(&mgr, (m_ip + ":" + m_port).c_str(), m_ev_handler);
|
||||||
|
if (!nc)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ns_set_protocol_http_websocket(nc);
|
||||||
server_thread = new boost::thread(&Json_rpc_http_server::poll, this);
|
server_thread = new boost::thread(&Json_rpc_http_server::poll, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Json_rpc_http_server::poll()
|
void Json_rpc_http_server::poll()
|
||||||
{
|
{
|
||||||
ns_mgr_init(&mgr, NULL);
|
|
||||||
nc = ns_bind(&mgr, (m_ip + ":" + m_port).c_str(), std::bind(&Json_rpc_http_server::ev_handler, this));
|
|
||||||
ns_set_protocol_http_websocket(nc);
|
|
||||||
while (m_is_running) {
|
while (m_is_running) {
|
||||||
ns_mgr_poll(&mgr, 1000);
|
ns_mgr_poll(&mgr, 1000);
|
||||||
}
|
}
|
||||||
@ -58,18 +66,4 @@ namespace RPC
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Json_rpc_http_server::add_handler(const std::string &method_name,
|
|
||||||
int (*hander)(char *buf, int len, struct ns_rpc_request *req))
|
|
||||||
{
|
|
||||||
if (m_method_count == MAX_METHODS)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_method_names[m_method_count] = new char[method_name.length() + 1];
|
|
||||||
strcpy(m_method_names[m_method_count], method_name.c_str());
|
|
||||||
m_handlers[m_method_count] = hander;
|
|
||||||
m_method_count++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define MAX_METHODS 100
|
#define JSON_RPC_MAX_METHODS 100
|
||||||
|
|
||||||
namespace RPC
|
namespace RPC
|
||||||
{
|
{
|
||||||
@ -16,13 +16,16 @@ namespace RPC
|
|||||||
std::string m_ip;
|
std::string m_ip;
|
||||||
std::string m_port;
|
std::string m_port;
|
||||||
bool m_is_running;
|
bool m_is_running;
|
||||||
char *m_method_names[MAX_METHODS];
|
const char **m_method_names;
|
||||||
ns_rpc_handler_t m_handlers[MAX_METHODS];
|
ns_rpc_handler_t *m_handlers;
|
||||||
int m_method_count;
|
int m_method_count;
|
||||||
|
void (*m_ev_handler)(struct ns_connection *nc, int ev, void *ev_data);
|
||||||
public:
|
public:
|
||||||
Json_rpc_http_server(const std::string &ip, const std::string &port);
|
Json_rpc_http_server(const std::string &ip, const std::string &port,
|
||||||
|
void (*ev_handler)(struct ns_connection *nc, int ev, void *ev_data),
|
||||||
|
const char **method_names, ns_rpc_handler_t *handlers);
|
||||||
~Json_rpc_http_server();
|
~Json_rpc_http_server();
|
||||||
void start();
|
bool start();
|
||||||
void stop();
|
void stop();
|
||||||
bool add_handler(const std::string &method_name,
|
bool add_handler(const std::string &method_name,
|
||||||
int (*hander)(char *buf, int len, struct ns_rpc_request *req));
|
int (*hander)(char *buf, int len, struct ns_rpc_request *req));
|
||||||
|
Loading…
Reference in New Issue
Block a user