Skip to content

Commit f94bef4

Browse files
committed
lws_header_table_reset: make caller responsibility to clear down ah rx buffer
There are two kinds of reaason to call lws_header_table_reset(), one is we are reallocating a destroyed ah to another wsi, and the other is we are moving to the next pipelined header set still on the same wsi, and we need a "weaker" reset that only clears down the state related to the header parsing, not everything about the ah context including the ah rx buffer. This patch moves the ah rxbuffer rxpos and rxlen resetting out of lws_header_table_reset() and to be the responsibility of the caller. Callers who are moving the ah to another wsi are patched to deal with resetting rxpos and rxlen and lws_http_transaction_completed() who only resets the ah when moving to the next pipelined headers, no longer wrongly clears the ah rxbuf. warmcat#638
1 parent b0ff623 commit f94bef4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/parsers.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ lextable_decode(int pos, char c)
6060
}
6161
}
6262

63+
// doesn't scrub the ah rxbuffer by default, parent must do if needed
64+
6365
void
6466
lws_header_table_reset(struct lws *wsi, int autoservice)
6567
{
@@ -77,10 +79,6 @@ lws_header_table_reset(struct lws *wsi, int autoservice)
7779
ah->nfrag = 0;
7880
ah->pos = 0;
7981

80-
/* and reset the rx state */
81-
ah->rxpos = 0;
82-
ah->rxlen = 0;
83-
8482
/* since we will restart the ah, our new headers are not completed */
8583
// wsi->hdr_parsing_completed = 0;
8684

@@ -182,6 +180,11 @@ lws_header_table_attach(struct lws *wsi, int autoservice)
182180
lws_pt_unlock(pt);
183181

184182
reset:
183+
184+
/* and reset the rx state */
185+
wsi->u.hdr.ah->rxpos = 0;
186+
wsi->u.hdr.ah->rxlen = 0;
187+
185188
lws_header_table_reset(wsi, autoservice);
186189
time(&wsi->u.hdr.ah->assigned);
187190

@@ -288,6 +291,9 @@ int lws_header_table_detach(struct lws *wsi, int autoservice)
288291

289292
wsi->u.hdr.ah = ah;
290293
ah->wsi = wsi; /* new owner */
294+
/* and reset the rx state */
295+
ah->rxpos = 0;
296+
ah->rxlen = 0;
291297
lws_header_table_reset(wsi, autoservice);
292298
time(&wsi->u.hdr.ah->assigned);
293299

lib/server.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,11 +1791,15 @@ lws_server_socket_service(struct lws_context *context, struct lws *wsi,
17911791
if ( wsi->u.hdr.ah->rxlen)
17921792
wsi->u.hdr.ah->rxpos += n;
17931793

1794+
lwsl_debug("%s: wsi %p: ah read rxpos %d, rxlen %d\n", __func__, wsi, wsi->u.hdr.ah->rxpos, wsi->u.hdr.ah->rxlen);
1795+
17941796
if (wsi->u.hdr.ah->rxpos == wsi->u.hdr.ah->rxlen &&
17951797
(wsi->mode != LWSCM_HTTP_SERVING &&
17961798
wsi->mode != LWSCM_HTTP_SERVING_ACCEPTED &&
17971799
wsi->mode != LWSCM_HTTP2_SERVING))
17981800
lws_header_table_detach(wsi, 1);
1801+
else
1802+
wsi->more_rx_waiting = 1;
17991803
}
18001804
break;
18011805
}

0 commit comments

Comments
 (0)