diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2023-07-20 09:23:17 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2023-07-20 09:23:17 +0200 |
commit | 2de7bab3cf1c7757078a113b35e927ecbccc5e3d (patch) | |
tree | b13bf0497dab9bcf87dd6a58805511c4e1d3dc40 | |
parent | c8e4c6851b0975200b5a34b8003e7c08389e6b33 (diff) | |
download | dabmod-2de7bab3cf1c7757078a113b35e927ecbccc5e3d.tar.gz dabmod-2de7bab3cf1c7757078a113b35e927ecbccc5e3d.tar.bz2 dabmod-2de7bab3cf1c7757078a113b35e927ecbccc5e3d.zip |
Handle event socket bind failure
-rwxr-xr-x | doc/receive_events.py | 2 | ||||
-rw-r--r-- | src/Events.cpp | 12 | ||||
-rw-r--r-- | src/Events.h | 1 |
3 files changed, 13 insertions, 2 deletions
diff --git a/doc/receive_events.py b/doc/receive_events.py index dca27cd..bfd6f86 100755 --- a/doc/receive_events.py +++ b/doc/receive_events.py @@ -13,7 +13,7 @@ from pprint import pprint context = zmq.Context() sock = context.socket(zmq.SUB) -ep = "tcp://127.0.0.1:5557" +ep = "tcp://127.0.0.1:5556" print(f"Receive from {ep}") sock.connect(ep) 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()); diff --git a/src/Events.h b/src/Events.h index 215c5a8..9f838e5 100644 --- a/src/Events.h +++ b/src/Events.h @@ -61,6 +61,7 @@ class EventSender { private: zmq::context_t m_zmq_context; zmq::socket_t m_socket; + bool m_socket_valid = false; }; class LogToEventSender: public LogBackend { |