profile/ivi/libwebsockets.git
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>
11 years agoadd empty m4 dir as workaround for autoreconf issue 02/2902/1
Andy Green [Tue, 15 Jan 2013 13:56:12 +0000 (21:56 +0800)]
add empty m4 dir as workaround for autoreconf issue

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoallow LWS_SOMAXCONN to be defined at configuretime 01/2901/1
Andy Green [Tue, 15 Jan 2013 12:52:29 +0000 (20:52 +0800)]
allow LWS_SOMAXCONN to be defined at configuretime

Default remains at SOMAXCONN, you can force it at configure time
along these lines

./configure CFLAGS="-DLWS_SOMAXCONN=16384"

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoextpoll use hashtable for fd tracking 00/2900/1
Andy Green [Tue, 15 Jan 2013 11:44:33 +0000 (19:44 +0800)]
extpoll use hashtable for fd tracking

This implements a much faster, hashtable-based tracking scheme for
external poll fds.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoallow building just the library not the testapps 99/2899/1
Andy Green [Tue, 15 Jan 2013 11:57:06 +0000 (19:57 +0800)]
allow building just the library not the testapps

From an idea by Jack Mitchell <ml@communistcode.co.uk>

Use --without-testapps at configure time to suppress building them

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agomake sure we have PATH_MAX on some linux toolchains 98/2898/1
Jack Mitchell [Tue, 15 Jan 2013 11:49:05 +0000 (19:49 +0800)]
make sure we have PATH_MAX on some linux toolchains
(AG modified a bit)

Signed-off-by: Jack Mitchell <ml@communistcode.co.uk>
11 years agoextpoll break out of loop when set or clear finds fd 97/2897/1
Edwin van der Oetelaar [Tue, 15 Jan 2013 08:22:34 +0000 (16:22 +0800)]
extpoll break out of loop when set or clear finds fd

Signed-off-by: Edwin van der Oetelaar <oetelaar.automatisering@gmail.com>
11 years agohttp service break into outer loop states 96/2896/1
Andy Green [Tue, 15 Jan 2013 05:40:23 +0000 (13:40 +0800)]
http service break into outer loop states

Previously we sat and looped to dump a file over http protocol.

Actually that's a source of blocking to the other sockets being serviced.

This patch breaks up the file service into a roundtrip around the poll()
loop for each 512-byte packet.  It doesn't make much difference if the
server is idle, but if it's busy it makes sure everyone else is getting
service while the file is sent.

It doesn't try to optimize multiple users of the file or to keep the
descriptor open, the point of this patch is to establish the breaking up
of the file send action into the poll loop.

On the user side, there are two differences:

 - context is now needed in the first argument to libwebsockets_serve_http_file()
that's not too bad since we provide context in the callback.

 - file send is now asynchronous to the user code, you get a new callback coming
in protocol 0 when it's done, LWS_CALLBACK_HTTP_FILE_COMPLETION

libwebsockets-test-server is updated accordingly.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agomerge test server extpoll into test server 95/2895/1
Andy Green [Tue, 15 Jan 2013 04:39:48 +0000 (12:39 +0800)]
merge test server extpoll into test server

the -extpoll version of the test server was starting to rot compared to
the test-server.c it was originally based on.

This patch deletes the -extpoll.c version and instead has the test-server.c
source built two different ways in the makefile, once with the define
EXTERNAL_POLL which forces non-fork mode and enables the "by hand"
pollfd array handling.  The resulting binary of that is still called
libwebsockets-test-server-extpoll.

Another problem was that the pollfd array length needs to match MAX_CLIENTS, that
now happens during the build.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agooptimize extpoll fd delete 94/2894/1
Edwin van der Oetelaar [Tue, 15 Jan 2013 03:23:05 +0000 (11:23 +0800)]
optimize extpoll fd delete

Previous method of shifting back array by one to cover the deleted
item could be expensive when the list was large and the deleted item
appeared early in it.

This scheme swaps the last guy into the vacant space and reduces the
list size by one.

(AG adapted for style and not to care if n is end guy)

Signed-off-by: Edwin van der Oetelaar <oetelaar.automatisering@gmail.com>
Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agodeal with SSL_ERROR_WANT_ in client connect action 93/2893/1
Andy Green [Sun, 13 Jan 2013 03:05:30 +0000 (11:05 +0800)]
deal with SSL_ERROR_WANT_ in client connect action

"4b0e01f Retry SSL_connect when SSL_get_error requests it. " from David Galeano
noticed the problem that client connect may receive SSL_ERROR_WANT_* from
SSL_connect, which is basically WOULDBLOCK.  That patch tried to deal with it
by blocking in a while(1) until the condition went away.

That's problematic because of it blocks service of anything else (including
the host application sockets in the external socket poll sharing case) for
up to 5s controlled by conditions at one client.

After fiddling with and researching this, the actual problem with the code is
we are not getting the SSL layer error correctly, it is not contained in the
code returned from the Connect api directly.

I was unable to get a renegotiation forced on my modern SSL libs, it complained
about protocol error are reopened the connection instead.  So I think the stuff
found in the docs and the web about the SSL_ERROR_WANT_ is probably not something
we will see in reality (if we check the right error code...)

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd longlived option to test client 92/2892/1
Andy Green [Sun, 13 Jan 2013 03:58:18 +0000 (11:58 +0800)]
add longlived option to test client

Needed to confirm pending timeouts won't kill the connection, by default
it spams the server with connections that live less than 5s

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agologging ensure everyone has a newline 91/2891/1
Andy Green [Mon, 14 Jan 2013 05:10:55 +0000 (13:10 +0800)]
logging ensure everyone has a newline

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoreplace ifdefs around close socket with compatible_close 90/2890/1
Andy Green [Mon, 14 Jan 2013 07:35:02 +0000 (15:35 +0800)]
replace ifdefs around close socket with compatible_close

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agossl client certs fix crash 89/2889/1
Larry Hayes [Mon, 14 Jan 2013 17:03:58 +0000 (01:03 +0800)]
ssl client certs fix crash

I run a web socket server that requires clients to present a certificate.

context_ssl_ = libwebsocket_create_context(wssPort_, wssIpAddr_.c_str(), protocols_ssl,

                           libwebsocket_internal_extensions,

                           cert_path.c_str(), key_path.c_str(), -1, -1,

LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT);

I am getting a crash in the OpenSSL_verify_callback().

The SSL_get_ex_data() call is returning NULL

I could not find a call to SSL_set_ex_data() for server mode operation.

Has anyone seen this crash in the newer versions?

Signed-off-by: Larry Hayes <larry.hayes@prodeasystems.com>
11 years agoabsorb README.rst into main README and code 88/2888/1
Andy Green [Sun, 13 Jan 2013 01:53:18 +0000 (09:53 +0800)]
absorb README.rst into main README and code

Some of the advice in README.rst became deprecated with recent patches,
the (good) advice about http connection close is better demonstrated
in the code and API docs, and the remainder can go in the main README,
which will have to be refactored itself at some point.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoexpose compiletime constants to setting from configure 87/2887/1
Andy Green [Sat, 12 Jan 2013 15:42:17 +0000 (23:42 +0800)]
expose compiletime constants to setting from configure

This patch allows control of the main compiletime constants in libwebsockets
from the configure commandline.

README is updated with documentation on what's available, how to set them
and the defaults.

The constants are logged with "info" severity (not visible by default) at
context create time.

The zlib constant previously exposed like this is moved to private-libwebsockets.h
so it can be printed along with the rest.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agorenable deflate frame buffer expansion fixing DoS 86/2886/1
Andy Green [Sat, 12 Jan 2013 15:09:36 +0000 (23:09 +0800)]
renable deflate frame buffer expansion fixing DoS

This reverts the removal of the deflate_frame code that was crashing after porting
David Galeano's code: he pointed out there's a typo in the merged version causing
the crash which is fixed here.

However the fixed code has a problem, there's no limit (other than int size) to the
amount of memory it will try to malloc, which can allow a DoS of the server by the
client sending malicious compression states that inflate to a large amount.  I have
added checking for OOM already that will avert the segfault that would otherwise follow
but the server will be unusuable if malicious connections were made repeatedly each
forcing it to allocate large buffers and cause small allocations on other connections
to fail.

The patch changes the code to use realloc(), and introduces a configurable limit
on the amount of memory one connection may need for zlib before the server hangs
up the connection.  It defaults to 64KBytes but can be set from ./configure as
described now in the README.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agofix config enable name for getifaddrs 85/2885/1
Andy Green [Sat, 12 Jan 2013 15:31:39 +0000 (23:31 +0800)]
fix config enable name for getifaddrs

copy-paste...

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agointroduce getifaddrs for toolchains without it 84/2884/1
David [Sat, 12 Jan 2013 12:39:47 +0000 (20:39 +0800)]
introduce getifaddrs for toolchains without it

David found that uclibc did not provide this slightly esoteric api
and provided one from BSD that can be built by the library internally.

AG: Made contingent on configure option --enable-builtin-getifaddrs

Signed-off-by: David <cymerio@gmail.com>
Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoaudit and make all malloc check for OOM 83/2883/1
Andy Green [Sat, 12 Jan 2013 05:21:08 +0000 (13:21 +0800)]
audit and make all malloc check for OOM

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agologging add timestamp 82/2882/1
Andy Green [Sat, 12 Jan 2013 01:25:07 +0000 (09:25 +0800)]
logging add timestamp

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agologging extend level set api to allow setting emission function 81/2881/1
Andy Green [Sat, 12 Jan 2013 01:17:42 +0000 (09:17 +0800)]
logging extend level set api to allow setting emission function

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoupdate README with info on new logging scheme 80/2880/1
Andy Green [Thu, 10 Jan 2013 14:56:15 +0000 (22:56 +0800)]
update README with info on new logging scheme

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoallow enabling debug contexts from test apps 79/2879/1
Andy Green [Thu, 10 Jan 2013 14:28:59 +0000 (22:28 +0800)]
allow enabling debug contexts from test apps

Adds a -d switch to everything so you can set the log level bitfeld.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agointroduce logging api and convert all library output to use it 78/2878/1
Andy Green [Thu, 10 Jan 2013 11:50:35 +0000 (19:50 +0800)]
introduce logging api and convert all library output to use it

 - multiple debug context calls lwsl_ err, warn, debug, parser, ext, client

 - api added to set which contexts output to stderr using a bitfield log_level

 - --disable-debug on configure removes all code that is not err or warn severity

 - err and warn contexts always output to stderr unless disabled by log_level

 - err and warn enabled by default in log_level

Signed-off-by: Andy Green <andy@warmcat.com>
11 years agocompile in xcode, privatize debug macro 77/2877/1
Aaron Zinman [Thu, 10 Jan 2013 04:35:18 +0000 (12:35 +0800)]
compile in xcode, privatize debug macro

11 years agoupdate soname and configure to v1.0 76/2876/1
Andy Green [Thu, 10 Jan 2013 04:35:18 +0000 (12:35 +0800)]
update soname and configure to v1.0

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agocorrect autotools warning 75/2875/1
Andy Green [Thu, 10 Jan 2013 04:36:59 +0000 (12:36 +0800)]
correct autotools warning

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agozlib code add OOM checks remove buffer expansion on rx path 74/2874/1
Andy Green [Thu, 10 Jan 2013 04:26:13 +0000 (12:26 +0800)]
zlib code add OOM checks remove buffer expansion on rx path

Here testing with the test serer and chrome 25, the buffer expansion
code on Rx was triggered by a valid no data output condition and looped
until it exhausted all memory.

This patch adds OOM check to all malloc()s and removes the buffer expansion
code on the rx path... leaving the code on tx path for now.

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoAvoid leaking a socket when SSL_accept fails. 73/2873/1
David Galeano [Thu, 10 Jan 2013 02:45:24 +0000 (10:45 +0800)]
Avoid leaking a socket when SSL_accept fails.

11 years agoPrint error string on accept failure. 72/2872/1
David Galeano [Thu, 10 Jan 2013 02:42:45 +0000 (10:42 +0800)]
Print error string on accept failure.

11 years agoIncreased MAX_BROADCAST_PAYLOAD to match MAX_USER_RX_BUFFER. 71/2871/1
David Galeano [Thu, 10 Jan 2013 02:41:10 +0000 (10:41 +0800)]
Increased MAX_BROADCAST_PAYLOAD to match MAX_USER_RX_BUFFER.

11 years agoAdded README file with some useful tips for using the library. 70/2870/1
David Galeano [Thu, 10 Jan 2013 02:39:57 +0000 (10:39 +0800)]
Added README file with some useful tips for using the library.

11 years agoAdded support for continuation frames on the server. 69/2869/1
David Galeano [Thu, 10 Jan 2013 02:38:21 +0000 (10:38 +0800)]
Added support for continuation frames on the server.

11 years agoClose connection if LWS_CALLBACK_HTTP returns non-zero. 68/2868/1
David Galeano [Thu, 10 Jan 2013 02:37:29 +0000 (10:37 +0800)]
Close connection if LWS_CALLBACK_HTTP returns non-zero.

11 years agoFixed to keep reading data until the SSL internal buffer is empty. 67/2867/1
David Galeano [Thu, 10 Jan 2013 02:35:32 +0000 (10:35 +0800)]
Fixed to keep reading data until the SSL internal buffer is empty.
Before this fix only 2048 bytes were read,
the rest were buffered inside SSL until another message arrived!!!

11 years agoAdded no-cache headers to client handshake: 66/2866/1
David Galeano [Thu, 10 Jan 2013 02:26:05 +0000 (10:26 +0800)]
Added no-cache headers to client handshake:
http://www.ietf.org/mail-archive/web/hybi/current/msg09841.html

11 years agoSeparate compression levels for server and client, 65/2865/1
David Galeano [Thu, 10 Jan 2013 02:24:32 +0000 (10:24 +0800)]
Separate compression levels for server and client,
increased the later one to zlib default (6).

11 years agoMore correct handling of inflate result. 64/2864/1
David Galeano [Thu, 10 Jan 2013 02:22:47 +0000 (10:22 +0800)]
More correct handling of inflate result.

11 years agoFixed crash when HTTP requests method is not GET. 63/2863/1
David Galeano [Thu, 10 Jan 2013 02:20:01 +0000 (10:20 +0800)]
Fixed crash when HTTP requests method is not GET.

11 years agoCheck if macro SSL_OP_NO_COMPRESSION is defined before trying to use it. 62/2862/1
David Galeano [Thu, 10 Jan 2013 02:18:59 +0000 (10:18 +0800)]
Check if macro SSL_OP_NO_COMPRESSION is defined before trying to use it.

11 years agoUsing size_t instead of int for deflate-frame offsets and length. 61/2861/1
David Galeano [Thu, 10 Jan 2013 02:18:17 +0000 (10:18 +0800)]
Using size_t instead of int for deflate-frame offsets and length.

11 years agoAdded private macro CIPHERS_LIST_STRING to define ciphers list string. 60/2860/1
David Galeano [Thu, 10 Jan 2013 02:15:19 +0000 (10:15 +0800)]
Added private macro CIPHERS_LIST_STRING to define ciphers list string.

11 years agoWhen choosing a cipher, use the server's preferences. 59/2859/1
David Galeano [Thu, 10 Jan 2013 02:14:12 +0000 (10:14 +0800)]
When choosing a cipher, use the server's preferences.

11 years agoPass URI length to LWS_CALLBACK_HTTP. 58/2858/1
David Galeano [Thu, 10 Jan 2013 02:13:19 +0000 (10:13 +0800)]
Pass URI length to LWS_CALLBACK_HTTP.

11 years agoDisable compression for SSL socket, 57/2857/1
David Galeano [Thu, 10 Jan 2013 02:11:57 +0000 (10:11 +0800)]
Disable compression for SSL socket,
it is a waste of CPU when using compression extensions.

11 years agoUsing "SSL_CTX_use_certificate_chain_file" instead of "SSL_CTX_use_certificate_file" 56/2856/1
David Galeano [Thu, 10 Jan 2013 02:11:21 +0000 (10:11 +0800)]
Using "SSL_CTX_use_certificate_chain_file" instead of "SSL_CTX_use_certificate_file"
to support server certificates signed by intermediaries.

11 years agoBetter definition of "debug" macro for Win32 builds. 55/2855/1
David Galeano [Thu, 10 Jan 2013 02:08:50 +0000 (10:08 +0800)]
Better definition of "debug" macro for Win32 builds.

11 years agoUse __inline for Win32 builds. 54/2854/1
David Galeano [Thu, 10 Jan 2013 02:07:16 +0000 (10:07 +0800)]
Use __inline for Win32 builds.

11 years agoAvoid checking choked pipe if no extension has more data to write. 53/2853/1
David Galeano [Thu, 10 Jan 2013 02:06:38 +0000 (10:06 +0800)]
Avoid checking choked pipe if no extension has more data to write.

11 years agozlib update 1.2.7 52/2852/1
David Galeano [Thu, 10 Jan 2013 02:03:42 +0000 (10:03 +0800)]
zlib update 1.2.7

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoSet listen backlog to SOMAXCONN. 51/2851/1
David Galeano [Thu, 10 Jan 2013 01:58:24 +0000 (09:58 +0800)]
Set listen backlog to SOMAXCONN.

11 years agoFixed operator precedence bug. 50/2850/1
David Galeano [Thu, 10 Jan 2013 01:54:10 +0000 (09:54 +0800)]
Fixed operator precedence bug.

11 years agoAvoid deflate of small packets. 49/2849/1
David Galeano [Thu, 10 Jan 2013 01:51:15 +0000 (09:51 +0800)]
Avoid deflate of small packets.

11 years agoSupport compressed packets bigger than MAX_USER_RX_BUFFER. 48/2848/1
David Galeano [Thu, 10 Jan 2013 01:41:06 +0000 (09:41 +0800)]
Support compressed packets bigger than MAX_USER_RX_BUFFER.
(AG adapted style and removed logging stuff)

11 years agoAllow extensions when no protocol was specified. 47/2847/1
David Galeano [Wed, 9 Jan 2013 11:49:50 +0000 (19:49 +0800)]
Allow extensions when no protocol was specified.

11 years agoAdded extension "deflate-frame". 46/2846/1
David Galeano [Wed, 9 Jan 2013 10:21:33 +0000 (18:21 +0800)]
Added extension "deflate-frame".
Using by default instead of "deflate-stream".

11 years agoAdded support for extensions that only manipulate application data. 45/2845/1
David Galeano [Wed, 9 Jan 2013 10:06:55 +0000 (18:06 +0800)]
Added support for extensions that only manipulate application data.

11 years agoFixed deflate-stream extension. 44/2844/1
David Galeano [Wed, 9 Jan 2013 10:03:28 +0000 (18:03 +0800)]
Fixed deflate-stream extension.
When the output buffer was exhausted the input buffer was discarded
without checking if zlib had actually consumed all the input,
now we copy the remaining input data for the next call.

11 years agoAdded private macro AWAITING_TIMEOUT instead of harcoded value 5. 43/2843/1
David Galeano [Wed, 9 Jan 2013 10:01:23 +0000 (18:01 +0800)]
Added private macro AWAITING_TIMEOUT instead of harcoded value 5.

11 years agoFixed spacing. 42/2842/1
David Galeano [Wed, 9 Jan 2013 08:35:18 +0000 (16:35 +0800)]
Fixed spacing.

11 years agoAdded context creation parameter for CA certificates file. 41/2841/1
David Galeano [Wed, 9 Jan 2013 08:25:54 +0000 (16:25 +0800)]
Added context creation parameter for CA certificates file.

11 years agoReturn NULL if the handshake failed to complete, 40/2840/1
David Galeano [Wed, 9 Jan 2013 08:17:04 +0000 (16:17 +0800)]
Return NULL if the handshake failed to complete,
libwebsocket_service_fd closes and frees the websocket in that case.

11 years agoIgnoring linux build files 39/2839/1
David Galeano [Wed, 9 Jan 2013 07:46:11 +0000 (15:46 +0800)]
Ignoring linux build files

11 years agoUse feature check rather than browser check. 38/2838/1
David Galeano [Wed, 9 Jan 2013 07:39:50 +0000 (15:39 +0800)]
Use feature check rather than browser check.

11 years agoChanged client handshake to use "Origin" instead of "Sec-WebSocket-Origin" as defined... 37/2837/1
David Galeano [Wed, 9 Jan 2013 07:31:46 +0000 (15:31 +0800)]
Changed client handshake to use "Origin" instead of "Sec-WebSocket-Origin" as defined by RFC 6455 when using version 13 of the protocol.

11 years agoFixed compiler warnings on Windows. 36/2836/1
David Galeano [Wed, 9 Jan 2013 07:29:00 +0000 (15:29 +0800)]
Fixed compiler warnings on Windows.

11 years agoAdded new status codes from RFC 6455. 35/2835/1
David Galeano [Wed, 9 Jan 2013 07:26:08 +0000 (15:26 +0800)]
Added new status codes from RFC 6455.

11 years agoFixed compiler warning on Windows. 34/2834/1
David Galeano [Wed, 9 Jan 2013 07:25:05 +0000 (15:25 +0800)]
Fixed compiler warning on Windows.

11 years agorequired version of autoconf can be lower 33/2833/1
Artem Baguinski [Wed, 9 Jan 2013 07:16:52 +0000 (15:16 +0800)]
required version of autoconf can be lower

11 years agoStatic variable is now const. 32/2832/1
David Galeano [Wed, 9 Jan 2013 07:14:31 +0000 (15:14 +0800)]
Static variable is now const.

11 years agoadd context construction option to skip server hostname lookup 31/2831/1
Andy Green [Mon, 22 Oct 2012 11:29:57 +0000 (12:29 +0100)]
add context construction option to skip server hostname lookup

Signed-off-by: Andy Green <andy.green@linaro.org>
11 years agoadd missing docs for new context user pointer 30/2830/1
Andy Green [Fri, 19 Oct 2012 10:36:28 +0000 (18:36 +0800)]
add missing docs for new context user pointer

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