1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +01:00

ws role: use protocol bind and unbind and transition earlier

Now individual role callbacks are added in an earlier patch for protocol
bind and unbind, change the ws upgrade action to use the generic protocol
bind and unbind apis so the corresponding callbacks are issued for ws.
This commit is contained in:
Andy Green 2018-08-28 19:51:19 +08:00
parent 43d0ab02e2
commit b31f8b2aa6

View file

@ -258,6 +258,26 @@ lws_process_ws_upgrade(struct lws *wsi)
if (!wsi->protocol)
lwsl_err("NULL protocol at lws_read\n");
/*
* We are upgrading to ws, so http/1.1 + h2 and keepalive + pipelined
* header considerations about keeping the ah around no longer apply.
*
* However it's common for the first ws protocol data to have been
* coalesced with the browser upgrade request and to already be in the
* ah rx buffer.
*/
lws_pt_lock(pt, __func__);
if (wsi->h2_stream_carries_ws)
lws_role_transition(wsi, LWSIFR_SERVER | LWSIFR_P_ENCAP_H2,
LRS_ESTABLISHED, &role_ops_ws);
else
lws_role_transition(wsi, LWSIFR_SERVER, LRS_ESTABLISHED,
&role_ops_ws);
lws_pt_unlock(pt);
/*
* It's either websocket or h2->websocket
*
@ -305,7 +325,8 @@ lws_process_ws_upgrade(struct lws *wsi)
if (wsi->vhost->protocols[n].name &&
!strcmp(wsi->vhost->protocols[n].name,
protocol_name)) {
wsi->protocol = &wsi->vhost->protocols[n];
lws_bind_protocol(wsi,
&wsi->vhost->protocols[n]);
hit = 1;
break;
}
@ -331,8 +352,8 @@ lws_process_ws_upgrade(struct lws *wsi)
lwsl_info("defaulting to prot handler %d\n",
wsi->vhost->default_protocol_index);
n = wsi->vhost->default_protocol_index;
wsi->protocol = &wsi->vhost->protocols[
(int)wsi->vhost->default_protocol_index];
lws_bind_protocol(wsi, &wsi->vhost->protocols[
(int)wsi->vhost->default_protocol_index]);
}
/* allocate the ws struct for the wsi */
@ -395,28 +416,6 @@ lws_process_ws_upgrade(struct lws *wsi)
break;
}
lws_same_vh_protocol_insert(wsi, n);
/*
* We are upgrading to ws, so http/1.1 + h2 and keepalive + pipelined
* header considerations about keeping the ah around no longer apply.
*
* However it's common for the first ws protocol data to have been
* coalesced with the browser upgrade request and to already be in the
* ah rx buffer.
*/
lws_pt_lock(pt, __func__);
if (wsi->h2_stream_carries_ws)
lws_role_transition(wsi, LWSIFR_SERVER | LWSIFR_P_ENCAP_H2,
LRS_ESTABLISHED, &role_ops_ws);
else
lws_role_transition(wsi, LWSIFR_SERVER, LRS_ESTABLISHED,
&role_ops_ws);
lws_pt_unlock(pt);
lws_server_init_wsi_for_ws(wsi);
lwsl_parser("accepted v%02d connection\n", wsi->ws->ietf_spec_revision);