Lines Matching refs:wsi
93 * The wsi at this level is normally the network wsi... we can get called on
98 rops_handle_POLLIN_h2(struct lws_context_per_thread *pt, struct lws *wsi,
108 if (wsi->http.cgi && (pollfd->revents & LWS_POLLOUT)) {
109 if (lws_handle_POLLOUT_event(wsi, pollfd))
117 wsi->lc.gutag, (unsigned int)wsi->wsistate,
122 if (wsi->wsistate == 0x10000013) {
123 wsi->bugcatcher++;
124 if (wsi->bugcatcher == 250) {
129 wsi->bugcatcher = 0;
135 if (lwsi_state(wsi) == LRS_PRE_WS_SERVING_ACCEPT) {
136 wsi->socket_is_permanently_unusable = 1;
140 if (lwsi_state(wsi) == LRS_WAITING_CONNECT) {
143 lws_handle_POLLOUT_event(wsi, pollfd)) {
148 n = lws_http_client_socket_service(wsi, pollfd);
158 lwsi_state_can_handle_POLLOUT(wsi) &&
159 lws_handle_POLLOUT_event(wsi, pollfd)) {
160 if (lwsi_state(wsi) == LRS_RETURNED_CLOSE)
161 lwsi_set_state(wsi, LRS_FLUSHING_BEFORE_CLOSE);
163 wsi->socket_is_permanently_unusable = 1;
168 if (lwsi_state(wsi) == LRS_RETURNED_CLOSE ||
169 lwsi_state(wsi) == LRS_WAITING_TO_SEND_CLOSE ||
170 lwsi_state(wsi) == LRS_AWAITING_CLOSE_ACK) {
176 lws_rx_flow_control(wsi, 1);
178 if (wsi->ws)
179 wsi->ws->tx_draining_ext = 0;
183 if (wsi->mux_substream || wsi->upgraded_to_http2) {
184 wsi1 = lws_get_network_wsi(wsi);
199 /* 3: network wsi buflist needs to be drained */
201 // lws_buflist_describe(&wsi->buflist, wsi, __func__);
203 ebuf.len = (int)lws_buflist_next_segment_len(&wsi->buflist,
211 if (wsi->mux_substream) {
212 lwsl_warn("%s: uh... %s mux child with nothing to drain\n", __func__, lws_wsi_tag(wsi));
214 lws_dll2_remove(&wsi->dll_buflist);
219 if (!lws_ssl_pending(wsi) &&
225 if (!(lwsi_role_client(wsi) &&
226 (lwsi_state(wsi) != LRS_ESTABLISHED &&
227 // lwsi_state(wsi) != LRS_H1C_ISSUE_HANDSHAKE2 &&
228 lwsi_state(wsi) != LRS_H2_WAITING_TO_SEND_HEADERS))) {
231 ebuf.len = lws_ssl_capable_read(wsi,
233 wsi->a.context->pt_serv_buf_size);
257 if (lwsi_role_http(wsi) && lwsi_role_client(wsi) &&
258 wsi->hdr_parsing_completed && !wsi->told_user_closed) {
271 wsi->client_rx_avail = 1;
272 if (lws_change_pollfd(wsi, LWS_POLLIN, 0))
279 wsi->a.protocol->callback,
280 wsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP,
281 wsi->user_space, NULL, 0)) {
294 if (lwsi_role_h2(wsi) && lwsi_state(wsi) != LRS_BODY &&
295 lwsi_state(wsi) != LRS_DISCARD_BODY)
296 n = lws_read_h2(wsi, ebuf.token, (unsigned int)ebuf.len);
298 n = lws_read_h1(wsi, ebuf.token, (unsigned int)ebuf.len);
301 /* we closed wsi */
307 m = (int)lws_buflist_use_segment(&wsi->buflist, (size_t)n);
312 __func__, lws_wsi_tag(wsi));
313 lws_dll2_remove(&wsi->dll_buflist);
318 m = lws_buflist_append_segment(&wsi->buflist,
325 __func__, lws_wsi_tag(wsi));
326 if (lws_dll2_is_detached(&wsi->dll_buflist))
327 lws_dll2_add_head(&wsi->dll_buflist,
333 // lws_buflist_describe(&wsi->buflist, wsi, __func__);
343 if (wsi->http.ah
345 && !wsi->client_h2_alpn
350 lws_header_table_detach(wsi, 0);
354 pending = (unsigned int)lws_ssl_pending(wsi);
363 int rops_handle_POLLOUT_h2(struct lws *wsi)
367 if (lwsi_state(wsi) == LRS_ISSUE_HTTP_BODY)
373 if ((wsi->upgraded_to_http2
375 || wsi->client_h2_alpn
377 ) && wsi->h2.h2n->pps) {
383 if (lws_h2_do_pps_send(wsi)) {
384 wsi->socket_is_permanently_unusable = 1;
387 if (wsi->h2.h2n->pps)
391 lws_rx_flow_control(wsi, LWS_RXFLOW_REASON_APPLIES_ENABLE |
400 if (lwsi_state(wsi) == LRS_RETURNED_CLOSE)
407 rops_write_role_protocol_h2(struct lws *wsi, unsigned char *buf, size_t len,
419 if (!lwsi_role_ws(wsi) && !wsi->mux_stream_immortal &&
423 base != LWS_WRITE_HTTP_HEADERS && lwsi_state(wsi) != LRS_BODY &&
424 ((lwsi_state(wsi) != LRS_RETURNED_CLOSE &&
425 lwsi_state(wsi) != LRS_WAITING_TO_SEND_CLOSE &&
426 lwsi_state(wsi) != LRS_ESTABLISHED &&
427 lwsi_state(wsi) != LRS_AWAITING_CLOSE_ACK)
434 (unsigned int)wsi->wsistate, *wp, wsi->a.protocol ?
435 wsi->a.protocol->name : "no protocol");
443 if (wsi->http.lcs) {
447 n = lws_http_compression_transform(wsi, buf, len, wp, &out, &o);
453 lws_wsi_tag(wsi), (int)len, (int)o, (int)*wp,
454 wsi->http.comp_ctx.may_have_more);
474 if (wsi->h2.send_END_STREAM ||
477 wsi->h2.send_END_STREAM = 1;
485 if (wsi->h2.send_END_STREAM ||
488 wsi->h2.send_END_STREAM = 1;
494 wsi->http.tx_content_length) {
495 wsi->http.tx_content_remain -= len;
497 lws_wsi_tag(wsi),
498 (unsigned long long)wsi->http.tx_content_remain);
499 if (!wsi->http.tx_content_remain) {
508 lws_wsi_tag(wsi), flags);
509 wsi->h2.send_END_STREAM = 1;
512 n = lws_h2_frame_write(wsi, n, flags, wsi->mux.my_sid, (unsigned int)len, buf);
523 rops_check_upgrades_h2(struct lws *wsi)
534 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD);
535 if (!wsi->a.vhost->h2.set.s[H2SET_ENABLE_CONNECT_PROTOCOL] ||
536 !wsi->mux_substream || !p || strcmp(p, "CONNECT"))
539 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_COLON_PROTOCOL);
544 lws_mux_mark_immortal(wsi);
545 wsi->h2_stream_carries_ws = 1;
547 lws_metrics_tag_wsi_add(wsi, "upg", "ws_over_h2");
549 if (lws_process_ws_upgrade(wsi))
605 rops_tx_credit_h2(struct lws *wsi, char peer_to_us, int add)
607 struct lws *nwsi = lws_get_network_wsi(wsi);
616 return lws_h2_update_peer_txcredit(wsi, (unsigned int)-1, add);
624 wsi->txc.tx_cr += add;
631 return lws_h2_tx_cr_get(wsi);
633 n = wsi->txc.peer_tx_cr_est;
641 rops_destroy_role_h2(struct lws *wsi)
643 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi];
647 lwsl_info("%s: %s: ah det due to close\n", __func__, lws_wsi_tag(wsi));
648 __lws_header_table_detach(wsi, 0);
653 if (ah->in_use && ah->wsi == wsi) {
654 lwsl_err("%s: ah leak: %s\n", __func__, lws_wsi_tag(wsi));
656 ah->wsi = NULL;
664 lws_http_compression_destroy(wsi);
667 if (wsi->upgraded_to_http2 || wsi->mux_substream) {
668 lws_hpack_destroy_dynamic_header(wsi);
670 if (wsi->h2.h2n)
671 lws_free_set_NULL(wsi->h2.h2n);
678 rops_close_kill_connection_h2(struct lws *wsi, enum lws_close_status reason)
682 if (wsi->http.proxy_clientside) {
684 wsi->http.proxy_clientside = 0;
686 if (user_callback_handle_rxflow(wsi->a.protocol->callback,
687 wsi,
689 wsi->user_space, NULL, 0))
690 wsi->http.proxy_clientside = 0;
694 if (wsi->mux_substream && wsi->h2_stream_carries_ws)
695 lws_h2_rst_stream(wsi, 0, "none");
697 if (wsi->mux_substream)
698 lws_h2_rst_stream(wsi, H2_ERR_STREAM_CLOSED, "swsi got closed");
701 lwsl_info(" %s, his parent %s: siblings:\n", lws_wsi_tag(wsi), lws_wsi_tag(wsi->mux.parent_wsi));
702 lws_wsi_mux_dump_children(wsi);
704 if (wsi->upgraded_to_http2 || wsi->mux_substream
706 || wsi->client_mux_substream
709 lwsl_info("closing %s: parent %s\n", lws_wsi_tag(wsi),
710 lws_wsi_tag(wsi->mux.parent_wsi));
712 if (wsi->mux.child_list && lwsl_visible(LLL_INFO)) {
713 lwsl_info(" parent %s: closing children: list:\n", lws_wsi_tag(wsi));
714 lws_wsi_mux_dump_children(wsi);
716 lws_wsi_mux_close_children(wsi, (int)reason);
719 if (wsi->upgraded_to_http2) {
721 struct lws_h2_protocol_send *w = wsi->h2.h2n->pps, *w1;
728 wsi->h2.h2n->pps = NULL;
733 wsi->client_mux_substream ||
735 wsi->mux_substream) &&
736 wsi->mux.parent_wsi) {
737 lws_wsi_mux_sibling_disconnect(wsi);
738 if (wsi->h2.pending_status_body)
739 lws_free_set_NULL(wsi->h2.pending_status_body);
746 rops_callback_on_writable_h2(struct lws *wsi)
753 // if (!lwsi_role_h2(wsi) && !lwsi_role_h2_ENCAPSULATION(wsi))
756 if (wsi->mux.requested_POLLOUT
758 && !wsi->client_h2_alpn
767 if (wsi->upgraded_to_http2 && !wsi->h2.h2n->pps &&
768 lws_wsi_txc_check_skint(&wsi->txc, lws_h2_tx_cr_get(wsi))) {
778 network_wsi = lws_get_network_wsi(wsi);
780 already = lws_wsi_mux_mark_parents_needing_writeable(wsi);
782 /* for network action, act only on the network wsi */
797 lws_h2_bind_for_post_before_action(struct lws *wsi)
806 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD);
811 if (!lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH) ||
812 !lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_PATH))
822 hit = lws_find_mount(wsi,
823 lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_PATH),
824 lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH));
827 lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_PATH),
844 pp = lws_vhost_name_to_protocol(wsi->a.vhost, name);
850 if (lws_bind_protocol(wsi, pp, __func__))
854 methidx = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len);
857 if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP,
858 wsi->user_space,
867 lws_prepare_access_log_info(wsi, uri_ptr, uri_len, methidx);
871 (int)wsi->wsistate, wsi->a.protocol->name);
873 lwsi_set_state(wsi, LRS_BODY);
875 if (wsi->http.content_length_explicitly_zero)
882 while (((!wsi->http.content_length_given) ||
883 wsi->http.rx_content_length) &&
884 (blen = lws_buflist_next_segment_len(&wsi->buflist, &buffered))) {
886 if ((size_t)wsi->http.rx_content_length < blen)
887 blen = (size_t)wsi->http.rx_content_length;
889 if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY,
890 wsi->user_space, buffered, blen))
892 lws_buflist_use_segment(&wsi->buflist, blen);
894 wsi->http.rx_content_length -= blen;
897 if (!wsi->buflist)
898 /* Take us off the pt's "wsi holding input buflist" list */
899 lws_dll2_remove(&wsi->dll_buflist);
901 if (wsi->http.content_length_given && wsi->http.rx_content_length)
905 if (!wsi->http.content_length_given && !wsi->h2.END_STREAM)
908 if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY_COMPLETION,
909 wsi->user_space, NULL, 0))
917 * we are the 'network wsi' for potentially many muxed child wsi with
930 rops_perform_user_POLLOUT_h2(struct lws *wsi)
938 wsi = lws_get_network_wsi(wsi);
940 wsi->mux.requested_POLLOUT = 0;
941 // if (!wsi->h2.initialized) {
946 lws_wsi_mux_dump_waiting_children(wsi);
948 wsi2 = &wsi->mux.child_list;
969 wa = &wsi->mux.child_list;
985 wa = &wsi->mux.child_list;
989 wa = &wsi->mux.child_list;
1011 wa = &wsi->mux.child_list;
1022 wa = &wsi->mux.child_list;
1028 wsi->could_have_pending = 0;
1039 wa = &wsi->mux.child_list;
1059 * that there is no partial pending on the network wsi.
1096 "(wsi->http.rx_content_remain %lld)\n",
1101 * that will complete asynchronously under its own wsi
1110 wa = &wsi->mux.child_list;
1114 wa = &wsi->mux.child_list;
1125 wa = &wsi->mux.child_list;
1142 * DATA here... if so close the actual wsi
1149 wa = &wsi->mux.child_list;
1212 wa = &wsi->mux.child_list;
1225 * set client wsi to immortal long-poll mode; send END_STREAM
1252 wa = &wsi->mux.child_list;
1259 } while (wsi2 && *wsi2 && !lws_send_pipe_choked(wsi));
1261 // lws_wsi_mux_dump_waiting_children(wsi);
1263 if (lws_wsi_mux_action_pending_writeable_reqs(wsi))
1270 rops_encapsulation_parent_h2(struct lws *wsi)
1272 if (wsi->mux.parent_wsi)
1273 return wsi->mux.parent_wsi;
1279 rops_alpn_negotiated_h2(struct lws *wsi, const char *alpn)
1283 lwsl_debug("%s: client %d\n", __func__, lwsi_role_client(wsi));
1285 if (lwsi_role_client(wsi)) {
1287 wsi->client_h2_alpn = 1;
1291 wsi->upgraded_to_http2 = 1;
1295 ah = wsi->http.ah;
1297 lws_role_transition(wsi, lwsi_role_client(wsi) ? LWSIFR_CLIENT : LWSIFR_SERVER, LRS_H2_AWAIT_PREFACE,
1301 wsi->http.ah = ah;
1303 if (!wsi->h2.h2n)
1304 wsi->h2.h2n = lws_zalloc(sizeof(*wsi->h2.h2n), "h2n");
1305 if (!wsi->h2.h2n)
1308 lws_h2_init(wsi);
1312 if (lws_hpack_dynamic_size(wsi,
1313 (int)wsi->h2.h2n->our_set.s[H2SET_HEADER_TABLE_SIZE]))
1315 wsi->txc.tx_cr = 65535;
1317 lwsl_info("%s: %s: configured for h2\n", __func__, lws_wsi_tag(wsi));
1323 rops_issue_keepalive_h2(struct lws *wsi, int isvalid)
1325 struct lws *nwsi = lws_get_network_wsi(wsi);
1340 assert(wsi == nwsi);