raw: defer creation callback until after fds inserted
authorAndy Green <andy@warmcat.com>
Fri, 7 Apr 2017 03:25:55 +0000 (11:25 +0800)
committerAndy Green <andy@warmcat.com>
Fri, 7 Apr 2017 03:25:55 +0000 (11:25 +0800)
lib/server.c

index 472e0e0..91c37c1 100644 (file)
@@ -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");