use context service buffer instead of stack for create_context

Signed-off-by: Andy Green <andy.green@linaro.org>
use context service buffer instead of stack for clent_connect_2

Signed-off-by: Andy Green <andy.green@linaro.org>
use context service buffer instead of stack for clent_connect

Signed-off-by: Andy Green <andy.green@linaro.org>
optimize wsi using bitfields and enums to chars

Also max protocols to 5 (overridable by configure) and max extensions
from 10 to 3 by default (also overridable by configure).

wsi is down to 608 on x86_64 with this.

Signed-off-by: Andy Green <andy.green@linaro.org>
throw out lws_websocket_related cruft

Signed-off-by: Andy Green <andy.green@linaro.org>
fix error path in file transfer

Signed-off-by: Andy Green <andy.green@linaro.org>
dont close in user callback wrapper let ancestor do it

Signed-off-by: Andy Green <andy.green@linaro.org>
stop O2 override

Now we are building with -O0 -g and debug enabled by default.
--disable-debug in configure will get you a -04 without -g

Signed-off-by: Andy Green <andy.green@linaro.org>
remove minimum frame size for deflate

The idea here seems wrong, if we have a mixture of frames of varying
sizes above and below the limit, we segfault in deflate after skipping
it once.

If the protocol doesn't want compression because many frames are
small, it should veto the extension in the user callback.  If only
a few frames are tiny, the overhead for compressing it all is tiny.

Signed-off-by: Andy Green <andy.green@linaro.org>
use part of service buffer to make response not malloc

Done with an offset because the encoded key is stored at the
start of service_buffer at this time

Signed-off-by: Andy Green <andy.green@linaro.org>
remove extension cruft from struct lws

Signed-off-by: Andy Green <andy.green@linaro.org>
valgrind free context allocations

Signed-off-by: Andy Green <andy.green@linaro.org>
improve static allocation notice

Signed-off-by: Andy Green <andy.green@linaro.org>
replace per header mallocs with single malloc 3 level struct

This big patch replaces the malloc / realloc per header
approach used until now with a single three-level struct
that gets malloc'd during the header union phase and freed
in one go when we transition to a different union phase.

It's more expensive in that we malloc a bit more than 4Kbytes,
but it's a lot cheaper in terms of malloc, frees, heap fragmentation,
no reallocs, nothing to configure.  It also moves from arrays of
pointers (8 bytes on x86_64) to unsigned short offsets into the
data array, (2 bytes on all platforms).

The 3-level thing is all in one struct

 - array indexed by the header enum, pointing to first "fragment" index
	(ie, header type to fragment lookup, or 0 for none)

 - array of fragments indexes, enough for 2 x the number of known headers
	(fragment array... note that fragments can point to a "next"
	fragment if the same header is spread across multiple entries)

 - linear char array where the known header payload gets written
	(fragments point into null-terminated strings stored in here,
	only the known header content is stored)

http headers can legally be split over multiple headers of the same
name which should be concatenated.  This scheme does not linearly
conatenate them but uses a linked list in the fragment structs to
link them.  There are apis to get the total length and copy out a
linear, concatenated version to a buffer.

Signed-off-by: Andy Green <andy.green@linaro.org>
valgrind drop header allocation down http path

Signed-off-by: Andy Green <andy.green@linaro.org>
valgrind context destroy close all conns properly

Signed-off-by: Andy Green <andy.green@linaro.org>
valgrind introduce protocol init and destroy user callbacks

To get a clean bill of health from valgrind, we have to have a way to
inform the user code that we're going down and it should free everything
it is holding that was malloc'd.

This patch introduces LWS_CALLBACK_PROTOCOL_DESTROY which each protocol
gets when the context is being destroyed and no more activity will come
after that call.  They can get rid of everything there.

To match it, LWS_CALLBACK_PROTOCOL_INIT is introduced which would allow
one-time init per protocol too.

Signed-off-by: Andy Green <andy.green@linaro.org>
valgrind free rx_user_buffer if entered CONNMODE_WS_SERVING

This seems to be enough to get a clean valgrind run for the
test server with 1 x chrome and 1 x libwebsockets-test-client
session being run for 10s

lwsts[19767]: libwebsockets-test-server exited cleanly
==19767==
==19767== HEAP SUMMARY:
==19767==     in use at exit: 0 bytes in 0 blocks
==19767==   total heap usage: 41,071 allocs, 41,071 frees, 27,464,834 bytes allocated
==19767==
==19767== All heap blocks were freed -- no leaks are possible
==19767==
==19767== For counts of detected and suppressed errors, rerun with: -v
==19767== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

test client is another story...

Signed-off-by: Andy Green <andy.green@linaro.org>
client convert to new headers scheme eliminating mallocs

This removes all the direct wsi members specific to clients,
most of them are moved to being fake headers in the next 3-layer
header scheme, c_port moves to being a member of the u.hdr
unionized struct.

It gets rid of a lot of fiddly mallocs and frees(), despite it
adds a small internal API to create the fake headers, actually
the patch deletes more than it adds...

Signed-off-by: Andy Green <andy.green@linaro.org>
valgrind client go through context destroy on connection error

Signed-off-by: Andy Green <andy.green@linaro.org>