33 #include <system_error> 40 constexpr
const int num_zmq_threads = 1;
41 constexpr
const std::int64_t max_message_size = 10 * 1024 * 1024;
42 constexpr
const std::chrono::seconds linger_timeout{2};
50 context(zmq_init(num_zmq_threads))
68 MERROR(
"ZMQ RPC server reply socket is null");
82 catch (
const std::system_error& e)
85 MERROR(
"ZMQ RPC Server Error: " << e.what());
87 catch (
const std::exception& e)
89 MERROR(
"ZMQ RPC Server Error: " << e.what());
93 MERROR(
"Unknown error in ZMQ RPC server");
99 MERROR(
"ZmqServer::addIPCSocket not yet implemented!");
107 MERROR(
"ZMQ RPC Server already shutdown");
111 rep_socket.reset(zmq_socket(context.get(), ZMQ_REP));
118 if (zmq_setsockopt(rep_socket.get(), ZMQ_MAXMSGSIZE, std::addressof(max_message_size),
sizeof(max_message_size)) != 0)
124 static constexpr
const int linger_value = std::chrono::milliseconds{linger_timeout}.count();
125 if (zmq_setsockopt(rep_socket.get(), ZMQ_LINGER, std::addressof(linger_value),
sizeof(linger_value)) != 0)
139 bind_address.append(
port.data(),
port.size());
141 if (zmq_bind(rep_socket.get(), bind_address.c_str()) < 0)
156 if (!run_thread.joinable())
std::error_code make_error_code(int code) noexcept
virtual std::string handle(const std::string &request)=0
expect< std::string > receive(void *const socket, const int flags)
epee::misc_utils::struct_init< response_t > response
std::unique_ptr< void, close > socket
Unique ZMQ socket handle, calls zmq_close on destruction.
#define ELECTRONEUM_ZMQ_THROW(msg)
Throw an exception with a custom msg, current ZMQ error code, filename, and line number.
Holds cryptonote related classes and helpers.
#define ELECTRONEUM_LOG_ZMQ_ERROR(...)
Print a message followed by the current ZMQ error message.
bool addIPCSocket(boost::string_ref address, boost::string_ref port)
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
bool addTCPSocket(boost::string_ref address, boost::string_ref port)
std::string message("Message requiring signing")
boost::endian::big_uint16_t port
#define ELECTRONEUM_UNWRAP(...)
const T & move(const T &t)
expect< void > send(const epee::span< const std::uint8_t > payload, void *const socket, const int flags) noexcept