handle same vh protocol reinsert
[platform/upstream/libwebsockets.git] / lib / pollfd.c
index 7c3a0ef..25167dd 100644 (file)
@@ -236,6 +236,11 @@ remove_wsi_socket_from_fds(struct lws *wsi)
 #endif
        int m, ret = 0;
 
+       if (wsi->parent_carries_io) {
+               lws_same_vh_protocol_remove(wsi);
+               return 0;
+       }
+
 #if !defined(_WIN32) && !defined(LWS_WITH_ESP8266)
        if (wsi->desc.sockfd > context->max_fds) {
                lwsl_err("fd %d too high (%d)\n", wsi->desc.sockfd, context->max_fds);
@@ -348,6 +353,16 @@ lws_callback_on_writable(struct lws *wsi)
        if (wsi->socket_is_permanently_unusable)
                return 0;
 
+       if (wsi->parent_carries_io) {
+               int n = lws_callback_on_writable(wsi->parent);
+
+               if (n < 0)
+                       return n;
+
+               wsi->parent_pending_cb_on_writable = 1;
+               return 1;
+       }
+
        pt = &wsi->context->pt[(int)wsi->tsi];
        lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_WRITEABLE_CB_REQ, 1);
 #if defined(LWS_WITH_STATS)
@@ -434,8 +449,8 @@ lws_same_vh_protocol_insert(struct lws *wsi, int n)
        //              wsi->same_vh_protocol_prev);
 
        if (wsi->same_vh_protocol_prev || wsi->same_vh_protocol_next) {
-               lwsl_err("Attempted to attach wsi twice to same vh prot\n");
-               assert(0);
+               lws_same_vh_protocol_remove(wsi);
+               lwsl_notice("Attempted to attach wsi twice to same vh prot\n");
        }
 
        wsi->same_vh_protocol_prev = /* guy who points to us */