Commit graph

40 commits

Author SHA1 Message Date
Petar Paradzik
a5463053e8 Subject: libuv: Fix closing handle multiple times
Sometimes "Assertion failed: !uv__is_closing(handle)" happens because
handle is being closed multiple times. To fix this, "uv_is_closing"
is added before calling "uv_close".

Signed-off-by: Petar Paradzik <petar.paradzik@sartura.hr>
2017-05-23 23:50:04 +08:00
Andy Green
a68539492f mings: adjust plugin export name gen 2017-04-28 11:47:21 +08:00
Andy Green
36239951be mingw: use win32 plugin names 2017-04-28 10:14:40 +08:00
Andy Green
786e6dbf35 mingw: updates 2017-04-28 07:51:34 +08:00
Andy Green
42ea3bd703 ext: pmd: improve dealing with partial input usage with drain
https://github.com/warmcat/libwebsockets/issues/841
2017-03-20 19:34:49 +08:00
Andy Green
be8d791b5e adoption: make union for socket and file fds
This lets lws support adopting raw file FDs and raw socket fds.

A test plugin creates a FIFO and prints data sent on it, using
the lws event loop.
2017-03-01 10:01:53 +08:00
Andy Green
be9fb919d1 context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.

2) You can send this parent process a SIGHUP now to cause it to

 - close listening sockets in existing lwsws processes

 - mark those processes as to exit when the number of active connections
   on the falls to zero

 - spawn a fresh child process from scratch, using latest configuration
   file content, latest plugins, etc.  It can now reopen listening sockets
   if it chooses to, or open different listen ports or whatever.

Notes:

1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.

That's the purpose of the second part of the context destruction,
lws_context_destroy2().

For compatibility, if you are not using libuv, the first part calls the
second part.  However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-20 14:37:07 +08:00
Andy Green
0a3859f623 uv: dont try to touch watcher until after loop initialized 2016-12-20 14:37:07 +08:00
Bablooos
6e436dca39 vhost: allow adding vhosts after server init
This should allow adding vhosts "late", ie, after the server is up and
running with its initial vhost(s).  The necessary housekeeping is folded
into lws_create_vhost() itself so it should be transparent.

Notice though that at the point the server starts to do service after it
starts initially, if it was requested that the UID / GID change, that
is performed at that point and is not reversible.

So vhosts added "late" find themselves running under the unprivileged
UID / GID from the very start, whereas vhosts added "early" initially
run under the UID / GID the process started with.  If protocols the
vhost uses want to, eg, open privileged files at init and then use
them unprivileged, that will fail if the vhost is added late because
the initial privs are already gone.

AG: also deal with lws_protocol_init() on late vhost init (does the
callbacks for per vh protocol creation), add comments
2016-12-16 22:08:13 +08:00
Andy Green
b46c401245 alias lws_plat_service_tsi to lws_service_tsi in public api
Via Dosvald

lws_service_tsi() which has been around a while actually just
calls through to lws_plat_service_tsi(), meaning there is no
need to expose both apis.

Rename the internal lws_plat_service_tsi() to _lws_plat_service_tsi()
and replace the api export with a #define to lws_service_tsi for
compatibility's sake.
2016-12-16 22:08:12 +08:00
Andy Green
65135f2bc4 port forced service checking from libuv
Related to second part of

https://github.com/warmcat/libwebsockets/issues/638
2016-10-04 08:39:14 +08:00
Andy Green
a496700b3a lws_snprintf
Thanks to Fabrice Gilot for reporting the problem that led to uncovering this.

Due to a misunderstanding of the return value of snprintf (it is not truncated according
to the max size passed in) in several places relying on snprintf to truncate the length
overflows are possible.

This patch wraps snprintf with a new lws_snprintf() which does truncate its length to allow
the buffer limiting scheme to work properly.

All users should update with these fixes.
2016-09-15 02:22:57 +08:00
Andy Green
90f513b209 uv: dont handle SIGSEGV, SIGFPE
https://github.com/warmcat/libwebsockets/issues/609
2016-08-20 05:47:29 +08:00
Andy Green
9de9d0dacd windows adapt plugin name format vs functions
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-25 21:44:30 +08:00
Andy Green
7a9970f90d win fix warnings from appveyor
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-15 08:31:01 +08:00
Andy Green
97164368dd asserts log which
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-13 10:27:48 +08:00
Andy Green
b6d229d726 check oom on lws_malloc
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-12 21:04:33 +08:00
Andy Green
4e3b0ce973 libuv tidy up destroy and disable timer races during shutdown
Also don't make us wait 1s for init to finish.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-08 17:07:46 +08:00
Andy Green
5474221a0c libuv fixes for foreign loop test
Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-04 08:40:46 +08:00
Andy Green
cae57ad98d plugins_dir convert to array
If OOT lws plugins will be packaged as separate projects,
they're going to want to install their plugins somewhere
that makes sense for the package instead of one big lws
plugin dir.

This patch changes info to have a const char ** to a NULL
terminated array of directories it should search for
plugins.  lwsws knows about this and you can add to the
dir array using config fragments like

{
  "global": {
   "plugin-dir": "/usr/local/share/coherent-timeline/plugins"
  }
}

if the config fragment in /etc/lwsws/conf.d/ is also managed by the
package with the plugin, it can very cleanly add and remove itself
from lwsws based on package install status.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-05-02 10:03:25 +08:00
Andy Green
5f947cdcd9 windows another uv_poll_init
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-19 09:10:08 +08:00
Andy Green
4714cf02f4 vh doubly linked list for wsi on same protocol
This trades off a couple of wsi pointers for vastly increased speed
for the callback when writeable "all protocol" variants when there
are many kinds of wsi active.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-16 08:40:35 +08:00
Andy Green
a5e73a1a4b lwsws cgi integration
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-13 11:53:40 +08:00
Andy Green
0a183545b2 lwsws conf and plugins convert to libuv apis
After discussion here

https://libwebsockets.org/pipermail/libwebsockets/2016-April/002268.html

scandir usage in

 - lwsws conf.c
 - lws plugin support

and

 - lws plugin apis for dl

are converted to us libuv apis so they can work cross-platform easily.

lws itself remains not requiring libuv, although it's an option.

 - LWS_WITH_LWSWS
 - LWS_WITH_PLUGINS

now force LWS_WITH_LIBUV if selected... both of these are new features
only in master atm and both are off by default in CMake.

There's a complication libuv can be too old to offer the necessary apis,
this is the case in Travis Trusty instance.  In that case, UV_VERSION_MAJOR ==0,
then the unix-only plugin implementation is used instead.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-13 11:53:40 +08:00
Andy Green
020770566e plugins
This adds support for dynamically loaded plugins at runtime, which
can expose their own protocols or extensions transparently.

With these changes lwsws defaults to OFF in cmake, and if enabled it
automatically enables plugins and libuv support.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-07 09:38:08 +08:00
Andy Green
09998e3ad8 libuv add idle processing to force service where needed
https://github.com/warmcat/libwebsockets/issues/485

Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-07 09:38:08 +08:00
Andy Green
45dead99e0 libuv report init failure
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-05 06:57:02 +08:00
Meir Yanovich
9694ebefe8 libuv win32 fixes 2
https://github.com/warmcat/libwebsockets/issues/411#issuecomment-204284368
2016-04-01 15:56:48 +08:00
Andy Green
bbcd24167f libuv win32 fixes
Signed-off-by: Andy Green <andy@warmcat.com>
2016-03-31 20:12:14 +08:00
Andy Green
d526c50c22 introduce vhosts
This patch splits out some lws_context members into a new lws_vhost struct.

 - ssl state and options per vhost
 - SSL_CTX for serving and client per vhost
 - protocols[] per vhost
 - extensions[] per vhost

lws_context maintains a linked list of lws_vhosts.

The same lws_context_creation_info struct is used to regulate both the
context creation and to create vhosts: for backward compatibility if you
didn't provide the new LWS_SERVER_OPTION_EXPLICIT_VHOSTS option, then
a default vhost is created at context creation time using the same info
data as the context itself.

If you will have multiple vhosts though, you should give the
LWS_SERVER_OPTION_EXPLICIT_VHOSTS option at context creation time,
create the context first and then the vhosts afterwards using

  lws_create_vhost(contest, &info);

Although there is a lot of housekeeping to implement this change, there
is almost no additional overhead if you don't use multiple vhosts and
very little api impact (no changes to test apps).

Signed-off-by: Andy Green <andy@warmcat.com>
2016-03-28 10:15:25 +08:00
Andy Green
c6fd360160 LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT to default to runtime ssl disable
https://github.com/warmcat/libwebsockets/issues/468

Adds lws_check_opt() to regularize multibit flag checking.

There's a new context creation flag LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT,
this is included automatically if you give any other SSL-related option flag.
If you give no SSL-related option flag, nor this one directly, then even
though SSL support may be compiled in, it is never initialized nor used for the
whole lifetime of the lws context.

Conversely in order to prepare the context to use SSL, even though, eg, you
are not listening on SSL but will use SSL client connections later, you can
give this flag explicitly to make sure SSL is initialized.

Signed-off-by: Andy Green <andy@warmcat.com>
2016-03-23 09:22:11 +08:00
Denis Osvald
f107e4bb85 libuv: sigint API cleanup
Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
2016-03-23 07:46:39 +08:00
Denis Osvald
de9f794b27 libuv: handle signals only if requested
Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
2016-03-23 07:44:06 +08:00
Alex Hultman
fe16003644 libuv.c: Service fd with LWS_POLLHUP on poll errors 2016-03-02 18:57:26 +08:00
Andy Green
e3d141dae9 adopt readbuf do service
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-29 11:04:53 +08:00
Andy Green
38a1cbb498 libuv create 1Hz background timeout check
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-27 11:04:04 +08:00
Alex Hultman
ecf7f00772 Stop uv loop in default signal handler, clean-ups 2016-02-20 23:06:56 +08:00
Alex Hultman
2904de5ff2 Make sure every handle is closed before destroying the uv loop 2016-02-20 22:48:34 +08:00
Alex Hultman
f84be14677 Don't destroy ev/uv loops if they haven't been created yet 2016-02-20 19:29:06 +08:00
Andy Green
86ed65ff00 libuv integration
This gets the libuv stuff plumbed in and working.

Currently it's only workable for some service thread, and there
is an isolated valgrind problem left

==28425== 128 bytes in 1 blocks are definitely lost in loss record 3 of 3
==28425==    at 0x4C28C50: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==28425==    by 0x4C2AB1E: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==28425==    by 0x58BBB27: maybe_resize (core.c:748)
==28425==    by 0x58BBB27: uv__io_start (core.c:787)
==28425==    by 0x58C1B80: uv__signal_loop_once_init (signal.c:225)
==28425==    by 0x58C1B80: uv_signal_init (signal.c:260)
==28425==    by 0x58BF7A6: uv_loop_init (loop.c:66)
==28425==    by 0x4157F5: lws_uv_initloop (libuv.c:89)
==28425==    by 0x405536: main (test-server-libuv.c:284)

libuv wants to sign off on all libuv 'handles' that will close, and
callback to do the close confirmation asynchronously.  The wsi close function
is adapted when libuv is in use to work with libuv accordingly and exit the uv
loop the number of remaining wsi is zero.

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-14 09:31:13 +08:00