reduce http_parser from 60 bytes to 48 bytes

This is mostly done by using sized types instead of enums, and
reordering fields to allow better packing.

I also moved the 'upgrade' field out of the PRIVATE section and into
the READ-ONLY section, as I believe that it is supposed to be
non-private.
event_stream
Cliff Frey 15 years ago committed by Ryan Dahl
parent 0e8ad4e003
commit 5502cddd35

@ -94,17 +94,10 @@ enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
struct http_parser { struct http_parser {
/** PRIVATE **/ /** PRIVATE **/
enum http_parser_type type; unsigned char type;
unsigned short state; unsigned char state;
unsigned short header_state; unsigned char header_state;
size_t index; unsigned char index;
/* 1 = Upgrade header was present and the parser has exited because of that.
* 0 = No upgrade header present.
* Should be checked when http_parser_execute() returns in addition to
* error checking.
*/
unsigned short upgrade;
char flags; char flags;
@ -122,11 +115,18 @@ struct http_parser {
/** READ-ONLY **/ /** READ-ONLY **/
unsigned short status_code; /* responses only */ unsigned short status_code; /* responses only */
enum http_method method; /* requests only */ unsigned short method; /* requests only */
unsigned short http_major; unsigned short http_major;
unsigned short http_minor; unsigned short http_minor;
char buffer[HTTP_PARSER_MAX_METHOD_LEN]; char buffer[HTTP_PARSER_MAX_METHOD_LEN];
/* 1 = Upgrade header was present and the parser has exited because of that.
* 0 = No upgrade header present.
* Should be checked when http_parser_execute() returns in addition to
* error checking.
*/
char upgrade;
/** PUBLIC **/ /** PUBLIC **/
void *data; /* A pointer to get hook to the "connection" or "socket" object */ void *data; /* A pointer to get hook to the "connection" or "socket" object */
}; };

Loading…
Cancel
Save