From 2de7bab3cf1c7757078a113b35e927ecbccc5e3d Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 20 Jul 2023 09:23:17 +0200 Subject: Handle event socket bind failure --- src/Events.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/Events.cpp') diff --git a/src/Events.cpp b/src/Events.cpp index d65b73a..3171cda 100644 --- a/src/Events.cpp +++ b/src/Events.cpp @@ -47,11 +47,21 @@ EventSender::~EventSender() void EventSender::bind(const std::string& bind_endpoint) { - m_socket.bind(bind_endpoint); + try { + m_socket.bind(bind_endpoint); + m_socket_valid = true; + } + catch (const zmq::error_t& err) { + fprintf(stderr, "Cannot bind event socket: %s", err.what()); + } } void EventSender::send(const std::string& event_name, const json::map_t& detail) { + if (not m_socket_valid) { + return; + } + zmq::message_t zmsg1(event_name.data(), event_name.size()); const auto detail_json = json::map_to_json(detail); zmq::message_t zmsg2(detail_json.data(), detail_json.size()); -- cgit v1.2.3