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

316 commits

Author SHA1 Message Date
Fredrik Fornstad
6104a25f1f Fix QTA erase after factory partition update 2018-09-17 07:26:08 +08:00
Andy Green
ee250c0d83 esp32: follow idf meddlings 2018-09-12 09:38:30 +08:00
Andy Green
95f3eb2980 plat: ENOTCONN 2018-09-11 18:27:59 +08:00
Andy Green
d58828692e http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.

This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.

Currently provides 'deflate' and 'br' compression methods for server side only.

'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.

Other compression methods can be added nicely using an ops struct.

The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.

zlib allocates quite a bit while in use, it seems to be around 256KiB per stream.  So this
is only useful on relatively strong servers with lots of memory.  However for some usecases
where you are serving a lot of css and js assets, it's a nice help.

The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end.  So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.

For h2 the chunking is neither supported nor required, so it "just works".

User code can also request to add a compression transform before the reply headers were
sent using the new api

LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
			   unsigned char **p, unsigned char *end, char decomp);

... this allows transparent compression of dynamically generated HTTP.  The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.

Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.

NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written.  The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
Andy Green
90e6e65bff partial: replace ad-hoc code with a wsi buflist_out
Various kinds of input stashing were replaced with a single buflist before
v3.0... this patch replaces the partial send arrangements with its own buflist
in the same way.

Buflists as the name says are growable lists of allocations in a linked-list
that take care of book-keeping what's added and removed (even if what is
removed is less than the current buffer on the list).

The immediate result is that we no longer have to freak out if we had a partial
buffered and new output is coming... we can just pile it on the end of the
buflist and keep draining the front of it.

Likewise we no longer need to be rabid about reporting multiple attempts to
send stuff without going back to the event loop, although not doing that
will introduce inefficiencies we don't have to term it "illegal" any more.

Since buflists have proven reliable on the input side and the logic for dealing
with truncated "non-network events" was already there this internal-only change
should be relatively self-contained.
2018-08-20 12:02:26 +08:00
Frank May
2cddfc963b windows: fix timeout between writes on Windows
After servicing a writable socket, we need to set timeout_ms
to zero. This makes WSAWaitForMultipleEvents() return immediately
after checking events.
2018-08-19 06:44:19 +08:00
Frank May
248826d7fc windows: Remove useless code
WSASetEvent(pt->events) just makes WSAWaitForMultipleEvents()
return, it will not set LWS_POLLOUT in pfd->revents and thus
has IMHO no effect. If WSAWaitForMultipleEvents() will set
LWS_POLLOUT it will also signal the event automatically.
2018-08-19 06:44:03 +08:00
Frank May
e17820cf67 windows: fix possible crash
Checking for (!wsi) does not make sense, if wsi is
dereferenced in the line above.
2018-08-19 06:43:49 +08:00
Andy Green
d461f46a97 libwebsockets.h: clean out some boilerplate better put in core/private.h
https://github.com/warmcat/libwebsockets/issues/1370
2018-08-16 19:10:32 +08:00
Andy Green
f44e38f148 unix socket: fixes and improvements
Auto-remove any unix socket file already there.

Correctly identify if it's in use per-vhost.

Make the peer-limits stuff ignore it.
2018-08-14 08:00:30 +08:00
Andy Green
69d9cf2e6b coverity: cleanup 2018-08-14 08:00:30 +08:00
Andy Green
de21a5b5b9 protocol_init: make errors fatal 2018-08-14 08:00:30 +08:00
Andy Green
cfeb196479 client: SMP: associate client with tsi of thread creating client connection
1) This moves the service tid detection stuff from context to pt.

2) If LWS_MAX_SMP > 1, a default pthread tid detection callback is provided
   on the dummy callback.  Callback handlers that call through to the dummy
   handler will inherit this.  It provides an int truncation of the pthread
   tid.

3) If there has been any service calls on the service threads, the pts now
   know the low sizeof(int) bytes of their tid.  When you ask for a client
   connection to be created, it looks through the pts to see if the calling
   thread is a pt service thread.  If so, the new client is set to use the
   same pt as the caller.
2018-08-14 08:00:30 +08:00
shinny-chengzhi
5740356d9a Fix I/O hang after received a large deflate frame
When a large deflate frame been received, WSAEnumNetworkEvents will indicate the socket is ready to read. And because the frame is compressed, it may not be consumed entirely(not all bytes ready to receive have been received), since WSAEnumNetworkEvents is edge triggered, and the socket read buffer never been drained, WSAEnumNetworkEvents will never indicate the socket is ready to read again. What here need is level trigger behavior, thus add additional recv with empty buffer to reset edge status.
2018-07-11 15:14:01 +08:00
Andy Green
f2f96857d6 fd_cloexec: add and use lws_open wrapper and lws_plat_apply_FD_CLOEXEC() on cgi 2018-06-23 12:56:21 +08:00
Per Bothner
f7631b7a10 sockets: FD_CLOEXEC
If the user code forks, it inherits open copies of all
lws sockets, which conflict if lws later decides to
close them.
2018-06-23 05:44:36 +08:00
negativekelvin
bd9c1b715f Fixes to track updates in esp-idf 2018-06-20 16:41:28 +08:00
Andy Green
df1d60fc1a plat: refactor private headers and split files
Also remove LWS_VISIBLE that are not necessary from plat apis
2018-06-20 16:41:27 +08:00
Ecionis
794c70cdc0 windows: fix microseconds time calculation
https://github.com/warmcat/libwebsockets/issues/1297
2018-06-02 06:01:47 +08:00
emptyVoid
43bb340566 Fixed a couple of runtime issues introduced in commit 44efcd6. 2018-06-02 05:56:19 +08:00
Andy Green
44efcd6196 windows: remove unused event array 2018-05-26 19:41:06 +08:00
Andy Green
064c548f9b lws_read_h1: handle LRS_RETURNED_CLOSE 2018-05-11 10:25:28 +08:00
Andy Green
f6f7c7e228 TCP_USER_TIMEOUT: make sure we include the correct header if linux 2018-05-10 19:31:05 +08:00
Andy Green
7bced4fac7 LWS_INLINE: replace all inline 2018-05-09 09:28:06 +08:00
Andy Green
2f5f1125f7 esp32: align hrtimer and avoid compiler warning 2018-05-07 13:34:14 +08:00
Andy Green
c4dc102a0b windows: cleanup wrong and duplicated socket validity helpers
https://github.com/warmcat/libwebsockets/issues/1259
2018-05-06 07:22:25 +08:00
Andy Green
e77dafba6f win32: align hrtimer support with unix plat
Workaround last build warnings on win32.
2018-05-05 07:18:00 +08:00
Andy Green
de064fd65a refactor: core code in lib/core and private-libwebsockets.h to core/private.h
This commit is coverity-clean as tested

cmake .. -DLWS_WITH_MINIMAL_EXAMPLES=1 -DLWS_WITHOUT_EXTENSIONS=1 -DLWS_WITH_ACME=1 -DLWS_WITH_LWSWS=1 -DLWS_WITH_LIBUV=1 -DLWS_WITH_HTTP2=1 -DLWS_WITHOUT_CLIENT=0 -DLWS_WITHOUT_SERVER=0 -DLWS_UNIX_SOCK=1 -DLWS_WITH_TLS=0 -DLWS_WITH_MBEDTLS=0 -DLWS_WITH_CGI=1 -DCMAKE_BUILD_TYPE=DEBUG -DLWS_WITH_GENERIC_SESSIONS=1 -DLWS_WITH_RANGES=1 -DLWS_ROLE_WS=1 -DLWS_MAX_SMP=16 -DLWS_ROLE_H1=1 -DLWS_WITH_WOLFSSL=0 -DLWS_WITH_LIBEV=0 -DLWS_WITH_LIBEVENT=1
2018-05-03 10:49:36 +08:00
Andy Green
bce8cca042 refactor: also migrate tls to the ops struct and private.h pattern
Several new ops are planned for tls... so better to bite the bullet and
clean it out to the same level as roles + event-libs first.

Also adds a new travis target "mbedtls" and all the tests except
autobahn against mbedtls build.
2018-05-02 12:10:36 +08:00
Andy Green
f497562a62 refactor: change event lib minimal examples to serve as the test apps 2018-04-30 19:17:32 +08:00
Andy Green
d37b383edc refactor: apply ops structs to event loop handlers 2018-04-29 10:44:36 +08:00
Andy Green
91a47f4fab refactor: also constify CAPS usage of context info 2018-04-28 08:01:01 +08:00
Andy Green
7ff8f023d1 context info struct: make lws usage all const 2018-04-27 08:37:20 +08:00
Andy Green
27e86e2641 cmake: allow setting LWS_ROLE_WS
You can build lws without support for ws, with -DLWS_ROLE_WS=0.

This is thanks to the role ops isolating all the ws-specific business
in the ws role.

Also retire more test apps replaced by minmal-examples.
2018-04-25 08:42:18 +08:00
Andy Green
a9390874c7 tcp keepalive: user TCP_USER_TIMEOUT on linux if extant
https://github.com/warmcat/libwebsockets/issues/1223
2018-04-19 16:16:48 +08:00
Andy Green
62af7934c8 rxflow buflist: handle forced service 2018-04-19 16:15:10 +08:00
Andy Green
65f87efca9 pipe2 where possible 2018-04-19 16:15:10 +08:00
Andy Green
126be3ccf3 refactor role ops
This only refactors internal architecture and representations, the user
api is unaffected.
2018-04-11 13:39:42 +08:00
Andy Green
de4c1303f5 Coverity 189186: hrtimer calculation overflow 2018-04-06 10:38:04 +08:00
Andy Green
8f19a3fa9a network interface: defer bindings to absent network interfaces
Previously down network interfaces without an IPv4 address are
removed from the posix api that lists network interfaces.

That means if you bound a vhost listen socket to a particular
interface, it will fail at startup time.

This patch adds these vhosts to a list, starts the vhost without
a listen socket, and checks to see if the vhost's network interface
has appeared while the rest of lws is running.

If it appears, the listen socket is opened on the network interface
and the vhost becomes reachable.
2018-04-06 10:38:03 +08:00
Andy Green
1820212724 lws_set_timer_usecs: change to usec resolution
This replaces the existing, unreleased lws_set_timer(wsi, secs) with
lws_set_timer_usecs(wsi, usecs).

wsi with a timer waiting are added to a linked-list sorted by the
timer trigger time.

1) poll() timeout (ie, poll wait) is trimmed to the nearest ms of the
first waiting timer if the default poll wait is longer than the
interval until the first waiting timer.

The linked-list of waiting timers is checked every entry and exit
from poll()... if no timers waiting or none reached their time
this costs almost nothing.

2) libuv: the earliest hrtimer is checked after every IO, again this
is costing nothing if the list head is NULL.  If the case there
are hrtimers on the list, it costs a getimeofday (a VDSO in linux)
and more only if any of the timers have fired.

In addition on entry to libuv idle, if there are any waiting hrtimers
on the list, a libuv timer is used to force a wake in case we stay
idle (the libuv timer has ms resolution).

3) libev: not implemented

4) libevent: not implemented

Warnings are logged in the api is used on an event backend without
support.  Patches welcome to add support similarly to libuv.
2018-04-06 10:38:03 +08:00
Andy Green
aae2c24678 lws_snprintf 2018-03-12 09:28:42 +08:00
Andy Green
0d5ca2d87b pthreads: more locking 2018-03-05 16:49:28 +08:00
Andy Green
658b86ed9f esp32: fix basic auth 2018-03-01 10:27:12 +08:00
Andy Green
a0581a926b esp32: map basic auth to nvs 2018-02-24 08:14:17 +08:00
Andy Green
9556ad77fb esp32: bump ssid and pw fields to 64 2018-02-02 08:09:08 +08:00
Andy Green
65a67d72f1 esp32: adapt to esp-idf mdns changes 2018-01-29 15:17:33 +08:00
Anzey
08d36dbe43 qnx: add support
https://libwebsockets.org/pipermail/libwebsockets/2018-January/003600.html
2018-01-04 10:43:20 +08:00
Andy Green
e8e448df3e plat optee: updates 2017-12-20 10:44:21 +08:00
Andy Green
d58d749b30 acme: adaptations through plat for esp32 2017-12-11 13:30:12 +08:00