1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00
Commit graph

4250 commits

Author SHA1 Message Date
Andy Green
0b31909cce expose log level in emit
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-19 11:53:45 +08:00
Andy Green
3662b663bc change bitfield setting to avoid gcc warnings
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-19 11:53:41 +08:00
Andy Green
10601c1fba 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>
2013-01-19 10:39:35 +08:00
Andy Green
acbaee649a add lws_confirm_legit_wsi
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-18 22:00:22 +08:00
Andy Green
a1ce6be947 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>
2013-01-18 11:43:21 +08:00
Andy Green
2fd3f2f78f introdice tracking if frame is binary
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-18 09:49:20 +08:00
Edwin van den Oetelaar
759c9ac465 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>
2013-01-18 09:20:54 +08:00
Andy Green
6d1fcb7a95 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>
2013-01-18 01:55:48 +08:00
Andy Green
4a673a38ca 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>
2013-01-17 19:53:16 +08:00
Andy Green
706961dbb5 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>
2013-01-17 17:18:55 +08:00
Andy Green
0303db482e 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>
2013-01-17 17:07:52 +08:00
Andy Green
dfb2304168 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>
2013-01-17 15:50:10 +08:00
Edwin van der Oetelaar
6c720c4440 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>
2013-01-17 15:50:09 +08:00
Andy Green
b2de95d2d4 include daemonization file whoops
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-17 15:49:27 +08:00
Andy Green
eff73742bc portability dont assume size of tv.t_usec
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-17 15:02:02 +08:00
Andy Green
6304686509 add disable debug to README configuration options list
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-17 10:15:52 +08:00
Peter Young
27b3237392 including assert h needed on osx
Signed-off-by: Peter Young <young40@qq.com>
2013-01-17 10:10:10 +08:00
Peter Young
26757a75bc just use limits.h directly
Signed-off-by: Peter Young <young40@qq.com>
2013-01-17 10:08:16 +08:00
Andy Green
279a303662 introduce daemonize
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-17 10:05:39 +08:00
Andy Green
d32bb9128b 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>
2013-01-17 00:50:48 +08:00
Andy Green
443ea54c5c move array bounds gcc workaround outside function
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 17:46:00 +08:00
Andy Green
f7248f8dfa 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>
2013-01-16 15:12:33 +08:00
Andy Green
cf3590e460 export lswl_hexdump
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 14:35:27 +08:00
Andy Green
040d2efa12 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>
2013-01-16 13:40:43 +08:00
Andy Green
03674a655d 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>
2013-01-16 12:35:46 +08:00
Andy Green
5378b143c3 test client remove usleep
Whatever caused the need for this has gone away

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 12:34:58 +08:00
Andy Green
b429d48cf1 refactor output.c
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 12:34:56 +08:00
Andy Green
76f61e7ade refactor migrate client stuff to client.c
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 11:53:05 +08:00
Andy Green
53f437e4e1 add new context arg to libwebsockets_serve_http_file
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 11:45:38 +08:00
Andy Green
1023d2b18f robustness server dont exit server on accept problems
Error message corrected to %s as well

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 11:43:53 +08:00
Andy Green
3278872824 workaround for some gcc array bounds false positive
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 10:21:34 +08:00
Andy Green
fab033dd4f add logo to test file
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 10:11:34 +08:00
Andy Green
bb2dc8aeb1 update test server html serving callback to use aepd whitelist approach
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 10:06:28 +08:00
Andy Green
56d4697463 add libwebsockets.org logo to share
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 10:00:39 +08:00
Andy Green
583f8b3b11 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>
2013-01-16 09:16:30 +08:00
Andy Green
65b0e91061 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>
2013-01-16 07:59:47 +08:00
Andy Green
fa17ca7225 add empty m4 dir as workaround for autoreconf issue
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-15 21:56:12 +08:00
Andy Green
a824d18bc5 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>
2013-01-15 20:52:29 +08:00
Andy Green
5fc460cd41 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>
2013-01-15 20:44:46 +08:00
Andy Green
29da6d9443 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>
2013-01-15 19:57:06 +08:00
Jack Mitchell
63ca55e9b3 make sure we have PATH_MAX on some linux toolchains
(AG modified a bit)


Signed-off-by: Jack Mitchell <ml@communistcode.co.uk>
2013-01-15 19:49:05 +08:00
Edwin van der Oetelaar
8db451f363 extpoll break out of loop when set or clear finds fd
Signed-off-by: Edwin van der Oetelaar <oetelaar.automatisering@gmail.com>
2013-01-15 16:22:34 +08:00
Andy Green
d280b6ecb3 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>
2013-01-15 16:00:36 +08:00
Andy Green
a50dd1af40 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>
2013-01-15 15:50:31 +08:00
Edwin van der Oetelaar
5e59bf15e1 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>
2013-01-15 15:50:28 +08:00
Andy Green
73abc25cb5 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>
2013-01-15 15:43:31 +08:00
Andy Green
43063dd250 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>
2013-01-15 15:43:17 +08:00
Andy Green
f7609e9ada logging ensure everyone has a newline
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-15 15:41:15 +08:00
Andy Green
3fc2c65d2f replace ifdefs around close socket with compatible_close
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-15 15:41:05 +08:00
Larry Hayes
455d1fed06 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>
2013-01-15 01:03:58 +08:00