| 231 | } |
| 232 | |
| 233 | void Groot2Publisher::serverLoop() |
| 234 | { |
| 235 | auto const serialized_uuid = CreateRandomUUID(); |
| 236 | |
| 237 | auto& socket = _p->server; |
| 238 | |
| 239 | auto sendErrorReply = [&socket](const std::string& msg) { |
| 240 | zmq::multipart_t error_msg; |
| 241 | error_msg.addstr("error"); |
| 242 | error_msg.addstr(msg); |
| 243 | error_msg.send(socket); |
| 244 | }; |
| 245 | |
| 246 | // initialize _p->last_heartbeat |
| 247 | { |
| 248 | const std::unique_lock lk(_p->last_heartbeat_mutex); |
| 249 | _p->last_heartbeat = std::chrono::steady_clock::now(); |
| 250 | } |
| 251 | |
| 252 | while(_p->active_server) |
| 253 | { |
| 254 | zmq::multipart_t requestMsg; |
| 255 | try |
| 256 | { |
| 257 | if(!requestMsg.recv(socket) || requestMsg.size() == 0) |
| 258 | { |
| 259 | continue; |
| 260 | } |
| 261 | } |
| 262 | catch(const zmq::error_t&) |
| 263 | { |
| 264 | // Context was terminated or socket error - exit the loop |
| 265 | break; |
| 266 | } |
| 267 | |
| 268 | // this heartbeat will help establishing if Groot is connected or not |
| 269 | { |
| 270 | const std::unique_lock lk(_p->last_heartbeat_mutex); |
| 271 | _p->last_heartbeat = std::chrono::steady_clock::now(); |
| 272 | } |
| 273 | |
| 274 | std::string const request_str = requestMsg[0].to_string(); |
| 275 | if(request_str.size() != Monitor::RequestHeader::size()) |
| 276 | { |
| 277 | sendErrorReply("wrong request header"); |
| 278 | continue; |
| 279 | } |
| 280 | |
| 281 | auto request_header = Monitor::DeserializeRequestHeader(request_str); |
| 282 | |
| 283 | Monitor::ReplyHeader reply_header; |
| 284 | reply_header.request = request_header; |
| 285 | reply_header.request.protocol = Monitor::kProtocolID; |
| 286 | reply_header.tree_id = serialized_uuid; |
| 287 | |
| 288 | zmq::multipart_t reply_msg; |
| 289 | reply_msg.addstr(Monitor::SerializeHeader(reply_header)); |
| 290 |
nothing calls this directly
no test coverage detected