From 47bbb044ada920405a6c992ed2bf45d8a4d79c32 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 7 Apr 2017 11:25:55 +0800 Subject: [PATCH] raw: defer creation callback until after fds inserted --- lib/server.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/server.c b/lib/server.c index 472e0e01..91c37c18 100644 --- a/lib/server.c +++ b/lib/server.c @@ -1824,15 +1824,6 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, else n = LWS_CALLBACK_RAW_ADOPT; } - if ((new_wsi->protocol->callback)( - new_wsi, n, new_wsi->user_space, NULL, 0)) { - if (type & LWS_ADOPT_SOCKET) { - /* force us off the timeout list by hand */ - lws_set_timeout(new_wsi, NO_PENDING_TIMEOUT, 0); - compatible_close(new_wsi->desc.sockfd); - } - goto bail; - } if (!LWS_SSL_ENABLED(new_wsi->vhost) || !(type & LWS_ADOPT_ALLOW_SSL) || !(type & LWS_ADOPT_SOCKET)) { @@ -1868,6 +1859,14 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, goto fail; } + /* + * by deferring callback to this point, after insertion to fds, + * lws_callback_on_writable() can work from the callback + */ + if ((new_wsi->protocol->callback)( + new_wsi, n, new_wsi->user_space, NULL, 0)) + goto fail; + if (type & LWS_ADOPT_HTTP) if (!lws_header_table_attach(new_wsi, 0)) lwsl_debug("Attached ah immediately\n");