Clients: Give warning if keepalive too low.

This commit is contained in:
Roger A. Light 2020-11-03 09:51:28 +00:00
parent 1191a42c2e
commit 8e7e4a9d9a
2 changed files with 3 additions and 3 deletions

View File

@ -689,8 +689,8 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
return 1; return 1;
}else{ }else{
cfg->keepalive = atoi(argv[i+1]); cfg->keepalive = atoi(argv[i+1]);
if(cfg->keepalive>65535){ if(cfg->keepalive<5 || cfg->keepalive>UINT16_MAX){
fprintf(stderr, "Error: Invalid keepalive given: %d\n", cfg->keepalive); fprintf(stderr, "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.\n\n");
return 1; return 1;
} }
} }

View File

@ -43,7 +43,7 @@ static int mosquitto__connect_init(struct mosquitto *mosq, const char *host, int
if(!mosq) return MOSQ_ERR_INVAL; if(!mosq) return MOSQ_ERR_INVAL;
if(!host || port < 0 || port > UINT16_MAX) return MOSQ_ERR_INVAL; if(!host || port < 0 || port > UINT16_MAX) return MOSQ_ERR_INVAL;
if(keepalive < 5 || keepalive > UINT16_MAX) return MOSQ_ERR_INVAL; if(keepalive != 0 && (keepalive < 5 || keepalive > UINT16_MAX)) return MOSQ_ERR_INVAL;
/* Only MQTT v3.1 requires a client id to be sent */ /* Only MQTT v3.1 requires a client id to be sent */
if(mosq->id == NULL && (mosq->protocol == mosq_p_mqtt31)){ if(mosq->id == NULL && (mosq->protocol == mosq_p_mqtt31)){