diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 3c130469..79aee0ee 100755 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -211,6 +211,7 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason) wsi->u.http.fd = LWS_INVALID_FILE; wsi->vhost->protocols->callback(wsi, LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0); + wsi->told_user_closed = 1; } if (wsi->socket_is_permanently_unusable || reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY || @@ -255,10 +256,13 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason) wsi->user_space, NULL, 0); wsi->vhost->protocols->callback(wsi, LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0); + wsi->told_user_closed = 1; } - if (wsi->mode & LWSCM_FLAG_IMPLIES_CALLBACK_CLOSED_CLIENT_HTTP ) + if (wsi->mode & LWSCM_FLAG_IMPLIES_CALLBACK_CLOSED_CLIENT_HTTP) { wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_CLOSED_CLIENT_HTTP, wsi->user_space, NULL, 0); + wsi->told_user_closed = 1; + } /* * are his extensions okay with him closing? Eg he might be a mux diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 38e5e8cb..5e7f0f6a 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -1383,6 +1383,7 @@ struct lws { unsigned int favoured_pollin:1; unsigned int sending_chunked:1; unsigned int already_did_cce:1; + unsigned int told_user_closed:1; #if defined(LWS_WITH_ESP8266) unsigned int pending_send_completion:3; unsigned int close_is_pending_send_completion:1; diff --git a/lib/service.c b/lib/service.c index 5f2aedd7..d9929325 100644 --- a/lib/service.c +++ b/lib/service.c @@ -968,7 +968,8 @@ read: drain: #ifndef LWS_NO_CLIENT - if (wsi->mode == LWSCM_HTTP_CLIENT_ACCEPTED) { + if (wsi->mode == LWSCM_HTTP_CLIENT_ACCEPTED && + !wsi->told_user_closed) { /* * simply mark ourselves as having readable data