handshake bail3 should be bail

Reported-by: Jack Mitchell <ml@communistcode.co.uk>
Signed-off-by: Andy Green <andy.green@linaro.org>
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>
align max frame for mirror protocol to what the code does

Signed-off-by: Andy Green <andy.green@linaro.org>
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>
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>
introduce keepalive option and make common socket options function

Signed-off-by: Andy Green <andy.green@linaro.org>
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>
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>
dont try figure out listen_service_fd position if unset

Signed-off-by: Andy Green <andy.green@linaro.org>
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>
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>
use context service buffer instead of stack for lws_client_socket_service

Signed-off-by: Andy Green <andy.green@linaro.org>
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>
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>