mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
DROP_PROTOCOL: guarantee only one DROP per BIND
This commit is contained in:
parent
419a6af38d
commit
af88a889d0
2 changed files with 13 additions and 4 deletions
|
@ -473,9 +473,11 @@ lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p)
|
|||
// return 0;
|
||||
const struct lws_protocols *vp = wsi->vhost->protocols, *vpo;
|
||||
|
||||
if (wsi->protocol)
|
||||
if (wsi->protocol && wsi->protocol_bind_balance) {
|
||||
wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP_DROP_PROTOCOL,
|
||||
wsi->user_space, NULL, 0);
|
||||
wsi->protocol_bind_balance = 0;
|
||||
}
|
||||
if (!wsi->user_space_externally_allocated)
|
||||
lws_free_set_NULL(wsi->user_space);
|
||||
|
||||
|
@ -513,6 +515,8 @@ lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p)
|
|||
wsi->user_space, NULL, 0))
|
||||
return 1;
|
||||
|
||||
wsi->protocol_bind_balance = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -672,10 +676,12 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char *
|
|||
if (!wsi->told_user_closed &&
|
||||
(wsi->mode == LWSCM_HTTP_SERVING ||
|
||||
wsi->mode == LWSCM_HTTP2_SERVING)) {
|
||||
if (wsi->user_space)
|
||||
if (wsi->user_space && wsi->protocol_bind_balance) {
|
||||
wsi->vhost->protocols->callback(wsi,
|
||||
LWS_CALLBACK_HTTP_DROP_PROTOCOL,
|
||||
wsi->user_space, NULL, 0);
|
||||
wsi->protocol_bind_balance = 0;
|
||||
}
|
||||
wsi->vhost->protocols->callback(wsi, LWS_CALLBACK_CLOSED_HTTP,
|
||||
wsi->user_space, NULL, 0);
|
||||
wsi->told_user_closed = 1;
|
||||
|
@ -846,12 +852,14 @@ just_kill_connection:
|
|||
lws_remove_child_from_any_parent(wsi);
|
||||
n = 0;
|
||||
|
||||
if (!wsi->told_user_closed && wsi->user_space) {
|
||||
lwsl_debug("%s: %p: DROP_PROTOCOL %s\n", __func__, wsi,
|
||||
if (!wsi->told_user_closed && wsi->user_space &&
|
||||
wsi->protocol_bind_balance) {
|
||||
lwsl_debug("%s: %p: DROP_PROTOCOL %s\n", __func__, wsi,
|
||||
wsi->protocol->name);
|
||||
wsi->protocol->callback(wsi,
|
||||
LWS_CALLBACK_HTTP_DROP_PROTOCOL,
|
||||
wsi->user_space, NULL, 0);
|
||||
wsi->protocol_bind_balance = 0;
|
||||
}
|
||||
|
||||
if ((wsi->mode == LWSCM_WSCL_WAITING_SERVER_REPLY ||
|
||||
|
|
|
@ -2004,6 +2004,7 @@ struct lws {
|
|||
unsigned int event_pipe:1;
|
||||
unsigned int on_same_vh_list:1;
|
||||
unsigned int handling_404:1;
|
||||
unsigned int protocol_bind_balance:1;
|
||||
|
||||
unsigned int could_have_pending:1; /* detect back-to-back writes */
|
||||
unsigned int outer_will_close:1;
|
||||
|
|
Loading…
Add table
Reference in a new issue