From 0714998ef54e8c1a46af7ec48698faa3abdf457a Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Tue, 29 Oct 2024 22:06:51 +0100 Subject: Mehrere Topics möglich und bessere Abbruchsteuerung MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 1b5bac7..8a25176 100644 --- a/src/main.c +++ b/src/main.c @@ -76,11 +76,13 @@ connect(const char *clientid, // NOLINT } static void -run(struct mosquitto *client, const char *topic) +run(struct mosquitto *client, const char *topics[], const volatile bool *quit) { - mosquitto_subscribe(client, NULL, topic, 0); + for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { + mosquitto_subscribe(client, NULL, topics[idx], 0); + } - while ( !terminate ) { + while ( !*quit ) { static const int defaultTimeout = -1; // 1000ms int err = mosquitto_loop(client, defaultTimeout, 1); @@ -127,7 +129,8 @@ main(void) return EXIT_FAILURE; } - run(client, TOPIC); + run(client, (const char *[]){ TOPIC, NULL }, &terminate); + shutdown(client); return EXIT_SUCCESS; -- cgit v1.3