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>
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>
add libwebsockets.org logo to share

Signed-off-by: Andy Green <andy.green@linaro.org>
update test server html serving callback to use aepd whitelist approach

Signed-off-by: Andy Green <andy.green@linaro.org>
add logo to test file

Signed-off-by: Andy Green <andy.green@linaro.org>
workaround for some gcc array bounds false positive

Signed-off-by: Andy Green <andy.green@linaro.org>
robustness server dont exit server on accept problems

Error message corrected to %s as well

Signed-off-by: Andy Green <andy.green@linaro.org>
add new context arg to libwebsockets_serve_http_file

Signed-off-by: Andy Green <andy.green@linaro.org>
refactor migrate client stuff to client.c

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

Signed-off-by: Andy Green <andy.green@linaro.org>
test client remove usleep

Whatever caused the need for this has gone away

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

Signed-off-by: Andy Green <andy.green@linaro.org>
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>
move array bounds gcc workaround outside function

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