104{
105 if (!context)
106 {
107 MERROR(
"ZMQ RPC Server already shutdown");
108 return false;
109 }
110
111 rep_socket.reset(zmq_socket(context.get(), ZMQ_REP));
112 if (!rep_socket)
113 {
115 return false;
116 }
117
118 if (zmq_setsockopt(rep_socket.get(), ZMQ_MAXMSGSIZE, std::addressof(max_message_size), sizeof(max_message_size)) != 0)
119 {
121 return false;
122 }
123
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)
126 {
128 return false;
129 }
130
133 if (port.empty())
134 port = "*";
135
136 std::string bind_address = "tcp://";
138 bind_address += ":";
139 bind_address.append(port.data(), port.size());
140
141 if (zmq_bind(rep_socket.get(), bind_address.c_str()) < 0)
142 {
144 return false;
145 }
146 return true;
147}
#define ELECTRONEUM_LOG_ZMQ_ERROR(...)
Print a message followed by the current ZMQ error message.