From c1e488cb88939c00886ba7b6e9a48870f2ad5d4d Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 4 Sep 2019 14:29:26 +0100 Subject: [PATCH] Add timeout return code (27) for sub/rr using -W. Closes #275. --- ChangeLog.txt | 3 +++ client/rr_client.c | 7 ++++++- client/sub_client.c | 7 ++++++- lib/mosquitto.h | 1 + man/mosquitto_rr.1.xml | 18 ++++++++++++++++++ man/mosquitto_sub.1.xml | 18 ++++++++++++++++++ 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index a254ea4e..f580c42d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,9 @@ Broker: then try "nobody" instead. This reduces the burden on users installing Mosquitto themselves. +Clients: +- Add timeout return code (27) for `mosquitto_sub -W ` and + `mosquitto_rr -W `. Closes #275. 1.6.4 - 20190801 ================ diff --git a/client/rr_client.c b/client/rr_client.c index 44f105b0..e1a8596a 100644 --- a/client/rr_client.c +++ b/client/rr_client.c @@ -51,6 +51,7 @@ struct mosq_config cfg; bool process_messages = true; int msg_count = 0; struct mosquitto *mosq = NULL; +static bool timed_out = false; #ifndef WIN32 void my_signal_handler(int signum) @@ -58,6 +59,7 @@ void my_signal_handler(int signum) if(signum == SIGALRM){ process_messages = false; mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props); + timed_out = true; } } #endif @@ -359,7 +361,10 @@ int main(int argc, char *argv[]) rc = 0; } client_config_cleanup(&cfg); - if(rc){ + if(timed_out){ + err_printf(&cfg, "Timed out\n"); + return MOSQ_ERR_TIMEOUT; + }else if(rc){ err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc)); } return rc; diff --git a/client/sub_client.c b/client/sub_client.c index 68b0e790..f5f3ce6d 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -40,6 +40,7 @@ bool process_messages = true; int msg_count = 0; struct mosquitto *mosq = NULL; int last_mid = 0; +static bool timed_out = false; #ifndef WIN32 void my_signal_handler(int signum) @@ -47,6 +48,7 @@ void my_signal_handler(int signum) if(signum == SIGALRM){ process_messages = false; mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props); + timed_out = true; } } #endif @@ -356,7 +358,10 @@ int main(int argc, char *argv[]) rc = 0; } client_config_cleanup(&cfg); - if(rc){ + if(timed_out){ + err_printf(&cfg, "Timed out\n"); + return MOSQ_ERR_TIMEOUT; + }else if(rc){ err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc)); } return rc; diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 6957b619..274d54ec 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -98,6 +98,7 @@ enum mosq_err_t { MOSQ_ERR_QOS_NOT_SUPPORTED = 24, MOSQ_ERR_OVERSIZE_PACKET = 25, MOSQ_ERR_OCSP = 26, + MOSQ_ERR_TIMEOUT = 27, }; /* Option values */ diff --git a/man/mosquitto_rr.1.xml b/man/mosquitto_rr.1.xml index 5af06af0..ae06c126 100644 --- a/man/mosquitto_rr.1.xml +++ b/man/mosquitto_rr.1.xml @@ -783,6 +783,24 @@ + + Exit Values + + + + Success + + + + Timed out waiting for message + + + + Unspecified failure + + + + Files diff --git a/man/mosquitto_sub.1.xml b/man/mosquitto_sub.1.xml index 83a500ac..c7b293dc 100644 --- a/man/mosquitto_sub.1.xml +++ b/man/mosquitto_sub.1.xml @@ -924,6 +924,24 @@ mosquitto_sub -t 'bbc/#' -T bbc/bbc1 --remove-retained + + Exit Values + + + + Success + + + + Timed out waiting for message + + + + Unspecified failure + + + + Files