Skip to content

Commit

Permalink
Fix websockets clients sometimes not being disconnected promptly.
Browse files Browse the repository at this point in the history
Closes #1718. Thanks to Luca Casonato.
  • Loading branch information
ralight committed Jul 15, 2020
1 parent d371b3c commit 8234d24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -11,6 +11,8 @@ Broker:
set to true. Closes #1729.
- Fix `autosave_interval` not being triggered by messages being delivered.
Closes #1726.
- Fix websockets clients sometimes not being disconnected promptly.
Closes #1718.

Client library:
- Improved documentation around connect callback return codes. Close #1730.
Expand Down
15 changes: 12 additions & 3 deletions src/websockets.c
Expand Up @@ -302,7 +302,10 @@ static int callback_mqtt(struct libwebsocket_context *context,
}
count = libwebsocket_write(wsi, &packet->payload[packet->pos], txlen, LWS_WRITE_BINARY);
if(count < 0){
if (mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting){
if (mosq->state == mosq_cs_disconnect_ws
|| mosq->state == mosq_cs_disconnecting
|| mosq->state == mosq_cs_disused){

return -1;
}
return 0;
Expand All @@ -313,7 +316,10 @@ static int callback_mqtt(struct libwebsocket_context *context,
packet->to_process -= count;
packet->pos += count;
if(packet->to_process > 0){
if (mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting){
if (mosq->state == mosq_cs_disconnect_ws
|| mosq->state == mosq_cs_disconnecting
|| mosq->state == mosq_cs_disused){

return -1;
}
break;
Expand All @@ -340,7 +346,10 @@ static int callback_mqtt(struct libwebsocket_context *context,

mosq->next_msg_out = mosquitto_time() + mosq->keepalive;
}
if (mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting){
if (mosq->state == mosq_cs_disconnect_ws
|| mosq->state == mosq_cs_disconnecting
|| mosq->state == mosq_cs_disused){

return -1;
}
if(mosq->current_out_packet){
Expand Down

0 comments on commit 8234d24

Please sign in to comment.