lws-vhost-destroy
authorAndy Green <andy@warmcat.com>
Sat, 15 Jul 2017 06:37:04 +0000 (14:37 +0800)
committerAndy Green <andy@warmcat.com>
Wed, 19 Jul 2017 00:51:43 +0000 (08:51 +0800)
commitfaa1526b394ac85d023b62d11fc436dd713efb4c
tree81853b61d3a5f33039c30065bf24da85c3440ab5
parent632a0acc99ebba050ed03c8f376cb41ee0744068
lws-vhost-destroy

Adds a new api lws_vhost_destroy(struct lws_vhost *) which allows dynamic removal of vhosts.

The external api calls two parts of internal helpers that get reused for context destroy.

The second part is called deferred by 5s... this is to ensure that event library objects
composed into structs owned by the vhost all have a chance to complete their close
asynchronously.  That should happen immediately, but it requires us to return to the
event loop first.

The vhost being removed is deleted from the context vhost list by the first part, and does
not block further removals or creation during the delay for the deferred freeing of the
vhost memory.

Part 1:

 - if the vhost owned a listen socket needed by other vhosts listening on same iface + port, the listen
   socket is first handed off to another vhost so it stays alive

 - all wsi still open on the vhost are forcibly closed (including any listen socket still attached)

 - inform all active protocols on the vhost they should destroy themselves

 - remove vhost from context vhost list (can no longer be found by incoming connections)

 - add to a "being destroyed" context list and schedule the second part to be called in 5s

Part 2:

 - remove us from the being destroyed list

 - free all allocations owned by the vhost

 - zero down the vhost and free the vhost itself

In libwebsockets-test-server, you can send it a SIGUSR1 to have it toggle the creation and destruction of
a second vhost on port + 1.
13 files changed:
README.test-apps.md
lib/context.c
lib/libuv.c
lib/libwebsockets.c
lib/libwebsockets.h
lib/private-libwebsockets.h
lib/server.c
lib/service.c
lib/ssl-server.c
lwsws/main.c
plugins/protocol_dumb_increment.c
test-server/test-server-v2.0.c
test-server/test-server.c