diff --git a/lib/context.c b/lib/context.c index 037f4431..33dbbe07 100644 --- a/lib/context.c +++ b/lib/context.c @@ -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; diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 743017b7..855ee273 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -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 */ }; /** diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 65582731..1ddcd0fe 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -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. diff --git a/lib/service.c b/lib/service.c index 63d6da73..a520abcd 100644 --- a/lib/service.c +++ b/lib/service.c @@ -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 { diff --git a/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c b/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c index 81a87acc..d204cbe6 100644 --- a/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c +++ b/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c @@ -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) /*