Skip to content
Snippets Groups Projects
Commit b31f8b2a authored by Andy Green's avatar Andy Green
Browse files

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.
parent 43d0ab02
Branches
Tags
No related merge requests found
...@@ -258,6 +258,26 @@ lws_process_ws_upgrade(struct lws *wsi) ...@@ -258,6 +258,26 @@ lws_process_ws_upgrade(struct lws *wsi)
if (!wsi->protocol) if (!wsi->protocol)
lwsl_err("NULL protocol at lws_read\n"); 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 * It's either websocket or h2->websocket
* *
...@@ -305,7 +325,8 @@ lws_process_ws_upgrade(struct lws *wsi) ...@@ -305,7 +325,8 @@ lws_process_ws_upgrade(struct lws *wsi)
if (wsi->vhost->protocols[n].name && if (wsi->vhost->protocols[n].name &&
!strcmp(wsi->vhost->protocols[n].name, !strcmp(wsi->vhost->protocols[n].name,
protocol_name)) { protocol_name)) {
wsi->protocol = &wsi->vhost->protocols[n]; lws_bind_protocol(wsi,
&wsi->vhost->protocols[n]);
hit = 1; hit = 1;
break; break;
} }
...@@ -331,8 +352,8 @@ lws_process_ws_upgrade(struct lws *wsi) ...@@ -331,8 +352,8 @@ lws_process_ws_upgrade(struct lws *wsi)
lwsl_info("defaulting to prot handler %d\n", lwsl_info("defaulting to prot handler %d\n",
wsi->vhost->default_protocol_index); wsi->vhost->default_protocol_index);
n = wsi->vhost->default_protocol_index; n = wsi->vhost->default_protocol_index;
wsi->protocol = &wsi->vhost->protocols[ lws_bind_protocol(wsi, &wsi->vhost->protocols[
(int)wsi->vhost->default_protocol_index]; (int)wsi->vhost->default_protocol_index]);
} }
/* allocate the ws struct for the wsi */ /* allocate the ws struct for the wsi */
...@@ -395,28 +416,6 @@ lws_process_ws_upgrade(struct lws *wsi) ...@@ -395,28 +416,6 @@ lws_process_ws_upgrade(struct lws *wsi)
break; 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); lws_server_init_wsi_for_ws(wsi);
lwsl_parser("accepted v%02d connection\n", wsi->ws->ietf_spec_revision); lwsl_parser("accepted v%02d connection\n", wsi->ws->ietf_spec_revision);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment