Don't overwrite disused client state.
This commit is contained in:
parent
9411d94842
commit
110f4aada6
@ -206,7 +206,7 @@ int net__socket_close(struct mosquitto *mosq)
|
||||
if(mosq->wsi)
|
||||
{
|
||||
if(mosq->state != mosq_cs_disconnecting){
|
||||
mosq->state = mosq_cs_disconnect_ws;
|
||||
context__set_state(mosq, mosq_cs_disconnect_ws);
|
||||
}
|
||||
libwebsocket_callback_on_writable(mosq->ws_context, mosq->wsi);
|
||||
}else
|
||||
|
@ -123,7 +123,7 @@ int bridge__connect_step1(struct mosquitto_db *db, struct mosquitto *context)
|
||||
|
||||
if(!context || !context->bridge) return MOSQ_ERR_INVAL;
|
||||
|
||||
context->state = mosq_cs_new;
|
||||
context__set_state(context, mosq_cs_new);
|
||||
context->sock = INVALID_SOCKET;
|
||||
context->last_msg_in = mosquitto_time();
|
||||
context->next_msg_out = mosquitto_time() + context->bridge->keepalive;
|
||||
@ -243,7 +243,7 @@ int bridge__connect_step2(struct mosquitto_db *db, struct mosquitto *context)
|
||||
HASH_ADD(hh_sock, db->contexts_by_sock, sock, sizeof(context->sock), context);
|
||||
|
||||
if(rc == MOSQ_ERR_CONN_PENDING){
|
||||
context->state = mosq_cs_connect_pending;
|
||||
context__set_state(context, mosq_cs_connect_pending);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@ -302,7 +302,7 @@ int bridge__connect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
|
||||
if(!context || !context->bridge) return MOSQ_ERR_INVAL;
|
||||
|
||||
context->state = mosq_cs_new;
|
||||
context__set_state(context, mosq_cs_new);
|
||||
context->sock = INVALID_SOCKET;
|
||||
context->last_msg_in = mosquitto_time();
|
||||
context->next_msg_out = mosquitto_time() + context->bridge->keepalive;
|
||||
@ -399,7 +399,7 @@ int bridge__connect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
|
||||
return rc;
|
||||
}else if(rc == MOSQ_ERR_CONN_PENDING){
|
||||
context->state = mosq_cs_connect_pending;
|
||||
context__set_state(context, mosq_cs_connect_pending);
|
||||
}
|
||||
|
||||
HASH_ADD(hh_sock, db->contexts_by_sock, sock, sizeof(context->sock), context);
|
||||
|
@ -37,7 +37,7 @@ struct mosquitto *context__init(struct mosquitto_db *db, mosq_sock_t sock)
|
||||
if(!context) return NULL;
|
||||
|
||||
context->pollfd_index = -1;
|
||||
context->state = mosq_cs_new;
|
||||
context__set_state(context, mosq_cs_new);
|
||||
context->sock = sock;
|
||||
context->last_msg_in = mosquitto_time();
|
||||
context->next_msg_out = mosquitto_time() + 60;
|
||||
@ -275,14 +275,14 @@ void context__disconnect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
}else{
|
||||
session_expiry__add(context);
|
||||
}
|
||||
context->state = mosq_cs_disconnected;
|
||||
context__set_state(context, mosq_cs_disconnected);
|
||||
}
|
||||
|
||||
void context__add_to_disused(struct mosquitto_db *db, struct mosquitto *context)
|
||||
{
|
||||
if(context->state == mosq_cs_disused) return;
|
||||
|
||||
context->state = mosq_cs_disused;
|
||||
context__set_state(context, mosq_cs_disused);
|
||||
|
||||
if(db->ll_for_free){
|
||||
context->for_free_next = db->ll_for_free;
|
||||
@ -314,3 +314,11 @@ void context__remove_from_by_id(struct mosquitto_db *db, struct mosquitto *conte
|
||||
context->removed_from_by_id = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void context__set_state(struct mosquitto *context, enum mosquitto_client_state state)
|
||||
{
|
||||
if(context->state != mosq_cs_disused){
|
||||
context->state = state;
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ int handle__connack(struct mosquitto_db *db, struct mosquitto *context)
|
||||
}
|
||||
}
|
||||
}
|
||||
context->state = mosq_cs_connected;
|
||||
context__set_state(context, mosq_cs_connected);
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
case CONNACK_REFUSED_PROTOCOL_VERSION:
|
||||
if(context->bridge){
|
||||
|
@ -682,7 +682,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
|
||||
found_context->clean_start = true;
|
||||
found_context->session_expiry_interval = 0;
|
||||
found_context->state = mosq_cs_duplicate;
|
||||
context__set_state(found_context, mosq_cs_duplicate);
|
||||
do_disconnect(db, found_context);
|
||||
}
|
||||
|
||||
@ -740,7 +740,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
db->persistence_changes++;
|
||||
}
|
||||
#endif
|
||||
context->state = mosq_cs_connected;
|
||||
context__set_state(context, mosq_cs_connected);
|
||||
rc = send__connack(db, context, connect_ack, CONNACK_ACCEPTED, connack_props);
|
||||
mosquitto_property_free_all(&connack_props);
|
||||
return rc;
|
||||
@ -805,9 +805,9 @@ int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
}
|
||||
}
|
||||
if(reason_code == MQTT_RC_DISCONNECT_WITH_WILL_MSG){
|
||||
context->state = mosq_cs_disconnect_with_will;
|
||||
context__set_state(context, mosq_cs_disconnect_with_will);
|
||||
}else{
|
||||
context->state = mosq_cs_disconnecting;
|
||||
context__set_state(context, mosq_cs_disconnecting);
|
||||
}
|
||||
do_disconnect(db, context);
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
|
@ -487,7 +487,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
|
||||
log__printf(NULL, MOSQ_LOG_NOTICE, "Expiring persistent client %s due to timeout.", id);
|
||||
G_CLIENTS_EXPIRED_INC();
|
||||
context->session_expiry_interval = 0;
|
||||
context->state = mosq_cs_expiring;
|
||||
context__set_state(context, mosq_cs_expiring);
|
||||
do_disconnect(db, context);
|
||||
}
|
||||
}
|
||||
@ -632,7 +632,7 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
|
||||
#ifdef WITH_WEBSOCKETS
|
||||
if(context->wsi){
|
||||
if(context->state != mosq_cs_disconnecting){
|
||||
context->state = mosq_cs_disconnect_ws;
|
||||
context__set_state(context, mosq_cs_disconnect_ws);
|
||||
}
|
||||
if(context->wsi){
|
||||
libwebsocket_callback_on_writable(context->ws_context, context->wsi);
|
||||
@ -745,7 +745,7 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol
|
||||
len = sizeof(int);
|
||||
if(!getsockopt(context->sock, SOL_SOCKET, SO_ERROR, (char *)&err, &len)){
|
||||
if(err == 0){
|
||||
context->state = mosq_cs_new;
|
||||
context__set_state(context, mosq_cs_new);
|
||||
#ifdef WITH_ADNS
|
||||
if(context->bridge){
|
||||
bridge__connect_step3(db, context);
|
||||
|
@ -615,6 +615,7 @@ void context__add_to_disused(struct mosquitto_db *db, struct mosquitto *context)
|
||||
void context__free_disused(struct mosquitto_db *db);
|
||||
void context__send_will(struct mosquitto_db *db, struct mosquitto *context);
|
||||
void context__remove_from_by_id(struct mosquitto_db *db, struct mosquitto *context);
|
||||
void context__set_state(struct mosquitto *context, enum mosquitto_client_state state);
|
||||
|
||||
/* ============================================================
|
||||
* Logging functions
|
||||
|
@ -972,13 +972,13 @@ int mosquitto_security_apply_default(struct mosquitto_db *db)
|
||||
}
|
||||
|
||||
if(!allow_anonymous && !context->username){
|
||||
context->state = mosq_cs_disconnecting;
|
||||
context__set_state(context, mosq_cs_disconnecting);
|
||||
do_disconnect(db, context);
|
||||
continue;
|
||||
}
|
||||
/* Check for connected clients that are no longer authorised */
|
||||
if(mosquitto_unpwd_check(db, context, context->username, context->password) != MOSQ_ERR_SUCCESS){
|
||||
context->state = mosq_cs_disconnecting;
|
||||
context__set_state(context, mosq_cs_disconnecting);
|
||||
do_disconnect(db, context);
|
||||
continue;
|
||||
}
|
||||
@ -988,7 +988,7 @@ int mosquitto_security_apply_default(struct mosquitto_db *db)
|
||||
security_opts = &context->listener->security_options;
|
||||
}else{
|
||||
if(context->state != mosq_cs_connected){
|
||||
context->state = mosq_cs_disconnecting;
|
||||
context__set_state(context, mosq_cs_disconnecting);
|
||||
do_disconnect(db, context);
|
||||
continue;
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ static int callback_mqtt(struct libwebsocket_context *context,
|
||||
|
||||
if(rc && (mosq->out_packet || mosq->current_out_packet)) {
|
||||
if(mosq->state != mosq_cs_disconnecting){
|
||||
mosq->state = mosq_cs_disconnect_ws;
|
||||
context__set_state(mosq, mosq_cs_disconnect_ws);
|
||||
}
|
||||
libwebsocket_callback_on_writable(mosq->ws_context, mosq->wsi);
|
||||
} else if (rc) {
|
||||
|
Loading…
Reference in New Issue
Block a user