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

h2: allow control of rx scratch buffer from vhost info

This commit is contained in:
Andy Green 2018-03-31 11:30:12 +08:00
parent 3038af5b07
commit 2d3fc52b73
5 changed files with 16 additions and 6 deletions

View file

@ -617,6 +617,10 @@ lws_create_vhost(struct lws_context *context,
vh->pvo = info->pvo;
vh->headers = info->headers;
vh->user = info->user;
if (!info->h2_rx_scratch_size)
vh->h2_rx_scratch_size = LWS_H2_RX_SCRATCH_SIZE;
else
vh->h2_rx_scratch_size = info->h2_rx_scratch_size;
vh->ssl_info_event_mask = info->ssl_info_event_mask;
if (info->keepalive_timeout)
vh->keepalive_timeout = info->keepalive_timeout;

View file

@ -2872,6 +2872,10 @@ struct lws_context_creation_info {
/**< VHOST: If non-NULL, when asked to serve a non-existent file,
* lws attempts to server this url path instead. Eg,
* "/404.html" */
unsigned int h2_rx_scratch_size;
/**< VHOST: size of the rx scratch buffer for each stream. 0 =
* default (512 bytes). This affects the RX chunk size
* at the callback. */
/* Add new things just above here ---^
* This is part of the ABI, don't needlessly break compatibility
@ -2881,7 +2885,7 @@ struct lws_context_creation_info {
* was not built against the newer headers.
*/
void *_unused[8]; /**< dummy */
void *_unused[4]; /**< dummy */
};
/**

View file

@ -407,6 +407,8 @@ extern "C" {
#define SYSTEM_RANDOM_FILEPATH "/dev/urandom"
#endif
#define LWS_H2_RX_SCRATCH_SIZE 512
/*
* Choose the SSL backend
*/
@ -994,6 +996,7 @@ struct lws_vhost {
int listen_port;
unsigned int http_proxy_port;
unsigned int h2_rx_scratch_size;
#if defined(LWS_WITH_SOCKS5)
unsigned int socks_proxy_port;
#endif
@ -1641,8 +1644,6 @@ struct lws_h2_ghost_sid {
uint32_t sid;
};
#define LWS_H2_RX_SCRATCH_SIZE 512
/*
* http/2 connection info that is only used by the root connection that has
* the network connection.

View file

@ -744,7 +744,7 @@ int lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len)
len -= n;
assert ((char *)buf >= (char *)h2n->rx_scratch &&
(char *)&buf[len] <=
(char *)&h2n->rx_scratch[LWS_H2_RX_SCRATCH_SIZE]);
(char *)&h2n->rx_scratch[wsi->vhost->h2_rx_scratch_size]);
h2n->rx_scratch_pos = lws_ptr_diff(buf, h2n->rx_scratch);
h2n->rx_scratch_len = len;
@ -1690,13 +1690,13 @@ read:
if (!wsi->h2.h2n->rx_scratch) {
wsi->h2.h2n->rx_scratch =
lws_malloc(
LWS_H2_RX_SCRATCH_SIZE,
wsi->vhost->h2_rx_scratch_size,
"h2 rx scratch");
if (!wsi->h2.h2n->rx_scratch)
goto close_and_handled;
}
eff_buf.token = wsi->h2.h2n->rx_scratch;
eff_buf.token_len = LWS_H2_RX_SCRATCH_SIZE;
eff_buf.token_len = wsi->vhost->h2_rx_scratch_size;
} else
#endif
{

View file

@ -144,6 +144,7 @@ int main(int argc, char **argv)
info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */
info.protocols = protocols;
info.max_http_header_pool = 16;
info.h2_rx_scratch_size = 4096; /* trade h2 stream rx memory for speed */
#if defined(LWS_WITH_MBEDTLS)
/*