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

296 commits

Author SHA1 Message Date
Andy Green
b3d6e28bc7 lws_sequencer 2019-06-25 12:10:18 +01:00
Jim Borden
477d50bf56 Add locking into the cancellation process
To avoid racing on the set and reset of interrupt_requested
2019-06-25 12:08:49 +01:00
Jim Borden
1979bd8cc9 Make the Windows pipe more responsive
Otherwise it often forgets to inform about event loop interrupts.  Add a flag to the per thread context, set it in the signal function, then check / reset it in the service method.
2019-06-25 12:08:39 +01:00
Andy Green
4692c1a7ee rtos: clean warnings where uint32_t is an unsigned long 2019-06-07 11:11:46 +01:00
Chen Xi
892cde2c71 rtos: add support for AMAZON_RTOS 2019-06-05 05:04:17 +01:00
Andy Green
48366de1d1 unix plat: add minimal wsi fd map option
An lws context usually contains a processwide fd -> wsi lookup table.

This allows any possible fd returned by a *nix type OS to be immediately
converted to a wsi just by indexing an array of struct lws * the size of
the highest possible fd, as found by ulimit -n or similar.

This works modestly for Linux type systems where the default ulimit -n for
a process is 1024, it means a 4KB or 8KB lookup table for 32-bit or
64-bit systems.

However in the case your lws usage is much simpler, like one outgoing
client connection and no serving, this represents increasing waste.  It's
made much worse if the system has a much larger default ulimit -n, eg 1M,
the table is occupying 4MB or 8MB, of which you will only use one.

Even so, because lws can't be sure the OS won't return a socket fd at any
number up to (ulimit -n - 1), it has to allocate the whole lookup table
at the moment.

This patch looks to see if the context creation info is setting
info->fd_limit_per_thread... if it leaves it at the default 0, then
everything is as it was before this patch.  However if finds that
(info->fd_limit_per_thread * actual_number_of_service_threads) where
the default number of service threads is 1, is less than the fd limit
set by ulimit -n, lws switches to a slower lookup table scheme, which
only allocates the requested number of slots.  Lookups happen then by
iterating the table and comparing rather than indexing the array
directly, which is obviously somewhat of a performance hit.

However in the case where you know lws will only have a very few wsi
maximum, this method can very usefully trade off speed to be able to
avoid the allocation sized by ulimit -n.

minimal examples for client that can make use of this are also modified
by this patch to use the smaller context allocations.
2019-05-18 12:10:19 +01:00
Andy Green
7ca8b77f2c pmd: split ebufs to track in and out 2019-05-06 07:31:32 +01:00
Andy Green
80135635bb permissions: adapt drop permissions plat function to do uid and gid lookup separately 2019-05-02 09:28:25 +01:00
Andy Green
9e347e66ce plugins: remove requirement for libuv on unix 2019-05-02 09:28:16 +01:00
Kieran
a92cf6533f windows: fix build on VS2017 WIN10 2019-04-02 07:52:39 +08:00
Andy Green
1062370f07 unix skt: allow control over skt user:group
If you're providing a unix socket service that will be proxied / served by another
process on the same machine, the unix fd permissions on the listening unix socket fd
have to be managed so only something running under the server credentials
can open the listening unix socket.
2019-03-26 14:54:49 +08:00
Andy Green
ce1f395ead context: add info members to drop privileges using user and group name strings
Up until now if you wanted to drop privs, a numeric uid and gid had to be
given in info to control post-init permissions... this adds info.username
and info.groupname where you can do the same using user and group names.

The internal plat helper lws_plat_drop_app_privileges() is updated to directly use
context instead of info both ways it can be called, and to be able to return fatal
errors.

All failures to lookup non-0 or -1 uid or gid names from uid, or to look up
uid or gid from username or groupnames given, get an err message and fatal exit.
2019-03-26 14:54:49 +08:00
Andy Green
668a3f440f minimal-http-server-eventlib-smp 2019-03-21 10:26:42 +08:00
Andy Green
4c3146c27c glibc: if malloc_trim() exists, call it periodically 2019-03-16 08:10:47 +08:00
Andy Green
9c7162f253 windows: prepare for udp 2019-03-14 21:52:53 +08:00
Andy Green
f8cd973f85 mingw: windows: make minimal examples build 2019-03-10 08:02:02 +08:00
Andy Green
09fe212432 bzero: replace all with memset
lws_explicit_bzero() is available if the goal is to have volatile zeroing.
2019-03-10 08:02:02 +08:00
Andy Green
b31ab02786 ipv6: force ipv4 if iface bind uses ipv4 address 2019-03-10 08:02:02 +08:00
Andy Green
c741f71465 adopt: force incoming fd to nonblocking
Incoming fds muct be nonblocking for any event loop... add a platform
api to do that and call it during adopt.
2019-03-10 08:02:02 +08:00
Andy Green
2d086db6e8 codacy: fixes for warnings 2019-03-10 08:02:02 +08:00
Andy Green
e63b3a6348 daemonize: use pid_t
After report from Vitaly Shevtsov

https://libwebsockets.org/pipermail/libwebsockets/2019-January/007787.html
2019-01-23 18:06:32 +08:00
Andy Green
043700a4b0 optee: remove build system 2019-01-15 06:59:48 +08:00
Andy Green
84a57540ab LWS_WITH_NETWORK: cmake option for no network code 2019-01-13 07:54:57 +08:00
Bitomaxsp
b4161f5e97 windows: socket keepalive valid is ms
https://github.com/warmcat/libwebsockets/issues/1477
2019-01-13 07:54:56 +08:00
John Kamp
30315ec688 windows: proposed fix for CANCELLED
https://github.com/warmcat/libwebsockets/issues/1291
2018-12-07 21:13:19 +08:00
Andy Green
9bed6d6fc6 clean: general whitespace cleanup 2018-11-23 08:47:56 +08:00
Andy Green
cdd8ad702c bind: treat EADDRINUSE as fatal
The retry stuff for bind failures is actually aimed at the scenarios the interface
either doesn't exist yet, or is not configured enough (having an IP) to be bindable yet.

This patch treats EADDRINUSE as fatal at vhost init.
2018-11-22 17:58:30 +08:00
Andy Green
d3bc2c3f4f fulltext search 2018-10-26 13:53:28 +08:00
Andy Green
da444d04d1 lws_time_in_microseconds: export
Rename time_in_microseconds() and export the internal
api as lws_time_in_microseconds()
2018-10-14 06:15:36 +08:00
Andy Green
33a6034875 codacy: minor fixes 2018-10-13 08:16:27 +08:00
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