From bdc9eda20a8fc5ebcca1213e9b84d294404d3e1c Mon Sep 17 00:00:00 2001 From: Andy Green Date: Tue, 24 Oct 2017 06:46:02 +0800 Subject: [PATCH] protocol init: allow use of client apis during per-vhost protocol init --- lib/context.c | 13 ++++++++++++- lib/private-libwebsockets.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/context.c b/lib/context.c index d1344595c..f67476b1e 100644 --- a/lib/context.c +++ b/lib/context.c @@ -197,6 +197,11 @@ lws_protocol_init(struct lws_context *context) struct lws wsi; int n; + if (context->doing_protocol_init) + return 0; + + context->doing_protocol_init = 1; + memset(&wsi, 0, sizeof(wsi)); wsi.context = context; @@ -261,8 +266,12 @@ lws_protocol_init(struct lws_context *context) */ if (vh->protocols[n].callback(&wsi, LWS_CALLBACK_PROTOCOL_INIT, NULL, - (void *)pvo, 0)) + (void *)pvo, 0)) { + lwsl_err("%s: vhost %s failed init\n", __func__, + vh->protocols[n].name); + context->doing_protocol_init = 0; return 1; + } } vh->created_vhost_protocols = 1; @@ -270,6 +279,8 @@ next: vh = vh->vhost_next; } + context->doing_protocol_init = 0; + if (!context->protocol_init_done) lws_finalize_startup(context); diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 80e96a5ba..8239baaba 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -1116,6 +1116,7 @@ struct lws_context { unsigned int requested_kill:1; unsigned int protocol_init_done:1; unsigned int ssl_gate_accepts:1; + unsigned int doing_protocol_init; /* * set to the Thread ID that's doing the service loop just before entry * to poll indicates service thread likely idling in poll()