diff --git a/ChangeLog.txt b/ChangeLog.txt index 5bf8ac7c..c0666b30 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -23,6 +23,9 @@ Client library: - Fix mosquitto_topic_matches_sub() not correctly matching foo/bar against foo/+/#. Closes #670. +Clients: +- Correctly handle empty files with "mosquitto_pub -l". Closes #676. + Build: - Don't run TLS-PSK tests if TLS-PSK disabled at compile time. Closes #636. diff --git a/client/pub_client.c b/client/pub_client.c index c8ca981a..2f99b4af 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -34,6 +34,7 @@ Contributors: #define STATUS_CONNECTING 0 #define STATUS_CONNACK_RECVD 1 #define STATUS_WAITING 2 +#define STATUS_DISCONNECTING 3 /* Global variables for use in callbacks. See sub_client.c for an example of * using a struct to hold variables for use in callbacks. */ @@ -410,8 +411,15 @@ int main(int argc, char *argv[]) } } if(feof(stdin)){ - last_mid = mid_sent; - status = STATUS_WAITING; + if(last_mid == -1){ + /* Empty file */ + mosquitto_disconnect(mosq); + disconnect_sent = true; + status = STATUS_DISCONNECTING; + }else{ + last_mid = mid_sent; + status = STATUS_WAITING; + } } }else if(status == STATUS_WAITING){ if(last_mid_sent == last_mid && disconnect_sent == false){