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

remove header name buffer

The header name buffer and its max length handling has actually
been unused since the minilex parser was introduced.  We hold
parsing state in the lex-type parts and don't need to store or
worry about max length, since the parser will let us know as
soon as it can't be a match for the valid header names.

This strips it out reducing the per-connection allocation for
x86_64 with default configure from 224 to 160.

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2013-02-18 10:22:42 +08:00
parent 0caf9c5acb
commit cc7cb68ded
5 changed files with 1 additions and 25 deletions

View file

@ -147,10 +147,6 @@ They all have reasonable defaults usable for all use-cases except resource-
constrained, so you only need to take care about them if you want to tune them
to the amount of memory available.
- LWS_MAX_HEADER_NAME_LENGTH default 64: max characters in an HTTP header
name that libwebsockets can cope with, if a header arrives bigger than this
it's ignored until the next header is seen
- LWS_MAX_HEADER_LEN default 1024: allocated area to copy http headers that
libwebsockets knows about into. You only need to think about increasing this
if your application might have monster length URLs for example, or some other

View file

@ -192,7 +192,6 @@ libwebsocket_client_connect(struct libwebsocket_context *context,
ietf_version_or_minus_one = SPEC_LATEST_SUPPORTED;
wsi->ietf_spec_revision = ietf_version_or_minus_one;
wsi->u.hdr.name_buffer_pos = 0;
wsi->user_space = NULL;
wsi->state = WSI_STATE_CLIENT_UNCONNECTED;
wsi->protocol = NULL;

View file

@ -468,21 +468,6 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
case WSI_TOKEN_NAME_PART:
lwsl_parser("WSI_TOKEN_NAME_PART '%c'\n", c);
if (wsi->u.hdr.name_buffer_pos ==
sizeof(wsi->u.hdr.name_buffer) - 1) {
/* did we see HTTP token yet? */
if (!wsi->u.hdr.ah->frag_index[WSI_TOKEN_GET_URI]) {
lwsl_info("junk before method\n");
return -1;
}
/* name bigger than we can handle, skip until next */
wsi->u.hdr.name_buffer_pos = 0;
wsi->u.hdr.parser_state = WSI_TOKEN_SKIPPING;
break;
}
wsi->u.hdr.name_buffer[wsi->u.hdr.name_buffer_pos++] = c;
wsi->u.hdr.name_buffer[wsi->u.hdr.name_buffer_pos] = '\0';
wsi->u.hdr.lextable_pos =
lextable_decode(wsi->u.hdr.lextable_pos, c);
@ -510,7 +495,7 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
n = lextable[wsi->u.hdr.lextable_pos] & 0x7f;
lwsl_parser("known hdr '%s'\n", wsi->u.hdr.name_buffer);
lwsl_parser("known hdr %d\n", n);
if (n == WSI_TOKEN_GET_URI &&
wsi->u.hdr.ah->frag_index[WSI_TOKEN_GET_URI]) {
@ -586,7 +571,6 @@ start_fragment:
wsi->u.hdr.lextable_pos = 0;
} else
wsi->u.hdr.parser_state = WSI_TOKEN_SKIPPING;
wsi->u.hdr.name_buffer_pos = 0;
break;
/* we're done, ignore anything else */
case WSI_PARSING_COMPLETE:

View file

@ -322,8 +322,6 @@ struct allocated_headers {
};
struct _lws_header_related {
char name_buffer[LWS_MAX_HEADER_NAME_LENGTH];
unsigned char name_buffer_pos;
struct allocated_headers *ah;
int lextable_pos;
unsigned char parser_state; /* enum lws_token_indexes */

View file

@ -100,7 +100,6 @@ libwebsocket_create_new_server_wsi(struct libwebsocket_context *context)
/* intialize the instance struct */
new_wsi->state = WSI_STATE_HTTP;
new_wsi->u.hdr.name_buffer_pos = 0;
new_wsi->mode = LWS_CONNMODE_HTTP_SERVING;
new_wsi->hdr_parsing_completed = 0;