mosquitto_pub: split main loop.
Main loop has two different logics inside: one for stdin input, second for all other cases. Exit loop condition is also different for both variants. This commit splits these two variants into two separate loops. Signed-off-by: Marek Wodzinski <majek@w7i.pl>
This commit is contained in:
parent
cfacd961c9
commit
ede9f2a51d
@ -223,7 +223,7 @@ int pub_shared_loop(struct mosquitto *mosq)
|
||||
{
|
||||
int read_len;
|
||||
int pos;
|
||||
int rc, rc2;
|
||||
int rc;
|
||||
char *buf2;
|
||||
int buf_len_actual;
|
||||
int mode;
|
||||
@ -239,10 +239,7 @@ int pub_shared_loop(struct mosquitto *mosq)
|
||||
if(mode == MSGMODE_STDIN_LINE){
|
||||
mosquitto_loop_start(mosq);
|
||||
stdin_finished = false;
|
||||
}
|
||||
|
||||
do{
|
||||
if(mode == MSGMODE_STDIN_LINE){
|
||||
if(status == STATUS_CONNACK_RECVD){
|
||||
pos = 0;
|
||||
read_len = line_buf_len;
|
||||
@ -250,9 +247,9 @@ int pub_shared_loop(struct mosquitto *mosq)
|
||||
buf_len_actual = strlen(line_buf);
|
||||
if(line_buf[buf_len_actual-1] == '\n'){
|
||||
line_buf[buf_len_actual-1] = '\0';
|
||||
rc2 = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual-1, line_buf, cfg.qos, cfg.retain);
|
||||
if(rc2){
|
||||
err_printf(&cfg, "Error: Publish returned %d, disconnecting.\n", rc2);
|
||||
rc = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual-1, line_buf, cfg.qos, cfg.retain);
|
||||
if(rc){
|
||||
err_printf(&cfg, "Error: Publish returned %d, disconnecting.\n", rc);
|
||||
mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props);
|
||||
}
|
||||
break;
|
||||
@ -297,11 +294,13 @@ int pub_shared_loop(struct mosquitto *mosq)
|
||||
nanosleep(&ts, NULL);
|
||||
#endif
|
||||
}
|
||||
rc = MOSQ_ERR_SUCCESS;
|
||||
}while(stdin_finished == false);
|
||||
mosquitto_loop_stop(mosq, false);
|
||||
}else{
|
||||
do{
|
||||
rc = mosquitto_loop(mosq, loop_delay, 1);
|
||||
if(ready_for_repeat && check_repeat_time()){
|
||||
rc = 0;
|
||||
rc = MOSQ_ERR_SUCCESS;
|
||||
switch(cfg.pub_mode){
|
||||
case MSGMODE_CMD:
|
||||
case MSGMODE_FILE:
|
||||
@ -311,19 +310,14 @@ int pub_shared_loop(struct mosquitto *mosq)
|
||||
case MSGMODE_NULL:
|
||||
rc = my_publish(mosq, &mid_sent, cfg.topic, 0, NULL, cfg.qos, cfg.retain);
|
||||
break;
|
||||
case MSGMODE_STDIN_LINE:
|
||||
break;
|
||||
}
|
||||
if(rc){
|
||||
err_printf(&cfg, "Error sending repeat publish: %s", mosquitto_strerror(rc));
|
||||
}
|
||||
}
|
||||
}while(rc == MOSQ_ERR_SUCCESS);
|
||||
}
|
||||
}while(rc == MOSQ_ERR_SUCCESS && stdin_finished == false);
|
||||
|
||||
if(mode == MSGMODE_STDIN_LINE){
|
||||
mosquitto_loop_stop(mosq, false);
|
||||
}
|
||||
if(status == STATUS_DISCONNECTED){
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}else{
|
||||
|
Loading…
Reference in New Issue
Block a user