profile/ivi/libwebsockets.git
11 years agoCMake support + fixed windows build. 02/3002/1
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. 01/3001/1
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 00/3000/1
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 99/2999/1
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 98/2998/1
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 97/2997/1
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 96/2996/1
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 95/2995/1
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 94/2994/1
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 93/2993/1
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 92/2992/1
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 91/2991/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 90/2990/1
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 89/2989/1
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 88/2988/1
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 87/2987/1
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 86/2986/1
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 85/2985/1
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 84/2984/1
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 83/2983/1
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 82/2982/1
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>
11 years agochange get_peer_addresses to use context wsi latency 81/2981/1
Andy Green [Wed, 30 Jan 2013 00:12:20 +0000 (08:12 +0800)]
change get_peer_addresses to use context wsi latency

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoinstrument latency 80/2980/1
Andy Green [Tue, 29 Jan 2013 04:37:35 +0000 (12:37 +0800)]
instrument latency

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agointroduce lws_latency 79/2979/1
Andy Green [Tue, 29 Jan 2013 04:36:17 +0000 (12:36 +0800)]
introduce lws_latency

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix docs about protocol version supported 78/2978/1
Andy Green [Wed, 30 Jan 2013 00:31:43 +0000 (08:31 +0800)]
fix docs about protocol version supported

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agotest server terminate cleanly on ctrl c 77/2977/1
Andy Green [Wed, 30 Jan 2013 00:02:26 +0000 (08:02 +0800)]
test server terminate cleanly on ctrl c

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoevict all broadcast support 76/2976/1
Andy Green [Tue, 29 Jan 2013 09:57:39 +0000 (17:57 +0800)]
evict all broadcast support

Libwebsockets is fundamentally singlethreaded... the existence of the
fork and broadcast support, especially in the sample server is
giving the wrong idea about how to use it.

This replaces broadcast in the sample server with
libwebsocket_callback_on_writable_all_protocol().  The whole idea of
'broadcast' is removed.

All of the broadcast proxy stuff is removed: data must now be sent
from the callback only.  Doing othherwise is not reliable since the
service loop may close the socket and free the wsi at any time,
invalidating a wsi pointer held by another thread (don't do that!)

Likewise the confirm_legit_wsi api added recently does not help the
other thread case, since if the wsi has been freed dereferencing the
wsi to study if it is legit or not will segfault in that case.  So
this is removed too.

The overall effect is to push user code to only operate inside the
protocol callbacks or external poll loops, ie, single thread context.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoFreeBSD compatibility 75/2975/1
Matthieu Riviere [Mon, 28 Jan 2013 22:57:21 +0000 (06:57 +0800)]
FreeBSD compatibility

Seems we just need to take care about __FreeBSD__ along with
__APPLE__ in a couple of places.

Signed-off-by: Matthieu Riviere <matthieu.riviere@leukensis.org>
11 years agotrac 6 expose libwebsockets read with note about not normally needed 74/2974/1
Andy Green [Mon, 28 Jan 2013 22:52:00 +0000 (06:52 +0800)]
trac 6 expose libwebsockets read with note about not normally needed

Comes in handy if the original application poll loop is the boss,
in this case libwebsockets is optional and can't be the boss poll
loop

Requested-by: ajandhyala@wms.com
Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix ssl bits outside of ifdef coverage 73/2973/1
Edwin van den Oetelaar [Mon, 28 Jan 2013 13:53:53 +0000 (21:53 +0800)]
fix ssl bits outside of ifdef coverage

Signed-off-by: Edwin van den Oetelaar <oetelaar.automatisering@gmail.com>
11 years agoforce client ssl bio nonblocking 72/2972/1
Andy Green [Mon, 28 Jan 2013 09:48:21 +0000 (17:48 +0800)]
force client ssl bio nonblocking

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoforce ssl rw bios nonblocking 71/2971/1
Andy Green [Mon, 28 Jan 2013 09:45:34 +0000 (17:45 +0800)]
force ssl rw bios nonblocking

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agotimeout coverage for ssl accept 70/2970/1
Andy Green [Mon, 28 Jan 2013 09:20:41 +0000 (17:20 +0800)]
timeout coverage for ssl accept

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agobreak up ssl accept action 69/2969/1
Andy Green [Mon, 28 Jan 2013 04:19:10 +0000 (12:19 +0800)]
break up ssl accept action

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoensure accept is nonblocking 68/2968/1
Andy Green [Mon, 28 Jan 2013 03:23:52 +0000 (11:23 +0800)]
ensure accept is nonblocking

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoautocreate foreign broadcast sockets on broadcast 67/2967/1
Andy Green [Fri, 25 Jan 2013 09:34:15 +0000 (17:34 +0800)]
autocreate foreign broadcast sockets on broadcast

Also introduce libwebsockets_broadcast_foreign() separate from libwebsockets_broadcast()

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agotrac 5 sa_restorer deprecated 66/2966/1
Andy Green [Wed, 23 Jan 2013 00:32:03 +0000 (08:32 +0800)]
trac 5 sa_restorer deprecated

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agotrac 3 document write and context_user 65/2965/1
Andy Green [Tue, 22 Jan 2013 04:40:35 +0000 (12:40 +0800)]
trac 3 document write and context_user

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agotrac 4 correct libebsocket_service_fd 64/2964/1
Andy Green [Tue, 22 Jan 2013 04:32:11 +0000 (12:32 +0800)]
trac 4 correct libebsocket_service_fd

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoupdate numbers for minimal build footprint 63/2963/1
Andy Green [Mon, 21 Jan 2013 05:20:33 +0000 (13:20 +0800)]
update numbers for minimal build footprint

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agomore LWS_NO_DAEMONIZE 62/2962/1
Andy Green [Mon, 21 Jan 2013 05:06:38 +0000 (13:06 +0800)]
more LWS_NO_DAEMONIZE

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agouse correct LWS_NO_DAEMONIZE on test server 61/2961/1
Andy Green [Mon, 21 Jan 2013 04:58:04 +0000 (12:58 +0800)]
use correct LWS_NO_DAEMONIZE on test server

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agobind gcc debug generation to_DEBUG 60/2960/1
Andy Green [Mon, 21 Jan 2013 04:19:30 +0000 (12:19 +0800)]
bind gcc debug generation to_DEBUG

Either generate debug sections in output or optimize aggressively,
controlled by the existing --disable-debug

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agounionize mutually exclusive wsi members 59/2959/1
Andy Green [Mon, 21 Jan 2013 03:04:23 +0000 (11:04 +0800)]
unionize mutually exclusive wsi members

Large chunks of struct libwebsocket members actually have a mutually
exclusive lifecycle, eg, once the http headers are finished they sit
there unused until the instance is destroyed.

This makes a big improvement in memory efficiency by making four
categories of member: always needed, needed for header processing,
needed for http processing, and needed for ws processing.  The last
three are mutually exclusive and bound into a union inside the wsi.

Care needs taking now at "union transitions", although we zeroed down
the struct at init, the other union siblings have been writing the
same memory by the time later member siblings start to use it.  So
it must be cleared down appropriately when we cross from one
mutually-exclusive use to another.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agokey_b64 doesnt need to be in wsi 58/2958/1
Andy Green [Mon, 21 Jan 2013 03:04:49 +0000 (11:04 +0800)]
key_b64 doesnt need to be in wsi

It's only used in some client code and never seen again

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoavoid PATH_MAX in bss in daemonize 57/2957/1
Andy Green [Mon, 21 Jan 2013 02:36:12 +0000 (10:36 +0800)]
avoid PATH_MAX in bss in daemonize

PATH_MAX is typically 4KB, let's malloc space for the
actual path instead and just have the pointer in bss

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoremove all support for pre v13 protocols 56/2956/1
Andy Green [Mon, 21 Jan 2013 01:53:35 +0000 (09:53 +0800)]
remove all support for pre v13 protocols

Since v13 was defined as the released ietf version the older versions
are deprecated.  This patch strips out everything to do with the older
versions and gets rid of the option to send stuff unmasked.

The in-tree md5 implementation is then also deleted as nothing needs
it any more, 1280 loc are shed in all

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agodisable private broadcast sockets if enable no fork config option 55/2955/1
Andy Green [Mon, 21 Jan 2013 01:09:52 +0000 (09:09 +0800)]
disable private broadcast sockets if enable no fork config option

The whole thing about count_protocols + 1 broadcast sockets and
associated dummy wsis is a workaround for getting a broadcast from
a different process context, if we are running with --enable-no-fork
then we don't need any of it in.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoalign test server extpoll with library dynamic approach 54/2954/1
Edwin van den Oetelaar [Sun, 20 Jan 2013 12:51:14 +0000 (20:51 +0800)]
align test server extpoll with library dynamic approach

Signed-off-by: Edwin van den Oetelaar <oetelaar.automatisering@gmail.com>
11 years agodocument memory efficiency 53/2953/1
Andy Green [Sun, 20 Jan 2013 12:14:42 +0000 (20:14 +0800)]
document memory efficiency

This puts some numbers of library size with the various --without
and --disable options and about dynamic memory allocation
performance

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agolog major dynamic allocation info 52/2952/1
Andy Green [Sun, 20 Jan 2013 12:21:54 +0000 (20:21 +0800)]
log major dynamic allocation info

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agozlib not needed if no extensions 51/2951/1
Andy Green [Sun, 20 Jan 2013 10:26:20 +0000 (18:26 +0800)]
zlib not needed if no extensions

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agointroduce without extensions 50/2950/1
Andy Green [Sun, 20 Jan 2013 09:08:31 +0000 (17:08 +0800)]
introduce without extensions

The new --without-extensions config flag completely removes all code
and data related to extensions from the build throughout the library
when given.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agorefactor README 49/2949/1
Andy Green [Sun, 20 Jan 2013 03:28:06 +0000 (11:28 +0800)]
refactor README

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agosyslog requires format string 48/2948/1
Edwin van den Oetelaar [Sat, 19 Jan 2013 12:01:01 +0000 (20:01 +0800)]
syslog requires format string

Signed-off-by: Edwin van den Oetelaar <oetelaar.automatisering@gmail.com>
11 years agorevert zlib update 1.2.7 47/2947/1
Andy Green [Sat, 19 Jan 2013 07:11:23 +0000 (15:11 +0800)]
revert zlib update 1.2.7

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agomake use of lock file 46/2946/1
Andy Green [Sat, 19 Jan 2013 05:56:10 +0000 (13:56 +0800)]
make use of lock file

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agowindows compatibility changes for private libwebsockets 45/2945/1
FNA [Sat, 19 Jan 2013 05:58:06 +0000 (13:58 +0800)]
windows compatibility changes for private libwebsockets

Signed-off-by: FNA <aqiruse@gmail.com>
11 years agotest server add daemonization flag 44/2944/1
Andy Green [Sat, 19 Jan 2013 03:11:42 +0000 (11:11 +0800)]
test server add daemonization flag

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agotest server use syslog logging 43/2943/1
Andy Green [Sat, 19 Jan 2013 03:32:18 +0000 (11:32 +0800)]
test server use syslog logging

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoallow_use_of_lwsl_logging in user code 42/2942/1
Andy Green [Sat, 19 Jan 2013 03:58:07 +0000 (11:58 +0800)]
allow_use_of_lwsl_logging in user code

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agohelper api: log through syslog 41/2941/1
Andy Green [Sat, 19 Jan 2013 03:12:16 +0000 (11:12 +0800)]
helper api:  log through syslog

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agologging select some lwsl_info usage to be lwsl_notice 40/2940/1
Andy Green [Sat, 19 Jan 2013 05:08:17 +0000 (13:08 +0800)]
logging select some lwsl_info usage to be lwsl_notice

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd lwsl_notice 39/2939/1
Andy Green [Sat, 19 Jan 2013 04:18:07 +0000 (12:18 +0800)]
add lwsl_notice

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoexpose log level in emit 38/2938/1
Andy Green [Sat, 19 Jan 2013 03:17:56 +0000 (11:17 +0800)]
expose log level in emit

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agochange bitfield setting to avoid gcc warnings 37/2937/1
Andy Green [Sat, 19 Jan 2013 03:52:06 +0000 (11:52 +0800)]
change bitfield setting to avoid gcc warnings

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoimprove frame_is_binary setting 36/2936/1
Andy Green [Sat, 19 Jan 2013 02:39:35 +0000 (10:39 +0800)]
improve frame_is_binary setting

Gregory Junker <ggjunker@gmail.com> noticed the binary flag is not
getting set right, or at all on client side.  This should improve
matters.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd lws_confirm_legit_wsi 35/2935/1
Andy Green [Fri, 18 Jan 2013 14:00:22 +0000 (22:00 +0800)]
add lws_confirm_legit_wsi

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agorefactor and introduce without server configure option 34/2934/1
Andy Green [Fri, 18 Jan 2013 03:43:21 +0000 (11:43 +0800)]
refactor and introduce without server configure option

Move server-only stuff into their own files and make building
that depend on not having --without-server on the configure

Make fragments in other places conditional as well

Remove client-related members from struct libwebscket when
building LWS_NO_CLIENT

Apps:

normal: build test server, client, fraggle, ping
--without-client: build test server
--without-server: build test client, ping

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agointrodice tracking if frame is binary 33/2933/1
Andy Green [Fri, 18 Jan 2013 01:49:20 +0000 (09:49 +0800)]
introdice tracking if frame is binary

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agodifferent compiler warning fixes 32/2932/1
Edwin van den Oetelaar [Fri, 18 Jan 2013 01:20:54 +0000 (09:20 +0800)]
different compiler warning fixes

Solve some unchecked return codes in the new daemonization file

AG adapted a bit

Signed-off-by: Edwin van den Oetelaar <oetelaar.automatisering@gmail.com>
Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd lexical parser for headers 31/2931/1
Andy Green [Thu, 17 Jan 2013 17:55:48 +0000 (01:55 +0800)]
add lexical parser for headers

Profiling what happens during the ab test, one of the hotspots
was strcasecmp in a loop looking for header name matches each time.

This patch introduces a lexical parser that creates a state machine
in 276 bytes that encodes all the known header names.  The fsm is
walked bytewise as chaacters come in... most states do not need any
recursion to match or fail.

The state machine output is cut-and-pasted into parsers.c as an
unsigned char array.

The fsm generator is a bit rough and ready, included in the tree but
not built since normal mortals won't need to touch it.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agodeprecate x google mux 30/2930/1
Andy Green [Thu, 17 Jan 2013 11:53:16 +0000 (19:53 +0800)]
deprecate x google mux

Unfortunately this code is beginning to rot due to lack of demand to
provide it and it being disabled by default.

If demand appears we can revert this and resume work on it, otherwise
let's bite the bullet for the moment.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agosolve flowcontrol problems 29/2929/1
Andy Green [Thu, 17 Jan 2013 08:50:35 +0000 (16:50 +0800)]
solve flowcontrol problems

Problems with rx flow control implementation were the underlying cause
of the connection stalling issue that was covered up with the udelay()
patch that was removed recently.

This get rx flow control working properly and corrects problems with
fifo management in the test server mirror protocol code too.

The rxfow control api has been changed to just set a flag, so it's very cheap
to call from user code.  After the callbacks that might use the rxflow control
api the flag is checked and any pending actions done.

rx flow control now stops any rx packet coming immediately, with compessed
connections "just what was left in the pipe" might be hundreds of KBytes.  To
implement that the current packet being decoded is copied into a malloc'd buffer
by the rx processing code now.

When rxflow is allows to come again, the buffer is drained and freed before any
new packet content is accepted.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agocheck errors on shutdown close 28/2928/1
Andy Green [Thu, 17 Jan 2013 06:46:43 +0000 (14:46 +0800)]
check errors on shutdown close

Also make sure CLOSE doesn't go through extension munging

Reduce wait for close ack to 1s

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoreplace hashtable polltable management 27/2927/1
Andy Green [Thu, 17 Jan 2013 04:26:48 +0000 (12:26 +0800)]
replace hashtable polltable management

This rips out the connection hashtable implementation along with
MAX_CLIENTS and replaces it with a dynamically allocated fds array
and lookup table along the same lines as the new extpoll implementation
from Edwin van den Oetelaar.

It detects the max number of file descriptors possible at context init
time and allocates accordingly; this can be externally controlled by
ulimit and the server run as a specific user to facilitate targeting
specific ulimit rules at it.

Many operations that translated between socket descriptors and struct
websocket or pollfd objects have had iteration removed by this patch
and under load will be a lot faster.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agouse simple lookup table for extpoll 26/2926/1
Edwin van der Oetelaar [Thu, 17 Jan 2013 03:16:15 +0000 (11:16 +0800)]
use simple lookup table for extpoll

Hash stuff is overkill since Edwin found a max connection limit of 30000 on his
box anyway.  Just use a simple preallocated lookup table and fds array.

AG Modified for style and removed debugging bits

Signed-off-by: Edwin van der Oetelaar <oetelaar.automatisering@gmail.com>
Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoinclude daemonization file whoops 25/2925/1
Andy Green [Thu, 17 Jan 2013 07:49:27 +0000 (15:49 +0800)]
include daemonization file whoops

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoportability dont assume size of tv.t_usec 24/2924/1
Andy Green [Thu, 17 Jan 2013 07:02:02 +0000 (15:02 +0800)]
portability dont assume size of tv.t_usec

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd disable debug to README configuration options list 23/2923/1
Andy Green [Thu, 17 Jan 2013 02:15:52 +0000 (10:15 +0800)]
add disable debug to README configuration options list

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoincluding assert h needed on osx 22/2922/1
Peter Young [Thu, 17 Jan 2013 02:10:10 +0000 (10:10 +0800)]
including assert h needed on osx

Signed-off-by: Peter Young <young40@qq.com>
11 years agojust use limits.h directly 21/2921/1
Peter Young [Thu, 17 Jan 2013 02:08:16 +0000 (10:08 +0800)]
just use limits.h directly

Signed-off-by: Peter Young <young40@qq.com>
11 years agointroduce daemonize 20/2920/1
Andy Green [Thu, 17 Jan 2013 02:05:39 +0000 (10:05 +0800)]
introduce daemonize

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoclient allow remote server to accept with no protocol set 19/2919/1
Andy Green [Wed, 16 Jan 2013 16:50:48 +0000 (00:50 +0800)]
client allow remote server to accept with no protocol set

Needed if our clientside can connect to, eg, echo.websocket.org

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agomove array bounds gcc workaround outside function 18/2918/1
Andy Green [Wed, 16 Jan 2013 09:46:00 +0000 (17:46 +0800)]
move array bounds gcc workaround outside function

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoupdate ping test client and stop exposing payload to extensions 17/2917/1
Andy Green [Wed, 16 Jan 2013 06:35:12 +0000 (14:35 +0800)]
update ping test client and stop exposing payload to extensions

Ping and Pong payload in control messages need to be
above the fray of extension payload munging

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoexport lswl_hexdump 16/2916/1
Andy Green [Wed, 16 Jan 2013 06:35:27 +0000 (14:35 +0800)]
export lswl_hexdump

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoroubustness only return 0 from fd service if handled 15/2915/1
Andy Green [Wed, 16 Jan 2013 05:40:43 +0000 (13:40 +0800)]
roubustness only return 0 from fd service if handled

Otherwise our app outer loop will think the world is ending

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoconfigure without client 14/2914/1
Andy Green [Wed, 16 Jan 2013 03:47:40 +0000 (11:47 +0800)]
configure without client

This leverages the refactor patches to introduce the ability to
disable building any client side code in the library or the client
side test apps.

This will be a considerable size saving for embedded server-only
case.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agotest client remove usleep 13/2913/1
Andy Green [Wed, 16 Jan 2013 04:32:20 +0000 (12:32 +0800)]
test client remove usleep

Whatever caused the need for this has gone away

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agorefactor output.c 12/2912/1
Andy Green [Wed, 16 Jan 2013 04:21:29 +0000 (12:21 +0800)]
refactor output.c

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agorefactor migrate client stuff to client.c 11/2911/1
Andy Green [Wed, 16 Jan 2013 03:53:05 +0000 (11:53 +0800)]
refactor migrate client stuff to client.c

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd new context arg to libwebsockets_serve_http_file 10/2910/1
Andy Green [Wed, 16 Jan 2013 03:45:38 +0000 (11:45 +0800)]
add new context arg to libwebsockets_serve_http_file

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agorobustness server dont exit server on accept problems 09/2909/1
Andy Green [Wed, 16 Jan 2013 03:43:53 +0000 (11:43 +0800)]
robustness server dont exit server on accept problems

Error message corrected to %s as well

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoworkaround for some gcc array bounds false positive 08/2908/1
Andy Green [Wed, 16 Jan 2013 02:21:34 +0000 (10:21 +0800)]
workaround for some gcc array bounds false positive

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd logo to test file 07/2907/1
Andy Green [Wed, 16 Jan 2013 02:11:34 +0000 (10:11 +0800)]
add logo to test file

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoupdate test server html serving callback to use aepd whitelist approach 06/2906/1
Andy Green [Wed, 16 Jan 2013 02:06:28 +0000 (10:06 +0800)]
update test server html serving callback to use aepd whitelist approach

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd libwebsockets.org logo to share 05/2905/1
Andy Green [Wed, 16 Jan 2013 02:00:39 +0000 (10:00 +0800)]
add libwebsockets.org logo to share

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agooptimize http file sending 04/2904/1
Andy Green [Wed, 16 Jan 2013 00:37:48 +0000 (08:37 +0800)]
optimize http file sending

This adapts the approach from the single-packet-per-poll-loop improvement
to sending more packets while the socket can take them.

It still falls back to the multi-state scheme if the socket ever chokes,
which it certainly will on larger files, so it's safe while being highly
efficient at smaller file sizes.

Nor should it significantly add to latency for other sockets, it simply
stuffs the pipe asynchronously as much as the pipe can take.

We also increase the packet payoad size from 512 to 1400 a time.

This reduces the time taken in the 300 connection / 5000 transfers ab test
from >8s to ~3.4s, transferring the same amount of data.

$ ab -t 100 -n 5000 -c 300 'http://127.0.0.1:7681/'
This is ApacheBench, Version 2.3 <$Revision: 1373084 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests

Server Software:        libwebsockets
Server Hostname:        127.0.0.1
Server Port:            7681

Document Path:          /
Document Length:        8447 bytes

Concurrency Level:      300
Time taken for tests:   3.400 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      42680000 bytes
HTML transferred:       42235000 bytes
Requests per second:    1470.76 [#/sec] (mean)
Time per request:       203.976 [ms] (mean)
Time per request:       0.680 [ms] (mean, across all concurrent requests)
Transfer rate:          12260.17 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        7   24  15.6     20     125
Processing:    32  172  50.2    161     407
Waiting:       27  154  49.4    142     386
Total:         81  196  48.3    182     428

Percentage of the requests served within a certain time (ms)
  50%    182
  66%    185
  75%    188
  80%    194
  90%    304
  95%    316
  98%    322
  99%    328
 100%    428 (longest request)

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agolisten socket more frequent service 03/2903/1
Andy Green [Tue, 15 Jan 2013 23:59:47 +0000 (07:59 +0800)]
listen socket more frequent service

From an idea by Edwin van den Oetelaar <oetelaar.automatisering@gmail.com>

When testing libwebsockets with ab, Edwin found an unexpected bump in
the distribution of latencies, some connections were held back almost
the whole test duration.

http://ml.libwebsockets.org/pipermail/libwebsockets/2013-January/000006.html

Studying the problem revealed that when there are mass pending connections
amongst many active connections, we do not service the listen socket often
enough to clear the backlog, some seem to get stale violating FIFO ordering.

This patch introduces listen socket service "piggybacking", where every n
normal socket service actions we also check the listen socket and deal with
pending connections there.

Normally, it checks the listen socket gratuitously every 10 normal socket
services.  However, if it finds something waiting, it forces a check on the
next normal socket service too by keeping stats on how often something was
waiting.  If the probability of something waiting each time becomes high,
it will allow up to two waiting connections to be serviced for each normal
socket service.

In that way it has low burden in the normal case, but rapidly adapts by
detecting mass connection loads as found in ab.

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