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

4581 commits

Author SHA1 Message Date
Andy Green
3886ec7246 valgrind client close in a controlled way on SIGINT
With this, both the test server and client are valgrind-clean
tested with a chrome session also active to the server

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 14:33:03 +08:00
Andy Green
fdd305a986 valgrind eliminate uninitialized warning on close
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 14:32:48 +08:00
Andy Green
1ae1b1fae8 valgrind also deallocate rx buf on close when client
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 14:12:32 +08:00
Andy Green
310655bf27 valgrind dont close things directly in the callback
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 14:08:50 +08:00
Andy Green
93f98d748d valgrind client go through context destroy on connection error
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 14:05:02 +08:00
Andy Green
e77fb804dc 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>
2013-02-11 13:04:45 +08:00
Andy Green
bebc1bb852 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>
2013-02-11 12:37:13 +08:00
Andy Green
a7109e6ebf 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>
2013-02-11 12:05:54 +08:00
Andy Green
7b92205086 valgrind context destroy close all conns properly
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 11:43:05 +08:00
Andy Green
4708a02f06 valgrind drop header allocation down http path
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 11:27:44 +08:00
Andy Green
16ab3185c4 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>
2013-02-11 11:10:57 +08:00
Andy Green
a86f634d4f improve static allocation notice
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 11:10:56 +08:00
Andy Green
4659648159 valgrind free context allocations
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 11:04:01 +08:00
Andy Green
33fa908293 remove extension cruft from struct lws
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 10:31:17 +08:00
Andy Green
60fbc63513 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>
2013-02-11 10:19:59 +08:00
Andy Green
895d56d4ce 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>
2013-02-11 10:18:31 +08:00
Andy Green
a3957ef804 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>
2013-02-11 09:31:43 +08:00
Andy Green
aedc953a8f dont close in user callback wrapper let ancestor do it
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 00:34:43 +08:00
Andy Green
5ab9c68687 fix error path in file transfer
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 00:34:43 +08:00
Andy Green
acfa1a879e throw out lws_websocket_related cruft
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 00:34:43 +08:00
Andy Green
d91d5e8d22 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>
2013-02-11 00:34:43 +08:00
Andy Green
e48ba315b8 use context service buffer instead of stack for clent_connect
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 00:34:43 +08:00
Andy Green
f54a94b494 use context service buffer instead of stack for clent_connect_2
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 00:34:42 +08:00
Andy Green
e310b0c443 use context service buffer instead of stack for create_context
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-11 00:34:42 +08:00
Andy Green
2b40b79e6d fix non ssl changes missed from context api change
http://libwebsockets.org/trac/ticket/11#comment:5

Reported-by: amn
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 22:22:01 +08:00
Andy Green
c97067cf69 use context service buffer instead of stack for lws_client_socket_service
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 11:03:32 +08:00
Andy Green
0390608a39 use context service buffer instead of stack for server_socket_service
Reduces lws_server_socket_service from 4208 to 80 stack allocation
on x86_64

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 10:49:15 +08:00
Andy Green
5f348a80a0 add static stack analysis
You can get a worst-first list of stack allocators like this

$ cat ./lib/.libs/*.su | sort -k2g | tac

On x86_64, currently the ones above 100 bytes are

server.c:126:5:lws_server_socket_service	4208	static
client.c:42:5:lws_client_socket_service	1584	static
libwebsockets.c:1539:1:libwebsocket_create_context	1136	static
libwebsockets.c:783:1:libwebsocket_service_fd	656	static
client-handshake.c:3:22:__libwebsocket_client_connect_2	592	static
libwebsockets.c:2149:6:_lws_log	496	static
server-handshake.c:33:1:handshake_0405	464	static
libwebsockets.c:2102:13:lwsl_emit_stderr	352	static
client.c:351:1:lws_client_interpret_server_handshake	240	static
daemonize.c:93:1:lws_daemonize	224	static
libwebsockets.c:434:1:libwebsockets_get_peer_addresses	208	static
client.c:694:1:libwebsockets_generate_client_handshake	208	static
output.c:534:5:libwebsockets_serve_http_file	192	static
output.c:51:6:lwsl_hexdump	176	static
sha-1.c:316:1:SHA1	160	static
libwebsockets.c:157:1:libwebsocket_close_and_free_session	144	static

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 10:49:15 +08:00
Andy Green
f0b79e238c dont try figure out listen_service_fd position if unset
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 10:49:11 +08:00
Andy Green
a47865fa19 dont try set per socket keepalive timing on bsds
As per http://libwebsockets.org/trac/ticket/10
BSD doesn't support setting keepalive info per-socket

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 09:39:47 +08:00
Andy Green
9e4c917c27 fix broken listen socket piggybacking
As reported here

http://libwebsockets.org/trac/ticket/11

the code for connection storm handling had rotted, fds[0] is no longer
always related to the listen socket when serving.

This patch updates it to determine the listen socket correctly to stop
infinite recursion here.

Reported-by: amn
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 09:06:38 +08:00
Andy Green
a690cd066e introduce keepalive option and make common socket options function
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-09 14:27:38 +08:00
Andy Green
da1fb0b89f remove receiving timeout for client
Now we enforce nonblocking everywhere, hopefully properly,
this rx timeout stuff shouldn't be needed.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-09 14:27:30 +08:00
Andy Green
8e0c98484e correct test client to close synchronously with last send
Noticed previously the test client lifetime is decoupled from
the actual send activity.  With SSL if the connection starts but
there is a period of SSL-layer "blocking" (actually fail-and-retry)
the mirror lifetime could be exhausted before the connection really
completed, making it stall after it was then closed.

This corrects that so connection lifetime management is done in the
send callback.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-09 14:27:24 +08:00
Andy Green
e7c97e8429 align max frame for mirror protocol to what the code does
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-09 14:27:15 +08:00
Andy Green
1b26527e72 change context creation params to struct
*** This patch changes an API all apps use ***

Context creation parameters are getting a bit out of control, this
patch creates a struct to contain them.

All the test apps are updated accordingly.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-09 14:01:09 +08:00
Andy Green
0480f6420c handshake bail3 should be bail
Reported-by: Jack Mitchell <ml@communistcode.co.uk>
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-08 20:10:03 +08:00
Andy Green
5449511d3e remove fixed rx buffer allow definition per protocol
A new protocol member is defined that controls the size of rx
buffer allocation per connection.  For compatibility 0 size
allocates 4096, but you should adapt your protocol definition
array in the user code to declare an appropriate value.

See the changelog for more detail.

The advantage is the rx frame buffer size is now tailored to
what is expected from the protocol, rather than being fixed
to a default of 4096.  If your protocol only sends frames of
a dozen bytes this allows you to only allocate an rx frame
buffer of the same size.

For example the per-connection allocation (excluding headers)
for the test server fell from ~4500 to < 750 bytes with this.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-08 13:16:07 +08:00
Andy Green
f27034201f account for context in static allocation figure
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-08 13:11:50 +08:00
Andy Green
9b09dc0213 remove all PATH_MAX or MAX_PATH
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-08 13:11:47 +08:00
Andy Green
e84652c4ea use context service buf in place of large stack arrays
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-08 13:01:02 +08:00
Andy Green
b8b247d3e1 remove need for filepath buffer on http file serve
This gets rid of the stack buffer while serving files, and the
PATH_MAX char array that used to hold the filepath in the wsi.

It holds an extra file descriptor open while serving the file,
however it attempts to stuff the socket with as much of the
file as it can take.  For files of a few KB, that typically
completes (without blocking) in the call to
libwebsockets_serve_http_file() and then closes the file
descriptor before returning.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-08 12:19:01 +08:00
Andy Green
c11b587aed add static linking exception to LICENSE
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-07 23:44:21 +08:00
Andy Green
750200121e add unchanged lgpl 2.1 in LICENSE
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-07 23:43:56 +08:00
Peter Pentchev
3b233cbc24 Fix memory leaks when creating a context. 2013-02-07 23:36:52 +08:00
Peter Pentchev
4d46cb5a3f Generate the API reference in text format, too. 2013-02-07 23:36:37 +08:00
Peter Pentchev
c74964ec44 Fix two typos. 2013-02-07 23:23:10 +08:00
Andy Green
ed334463e8 changelog header lifecycle
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-07 21:14:33 +08:00
Andy Green
23c5f2ecd0 add autotools bits for cyassl
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-07 20:30:56 +08:00
Andy Green
68a672bb44 unionize header token array
This reduces the size of struct libwebscocket from 4840 to 4552
on x86_64

There are also big benefits on malloc pool fragmentation and
allocation, the header allocations only exist between the first
peer communication and websocket connection establishment for
both server and client.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-07 20:30:56 +08:00