Electroneum
jsonrpc_server_impl_base.h
Go to the documentation of this file.
1 #ifndef JSONRPC_SERVER_IMPL_BASE_H
2 #define JSONRPC_SERVER_IMPL_BASE_H
3 
4 #include <boost/thread.hpp>
5 #include <boost/bind.hpp>
6 
10 
11 namespace epee
12 {
13 
14 template<class t_child_class, class t_connection_context = epee::net_utils::connection_context_base>
16  {
17 
18  public:
20  : m_net_server()
21  {}
22 
23  explicit jsonrpc_server_impl_base(boost::asio::io_service& external_io_service)
24  : m_net_server(external_io_service)
25  {}
26 
27  bool init(const std::string& bind_port = "0", const std::string& bind_ip = "0.0.0.0")
28  {
29  //set self as callback handler
30  m_net_server.get_config_object().m_phandler = static_cast<t_child_class*>(this);
31 
32  LOG_PRINT_L0("Binding on " << bind_ip << ":" << bind_port);
33  bool res = m_net_server.init_server(bind_port, bind_ip);
34  if (!res)
35  {
36  LOG_ERROR("Failed to bind server");
37  return false;
38  }
39  return true;
40  }
41 
42  bool run(size_t threads_count, bool wait = true)
43  {
44  //go to loop
45  LOG_PRINT("Run net_service loop( " << threads_count << " threads)...", LOG_LEVEL_0);
46  if(!m_net_server.run_server(threads_count, wait))
47  {
48  LOG_ERROR("Failed to run net tcp server!");
49  }
50 
51  if(wait)
52  LOG_PRINT("net_service loop stopped.", LOG_LEVEL_0);
53  return true;
54  }
55 
56  bool deinit()
57  {
58  return m_net_server.deinit_server();
59  }
60 
62  {
63  return m_net_server.timed_wait_server_stop(ms);
64  }
65 
67  {
68  m_net_server.send_stop_signal();
69  return true;
70  }
71 
73  {
74  return m_net_server.get_binded_port();
75  }
76 
77  protected:
79  };
80 
81 }
82 
83 #endif /* JSONRPC_SERVER_IMPL_BASE_H */
84 
const char * res
Definition: hmac_keccak.cpp:41
bool init(const std::string &bind_port="0", const std::string &bind_ip="0.0.0.0")
::std::string string
Definition: gtest-port.h:1097
#define LOG_PRINT_L0(x)
Definition: misc_log_ex.h:99
net_utils::boosted_tcp_server< net_utils::jsonrpc2::jsonrpc2_connection_handler< t_connection_context > > m_net_server
the connection templated-class for one peer connection
unsigned __int64 uint64_t
Definition: stdint.h:136
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
jsonrpc_server_impl_base(boost::asio::io_service &external_io_service)
bool run(size_t threads_count, bool wait=true)