platform/upstream/libwebsockets.git
11 years agoapi remove hangup_on_client
Andy Green [Tue, 12 Feb 2013 02:15:25 +0000 (10:15 +0800)]
api remove hangup_on_client

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoupdate test echo for iface info member namechange
Andy Green [Tue, 12 Feb 2013 02:10:32 +0000 (10:10 +0800)]
update test echo for iface info member namechange

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoeliminate snprintf
Andy Green [Tue, 12 Feb 2013 02:07:22 +0000 (10:07 +0800)]
eliminate snprintf

The two cases where I introduced snprintf are either already
safe for buffer overflow or can be made so with one extra
statement, allowing sprintf.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix info struct api docs for iface vs interface
Andy Green [Tue, 12 Feb 2013 02:13:02 +0000 (10:13 +0800)]
fix info struct api docs for iface vs interface

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoFixed compilation on Windows.
Joakim Soderberg [Mon, 11 Feb 2013 16:52:23 +0000 (17:52 +0100)]
Fixed compilation on Windows.

11 years agoupdate memory performance info
Andy Green [Mon, 11 Feb 2013 14:40:39 +0000 (22:40 +0800)]
update memory performance info

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix ssl reject path for freeing header allocation
Andy Green [Mon, 11 Feb 2013 13:43:41 +0000 (21:43 +0800)]
fix ssl reject path for freeing header allocation

If the SSL connection failed before the headers came, we were not
dealing with deallocating the header malloc.  This takes care of it.

Using CyaSSL, we are then valgrind-clean for ssl client and server.

With OpenSSL, there is 88 bytes lost at init that never changes or
gets recovered.  AFAIK there's nothing to do about that.

OpenSSL also blows these during operation

==1059== Conditional jump or move depends on uninitialised value(s)
==1059==    at 0x4A0B131: bcmp (mc_replace_strmem.c:935)
==1059==    by 0x3014CDDBA8: ??? (in /usr/lib64/libcrypto.so.1.0.1c)
==1059==    by 0x3015430852: tls1_enc (in /usr/lib64/libssl.so.1.0.1c)
==1059==    by 0x3015428CEC: ssl3_read_bytes (in /usr/lib64/libssl.so.1.0.1c)
==1059==    by 0x30154264C5: ??? (in /usr/lib64/libssl.so.1.0.1c)
==1059==    by 0x4C3C596: lws_server_socket_service (server.c:153)
==1059==    by 0x4C32C1E: libwebsocket_service_fd (libwebsockets.c:927)
==1059==    by 0x4C33270: libwebsocket_service (libwebsockets.c:1225)
==1059==    by 0x401C84: main (in /usr/bin/libwebsockets-test-server)

However googling around

https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/60021
http://www.openssl.org/support/faq.html#PROG13
(also the next FAQ down)

it seems OpenSSL have a relaxed attitude to this and it's expected.
It's interesting CyaSSL works fine but doesn't have that problem...

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix busted debug format in ssl mode
Andy Green [Mon, 11 Feb 2013 12:10:56 +0000 (20:10 +0800)]
fix busted debug format in ssl mode

CyaSSL blows (symptomless?) uninitialized memory accesses in
valgrind when using SSL_get_version()... don't need to do it...

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix string escape runon
Andy Green [Mon, 11 Feb 2013 12:03:59 +0000 (20:03 +0800)]
fix string escape runon

Oh well it was a big patch to just be cosmetic ^^

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix without server
Andy Green [Mon, 11 Feb 2013 11:36:15 +0000 (19:36 +0800)]
fix without server

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agostyle cleanup
Andy Green [Mon, 11 Feb 2013 09:13:32 +0000 (17:13 +0800)]
style cleanup

This brings the library sources into compliance with checkpatch
style except for three or four exceptions like WIN32 related stuff
and one long string constant I don't want to break into multiple
sprintf calls.

There should be no functional or compilability change from all
this (hopefully).

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agovalgrind openssl destroy as far as possible
Andy Green [Mon, 11 Feb 2013 06:50:45 +0000 (14:50 +0800)]
valgrind openssl destroy as far as possible

OpenSSL doesn't seem to have a way to close out three allocations
it creates during SSL library init.

Even after doing the magic incantations suggested on the openssl list, we're
left with these.  Well, 88 bytes from ssl init is probably not critical,
but it's annoying

==15206== HEAP SUMMARY:
==15206==     in use at exit: 88 bytes in 3 blocks
==15206==   total heap usage: 13,566 allocs, 13,563 frees, 5,933,134 bytes allocated
==15206==
==15206== 24 bytes in 1 blocks are still reachable in loss record 1 of 3
==15206==    at 0x4A06409: malloc (vg_replace_malloc.c:270)
==15206==    by 0x3014C612B2: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1c)
==15206==    by 0x3015441B38: ??? (in /usr/lib64/libssl.so.1.0.1c)
==15206==    by 0x3015443A78: SSL_COMP_get_compression_methods (in /usr/lib64/libssl.so.1.0.1c)
==15206==    by 0x301544932B: SSL_library_init (in /usr/lib64/libssl.so.1.0.1c)
==15206==    by 0x4C340D4: libwebsocket_create_context (libwebsockets.c:1796)
==15206==    by 0x401C08: main (in /usr/bin/libwebsockets-test-server)
==15206==
==15206== 32 bytes in 1 blocks are still reachable in loss record 2 of 3
==15206==    at 0x4A06409: malloc (vg_replace_malloc.c:270)
==15206==    by 0x3014C612B2: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1c)
==15206==    by 0x3014CC91BE: sk_new (in /usr/lib64/libcrypto.so.1.0.1c)
==15206==    by 0x3015441AF9: ??? (in /usr/lib64/libssl.so.1.0.1c)
==15206==    by 0x3015443A78: SSL_COMP_get_compression_methods (in /usr/lib64/libssl.so.1.0.1c)
==15206==    by 0x301544932B: SSL_library_init (in /usr/lib64/libssl.so.1.0.1c)
==15206==    by 0x4C340D4: libwebsocket_create_context (libwebsockets.c:1796)
==15206==    by 0x401C08: main (in /usr/bin/libwebsockets-test-server)
==15206==
==15206== 32 bytes in 1 blocks are still reachable in loss record 3 of 3
==15206==    at 0x4A06409: malloc (vg_replace_malloc.c:270)
==15206==    by 0x3014C612B2: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1c)
==15206==    by 0x3014CC91DC: sk_new (in /usr/lib64/libcrypto.so.1.0.1c)
==15206==    by 0x3015441AF9: ??? (in /usr/lib64/libssl.so.1.0.1c)
==15206==    by 0x3015443A78: SSL_COMP_get_compression_methods (in /usr/lib64/libssl.so.1.0.1c)
==15206==    by 0x301544932B: SSL_library_init (in /usr/lib64/libssl.so.1.0.1c)
==15206==    by 0x4C340D4: libwebsocket_create_context (libwebsockets.c:1796)
==15206==    by 0x401C08: main (in /usr/bin/libwebsockets-test-server)
==15206==
==15206== LEAK SUMMARY:
==15206==    definitely lost: 0 bytes in 0 blocks
==15206==    indirectly lost: 0 bytes in 0 blocks
==15206==      possibly lost: 0 bytes in 0 blocks
==15206==    still reachable: 88 bytes in 3 blocks
==15206==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agovalgrind client close in a controlled way on SIGINT
Andy Green [Mon, 11 Feb 2013 06:32:02 +0000 (14:32 +0800)]
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>
11 years agovalgrind eliminate uninitialized warning on close
Andy Green [Mon, 11 Feb 2013 06:32:48 +0000 (14:32 +0800)]
valgrind eliminate uninitialized warning on close

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agovalgrind also deallocate rx buf on close when client
Andy Green [Mon, 11 Feb 2013 06:12:32 +0000 (14:12 +0800)]
valgrind also deallocate rx buf on close when client

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agovalgrind dont close things directly in the callback
Andy Green [Mon, 11 Feb 2013 06:08:50 +0000 (14:08 +0800)]
valgrind dont close things directly in the callback

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agovalgrind client go through context destroy on connection error
Andy Green [Mon, 11 Feb 2013 06:05:02 +0000 (14:05 +0800)]
valgrind client go through context destroy on connection error

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoclient convert to new headers scheme eliminating mallocs
Andy Green [Mon, 11 Feb 2013 05:04:45 +0000 (13:04 +0800)]
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>
11 years agovalgrind free rx_user_buffer if entered CONNMODE_WS_SERVING
Andy Green [Mon, 11 Feb 2013 04:37:13 +0000 (12:37 +0800)]
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>
11 years agovalgrind introduce protocol init and destroy user callbacks
Andy Green [Mon, 11 Feb 2013 04:05:54 +0000 (12:05 +0800)]
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>
11 years agovalgrind context destroy close all conns properly
Andy Green [Mon, 11 Feb 2013 03:43:05 +0000 (11:43 +0800)]
valgrind context destroy close all conns properly

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agovalgrind drop header allocation down http path
Andy Green [Mon, 11 Feb 2013 03:27:44 +0000 (11:27 +0800)]
valgrind drop header allocation down http path

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoreplace per header mallocs with single malloc 3 level struct
Andy Green [Sun, 10 Feb 2013 10:02:31 +0000 (18:02 +0800)]
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>
11 years agoimprove static allocation notice
Andy Green [Mon, 11 Feb 2013 03:04:56 +0000 (11:04 +0800)]
improve static allocation notice

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agovalgrind free context allocations
Andy Green [Mon, 11 Feb 2013 03:04:01 +0000 (11:04 +0800)]
valgrind free context allocations

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoremove extension cruft from struct lws
Andy Green [Mon, 11 Feb 2013 02:03:00 +0000 (10:03 +0800)]
remove extension cruft from struct lws

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agouse part of service buffer to make response not malloc
Andy Green [Mon, 11 Feb 2013 01:37:23 +0000 (09:37 +0800)]
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>
11 years agoremove minimum frame size for deflate
Andy Green [Mon, 11 Feb 2013 01:32:53 +0000 (09:32 +0800)]
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>
11 years agostop O2 override
Andy Green [Mon, 11 Feb 2013 01:31:43 +0000 (09:31 +0800)]
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>
11 years agodont close in user callback wrapper let ancestor do it
Andy Green [Sun, 10 Feb 2013 13:21:24 +0000 (21:21 +0800)]
dont close in user callback wrapper let ancestor do it

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix error path in file transfer
Andy Green [Sun, 10 Feb 2013 12:58:04 +0000 (20:58 +0800)]
fix error path in file transfer

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agothrow out lws_websocket_related cruft
Andy Green [Sun, 10 Feb 2013 08:25:20 +0000 (16:25 +0800)]
throw out lws_websocket_related cruft

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agooptimize wsi using bitfields and enums to chars
Andy Green [Sun, 10 Feb 2013 08:00:47 +0000 (16:00 +0800)]
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>
11 years agouse context service buffer instead of stack for clent_connect
Andy Green [Sun, 10 Feb 2013 07:34:59 +0000 (15:34 +0800)]
use context service buffer instead of stack for clent_connect

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agouse context service buffer instead of stack for clent_connect_2
Andy Green [Sun, 10 Feb 2013 07:19:39 +0000 (15:19 +0800)]
use context service buffer instead of stack for clent_connect_2

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agouse context service buffer instead of stack for create_context
Andy Green [Sun, 10 Feb 2013 07:10:10 +0000 (15:10 +0800)]
use context service buffer instead of stack for create_context

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix non ssl changes missed from context api change
Andy Green [Sun, 10 Feb 2013 14:22:01 +0000 (22:22 +0800)]
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>
11 years agouse context service buffer instead of stack for lws_client_socket_service
Andy Green [Sun, 10 Feb 2013 03:03:32 +0000 (11:03 +0800)]
use context service buffer instead of stack for lws_client_socket_service

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agouse context service buffer instead of stack for server_socket_service
Andy Green [Sun, 10 Feb 2013 02:43:04 +0000 (10:43 +0800)]
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>
11 years agoadd static stack analysis
Andy Green [Sun, 10 Feb 2013 02:23:24 +0000 (10:23 +0800)]
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>
11 years agodont try figure out listen_service_fd position if unset
Andy Green [Sun, 10 Feb 2013 02:46:45 +0000 (10:46 +0800)]
dont try figure out listen_service_fd position if unset

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agodont try set per socket keepalive timing on bsds
Andy Green [Sun, 10 Feb 2013 01:39:47 +0000 (09:39 +0800)]
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>
11 years agofix broken listen socket piggybacking
Andy Green [Sun, 10 Feb 2013 01:06:38 +0000 (09:06 +0800)]
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>
11 years agointroduce keepalive option and make common socket options function
Andy Green [Sat, 9 Feb 2013 04:25:31 +0000 (12:25 +0800)]
introduce keepalive option and make common socket options function

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoremove receiving timeout for client
Andy Green [Sat, 9 Feb 2013 06:20:17 +0000 (14:20 +0800)]
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>
11 years agocorrect test client to close synchronously with last send
Andy Green [Sat, 9 Feb 2013 06:10:04 +0000 (14:10 +0800)]
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>
11 years agoalign max frame for mirror protocol to what the code does
Andy Green [Sat, 9 Feb 2013 06:07:32 +0000 (14:07 +0800)]
align max frame for mirror protocol to what the code does

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agochange context creation params to struct
Andy Green [Sat, 9 Feb 2013 06:01:09 +0000 (14:01 +0800)]
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>
11 years agohandshake bail3 should be bail
Andy Green [Fri, 8 Feb 2013 12:10:03 +0000 (20:10 +0800)]
handshake bail3 should be bail

Reported-by: Jack Mitchell <ml@communistcode.co.uk>
Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoremove fixed rx buffer allow definition per protocol
Andy Green [Wed, 6 Feb 2013 12:10:16 +0000 (21:10 +0900)]
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>
11 years agoaccount for context in static allocation figure
Andy Green [Fri, 8 Feb 2013 04:53:27 +0000 (12:53 +0800)]
account for context in static allocation figure

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoremove all PATH_MAX or MAX_PATH
Andy Green [Fri, 8 Feb 2013 04:48:36 +0000 (12:48 +0800)]
remove all PATH_MAX or MAX_PATH

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agouse context service buf in place of large stack arrays
Andy Green [Fri, 8 Feb 2013 05:01:02 +0000 (13:01 +0800)]
use context service buf in place of large stack arrays

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoremove need for filepath buffer on http file serve
Andy Green [Mon, 21 Jan 2013 23:20:08 +0000 (07:20 +0800)]
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>
11 years agoadd static linking exception to LICENSE
Andy Green [Thu, 7 Feb 2013 15:44:21 +0000 (23:44 +0800)]
add static linking exception to LICENSE

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd unchanged lgpl 2.1 in LICENSE
Andy Green [Thu, 7 Feb 2013 15:43:56 +0000 (23:43 +0800)]
add unchanged lgpl 2.1 in LICENSE

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoFix memory leaks when creating a context.
Peter Pentchev [Thu, 7 Feb 2013 14:31:19 +0000 (16:31 +0200)]
Fix memory leaks when creating a context.

11 years agoGenerate the API reference in text format, too.
Peter Pentchev [Thu, 7 Feb 2013 14:19:52 +0000 (16:19 +0200)]
Generate the API reference in text format, too.

11 years agoFix two typos.
Peter Pentchev [Thu, 7 Feb 2013 14:17:13 +0000 (16:17 +0200)]
Fix two typos.

11 years agochangelog header lifecycle
Andy Green [Thu, 7 Feb 2013 13:14:33 +0000 (21:14 +0800)]
changelog header lifecycle

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd autotools bits for cyassl
Andy Green [Wed, 6 Feb 2013 06:43:00 +0000 (15:43 +0900)]
add autotools bits for cyassl

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agounionize header token array
Andy Green [Wed, 6 Feb 2013 11:23:40 +0000 (20:23 +0900)]
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>
11 years agodocument header lifecycle change
Andy Green [Wed, 6 Feb 2013 11:13:03 +0000 (20:13 +0900)]
document header lifecycle change

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoheaders deleted after websocket established
Andy Green [Wed, 6 Feb 2013 06:15:25 +0000 (15:15 +0900)]
headers deleted after websocket established

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoleverage TOKEN_SKIPPING better in parser
Andy Green [Mon, 4 Feb 2013 01:24:18 +0000 (09:24 +0800)]
leverage TOKEN_SKIPPING better in parser

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agosimplify parsing complete
Andy Green [Mon, 4 Feb 2013 01:09:19 +0000 (09:09 +0800)]
simplify parsing complete

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoact on fatal parse problems
Andy Green [Mon, 4 Feb 2013 00:55:42 +0000 (08:55 +0800)]
act on fatal parse problems

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoremove deprecated vcxproj
Andy Green [Wed, 6 Feb 2013 11:00:45 +0000 (20:00 +0900)]
remove deprecated vcxproj

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoupdate changelog about cmake
Andy Green [Wed, 6 Feb 2013 10:57:12 +0000 (19:57 +0900)]
update changelog about cmake

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoAdded build instructions for CMake.
Joakim Soderberg [Thu, 7 Feb 2013 12:24:19 +0000 (20:24 +0800)]
Added build instructions for CMake.

Also changed it so that specifying the include directories for CyaSSL is nicer.

11 years agoadd README
Andy Green [Wed, 6 Feb 2013 07:07:27 +0000 (16:07 +0900)]
add README

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoFixed compilation on NetBSD.
Joakim Soderberg [Wed, 6 Feb 2013 06:31:20 +0000 (15:31 +0900)]
Fixed compilation on NetBSD.

11 years agoCleaned up the CyaSSL linking in the CMake project a bit.
Joakim Söderberg [Wed, 6 Feb 2013 06:30:56 +0000 (15:30 +0900)]
Cleaned up the CyaSSL linking in the CMake project a bit.

Separated the CyaSSL linking and OpenSSL linking for more clearity.
Now tested on both OSX and Windows as well.

11 years agoFixed windows build.
Joakim Soderberg [Wed, 6 Feb 2013 06:30:33 +0000 (15:30 +0900)]
Fixed windows build.

- Fixed the original visual studio project so that inline gets defined.
- Fix error in CMake with zlib.

11 years agoAdded some minor changes to CMake build file.
Joakim Soderberg [Wed, 6 Feb 2013 06:29:59 +0000 (15:29 +0900)]
Added some minor changes to CMake build file.

- Added options for compiling without server/client parts.
- Fixed a syntax error on printing an error on CyaSSL compilation.
- Don't compile server-extpoll either when the server isn't compiled.

11 years agoAdded support for CyaSSL replacement of OpenSSL.
Joakim Soderberg [Wed, 6 Feb 2013 06:29:18 +0000 (15:29 +0900)]
Added support for CyaSSL replacement of OpenSSL.

http://www.yassl.com/yaSSL/Products-cyassl.html
- Small Size: 20-100kB
- Runtime Memory:  1-36kB
- 20X smaller than OpenSSL

So far only tested on Linux.

Note that this requires a bugfix in cyassl, otherwise it will crash. Pull request has been made to the official repos, in the meantime the following repos can be used: git://github.com/JoakimSoderberg/cyassl.git

11 years agoAdded check for inline keyword availability.
Joakim Soderberg [Wed, 6 Feb 2013 06:28:07 +0000 (15:28 +0900)]
Added check for inline keyword availability.

Both to CMake project and Autoconf. inline will be defined to whatever inline replacement exists on the system, such as __inline or __inline__

11 years agoFixed build on OSX.
Joakim Söderberg [Wed, 6 Feb 2013 06:27:39 +0000 (15:27 +0900)]
Fixed build on OSX.

- For some reason the "extern int pid_daemon" usage in libwebsockets.c would cause an "undefined symbols" linker error for the test-apps. This only happens with the CMake project, not the normal Makefiles. I have no clue why this is. Fixed it by getting the pid via a function instead.

- Added test-server-extpoll

- Renamed the library from libwebsocket -> libwebsockets

11 years agoFixed linux compilation and added more compile options.
Joakim Soderberg [Wed, 6 Feb 2013 06:27:27 +0000 (15:27 +0900)]
Fixed linux compilation and added more compile options.

- Tested and works on Linux now also, including SSL support.
- Look for ZLIB not zlib.
- Added CMake options for setting all LWS_ defines.

11 years agoCMake support + fixed windows build.
Joakim Soderberg [Wed, 6 Feb 2013 06:26:58 +0000 (15:26 +0900)]
CMake support + fixed windows build.
- Finalized CMake support (tested on windows only so far).
  - Uses a generated lws_config.h that is included in
  private-libwebsocket to pass defines, only used if CMAKE_BUILD is set.
  - Support for SSL on Windows.
  - Initial support for CyaSSL replacement of OpenSSL (This has been added
    to my older CMake-fork but haven't been tested on this version yet).
- Fixed windows build (see below for details).
- Fixed at least the 32-bit Debug build for the existing Visual Studio
  Project. (Not to keen fixing all the others when we have CMake support
  anyway (which can generate much better project files)...)
- BUGFIXES:
  - handshake.c
    - used C99 definition of handshake_0405 function
  - libwebsocket.c
    - syslog not available on windows, put in ifdefs.
    - Fixed previous known crash bug on Windows where WSAPoll in
      Ws2_32.dll would not be present, causing the poll function pointer
      being set to NULL.
    - Uninitialized variable context->listen_service_extraseen would
      result in stack overflow because of infinite recursion. Fixed by
      initializing in libwebsocket_create_context
    - SO_REUSADDR means something different on Windows compared to Unix.
    - Setting a socket to nonblocking is done differently on Windows.
      (This should probably broken out into a helper function instead)
    - lwsl_emit_syslog -> lwsl_emit_stderr on Windows.
  - private-libwebsocket.h
    - PATH_MAX is not available on Windows, define as MAX_PATH
    - Always define LWS_NO_DAEMONIZE on windows.
    - Don't define lws_latency as inline that does nothing. inline is not
      support by the Microsoft compiler, replaced with an empty define
      instead. (It's __inline in MSVC)
  - server.c
    - Fixed nonblock call on windows
  - test-ping.c
    - Don't use C99 features (Microsoft compiler does not support it).
    - Move non-win32 headers into ifdefs.
    - Skip use of sighandler on Windows.
  - test-server.c
    - ifdef syslog parts on Windows.

11 years agoSome more Cmake stuff.
Joakim Soderberg [Wed, 6 Feb 2013 06:25:26 +0000 (15:25 +0900)]
Some more Cmake stuff.

11 years agoStarted redoing CMake support based on the up to date repos
Joakim Soderberg [Fri, 1 Feb 2013 13:52:53 +0000 (14:52 +0100)]
Started redoing CMake support based on the up to date repos

11 years agoimprove test server poll loop docs
Andy Green [Sat, 2 Feb 2013 15:02:56 +0000 (23:02 +0800)]
improve test server poll loop docs

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd note about MIPS opewrt configure options
Andy Green [Sat, 2 Feb 2013 10:10:29 +0000 (18:10 +0800)]
add note about MIPS opewrt configure options

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoremove one more mention of broadcast callback
Andy Green [Fri, 1 Feb 2013 03:17:02 +0000 (11:17 +0800)]
remove one more mention of broadcast callback

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agointroduce library version plus git hash
Andy Green [Fri, 1 Feb 2013 02:50:15 +0000 (10:50 +0800)]
introduce library version plus git hash

This exposes the library version and git head hash it was built from
into LWS_LIBRARY_VERSION and LWS_BUILD_HASH.

These are combined into a version string that's both printed as a
notice log by the library and made available to the app using a new
api lws_get_library_version().  The version looks like

 1.1 178d78c

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoremove stray reference to max broadcast size from readme.build
Andy Green [Fri, 1 Feb 2013 00:48:41 +0000 (08:48 +0800)]
remove stray reference to max broadcast size from readme.build

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadditional casts allow test server build as cpp
Andy Green [Fri, 1 Feb 2013 00:42:15 +0000 (08:42 +0800)]
additional casts allow test server build as cpp

With these explicit casts that are not needed in C, it's possible to build
the test server using g++ like this, after building and installing the
library.

g++ -DINSTALL_DATADIR=\"/usr/share\" -ocpptest test.cpp -lwebsockets

Add a small documentation to README.coding

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoupdate changelog tag chrome 26 firefox 18
Andy Green [Thu, 31 Jan 2013 11:53:05 +0000 (19:53 +0800)]
update changelog tag chrome 26 firefox 18

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agorenovate test html
Andy Green [Thu, 31 Jan 2013 11:50:57 +0000 (19:50 +0800)]
renovate test html

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd changelog v1.0 to v1.1
Andy Green [Thu, 31 Jan 2013 02:16:44 +0000 (10:16 +0800)]
add changelog v1.0 to v1.1

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agobump version to 1.1 and soname to 2
Andy Green [Thu, 31 Jan 2013 02:12:52 +0000 (10:12 +0800)]
bump version to 1.1 and soname to 2

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoclean out remaining mentions of deprecated broadcast
Andy Green [Thu, 31 Jan 2013 02:34:52 +0000 (10:34 +0800)]
clean out remaining mentions of deprecated broadcast

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoget error from getnameinfo if unable to improve hostname and use hostname
Andy Green [Thu, 31 Jan 2013 02:05:43 +0000 (10:05 +0800)]
get error from getnameinfo if unable to improve hostname and use hostname

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofixes for without server and without client
Andy Green [Thu, 31 Jan 2013 01:57:05 +0000 (09:57 +0800)]
fixes for without server and without client

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix unused var if no enable openssl
Jack Mitchell [Wed, 30 Jan 2013 10:53:36 +0000 (18:53 +0800)]
fix unused var if no enable openssl

Signed-off-by: Jack Mitchell <ml@communistcode.co.uk>
11 years agointroduce test echo
Andy Green [Wed, 30 Jan 2013 03:03:01 +0000 (11:03 +0800)]
introduce test echo

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd info about why we close to more places
Andy Green [Wed, 30 Jan 2013 04:28:34 +0000 (12:28 +0800)]
add info about why we close to more places

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoroubustness handle problems in read loop better
Andy Green [Wed, 30 Jan 2013 04:27:27 +0000 (12:27 +0800)]
roubustness handle problems in read loop better

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoserver allow NULL protocol map to protocol 0
Andy Green [Wed, 30 Jan 2013 04:26:14 +0000 (12:26 +0800)]
server allow NULL protocol map to protocol 0

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