_lws_header_table_reset(ah);
+ wsi->u.hdr.parser_state = WSI_TOKEN_NAME_PART;
+ wsi->u.hdr.lextable_pos = 0;
+
/* since we will restart the ah, our new headers are not completed */
- // wsi->hdr_parsing_completed = 0;
+ wsi->hdr_parsing_completed = 0;
/*
* if we inherited pending rx (from socket adoption deferred
_lws_change_pollfd(wsi, 0, LWS_POLLIN, &pa);
- lwsl_info("%s: wsi %p: ah %p: count %d (on exit)\n", __func__,
+ lwsl_info("%s: did attach wsi %p: ah %p: count %d (on exit)\n", __func__,
(void *)wsi, (void *)wsi->u.hdr.ah, pt->ah_count_in_use);
lws_pt_unlock(pt);
return 1;
}
+void
+lws_header_table_force_to_detachable_state(struct lws *wsi)
+{
+ if (wsi->u.hdr.ah) {
+ wsi->u.hdr.ah->rxpos = -1;
+ wsi->u.hdr.ah->rxlen = -1;
+ wsi->hdr_parsing_completed = 1;
+ }
+}
+
+int
+lws_header_table_is_in_detachable_state(struct lws *wsi)
+{
+ struct allocated_headers *ah = wsi->u.hdr.ah;
+
+ return ah && ah->rxpos == ah->rxlen && wsi->hdr_parsing_completed;
+}
+
int lws_header_table_detach(struct lws *wsi, int autoservice)
{
struct lws_context *context = wsi->context;
struct lws **pwsi;
time_t now;
+ if (!ah)
+ return 0;
+
lwsl_info("%s: wsi %p: ah %p (tsi=%d, count = %d)\n", __func__,
(void *)wsi, (void *)ah, wsi->tsi,
pt->ah_count_in_use);
lws_free_set_NULL(wsi->u.hdr.preamble_rx);
/* may not be detached while he still has unprocessed rx */
- if (ah && ah->rxpos != ah->rxlen) {
- lwsl_err("%s: %p: CANNOT DETACH rxpos:%d, rxlen:%d\n", __func__, wsi,
- ah->rxpos, ah->rxlen);
- assert(ah->rxpos == ah->rxlen);
-
+ if (!lws_header_table_is_in_detachable_state(wsi)) {
+ lwsl_err("%s: %p: CANNOT DETACH rxpos:%d, rxlen:%d, wsi->hdr_parsing_completed = %d\n", __func__, wsi,
+ ah->rxpos, ah->rxlen, wsi->hdr_parsing_completed);
return 0;
}
pt->ah_wait_list_length--;
#ifndef LWS_NO_CLIENT
- if (wsi->state == LWSS_CLIENT_UNCONNECTED)
+ if (wsi->state == LWSS_CLIENT_UNCONNECTED) {
+ lws_pt_unlock(pt);
+
if (!lws_client_connect_via_info2(wsi)) {
/* our client connect has failed, the wsi
* has been closed
*/
- lws_pt_unlock(pt);
return -1;
}
+ return 0;
+ }
#endif
- assert(!!pt->ah_wait_list_length == !!(int)(long)pt->ah_wait_list);
+ assert(!!pt->ah_wait_list_length == !!(lws_intptr_t)pt->ah_wait_list);
bail:
lwsl_info("%s: wsi %p: ah %p (tsi=%d, count = %d)\n", __func__,
(void *)wsi, (void *)ah, wsi->tsi,
{
return wsi->u.ws.frame_is_binary;
}
+
+void
+lws_add_wsi_to_draining_ext_list(struct lws *wsi)
+{
+ struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
+
+ if (wsi->u.ws.rx_draining_ext)
+ return;
+
+ lwsl_ext("%s: RX EXT DRAINING: Adding to list\n", __func__);
+
+ wsi->u.ws.rx_draining_ext = 1;
+ wsi->u.ws.rx_draining_ext_list = pt->rx_draining_ext_list;
+ pt->rx_draining_ext_list = wsi;
+}
+
void
lws_remove_wsi_from_draining_ext_list(struct lws *wsi)
{
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
struct lws **w = &pt->rx_draining_ext_list;
+ if (!wsi->u.ws.rx_draining_ext)
+ return;
+
+ lwsl_ext("%s: RX EXT DRAINING: Removing from list\n", __func__);
+
wsi->u.ws.rx_draining_ext = 0;
+
/* remove us from context draining ext list */
while (*w) {
if (*w == wsi) {
+ /* if us, point it instead to who we were pointing to */
*w = wsi->u.ws.rx_draining_ext_list;
break;
}
int
lws_rx_sm(struct lws *wsi, unsigned char c)
{
- struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
int callback_action = LWS_CALLBACK_RECEIVE;
int ret = 0, n, rx_draining_ext = 0;
struct lws_tokens eff_buf;
if (n && eff_buf.token_len) {
/* extension had more... main loop will come back */
- // lwsl_notice("ext has stuff to drain\n");
- wsi->u.ws.rx_draining_ext = 1;
- wsi->u.ws.rx_draining_ext_list = pt->rx_draining_ext_list;
- pt->rx_draining_ext_list = wsi;
+ lws_add_wsi_to_draining_ext_list(wsi);
} else
lws_remove_wsi_from_draining_ext_list(wsi);