/* This does not actually stop the event loop. The reason is we have to pass libuv handle closures through its event loop. So this tries to close all wsi, and set a flag; when all the wsi closures are finalized then we actually stop the libuv event loops.  */
LWS_VISIBLE void lws_libuv_stop(struct lws_context *context)
/* This does not actually stop the event loop. The reason is we have to pass libuv handle closures through its event loop. So this tries to close all wsi, and set a flag; when all the wsi closures are finalized then we actually stop the libuv event loops.  */
LWS_VISIBLE void lws_libuv_stop(struct lws_context *context)
{
	struct lws_context_per_thread *pt;
	int n, m;
	if (context->requested_kill)
		return;
	context->requested_kill = 1;
	m = context->count_threads;
	context->being_destroyed = 1;
	while (m--) {
		pt = &context->pt[m];
		for (n = 0; (unsigned int)n < context->pt[m].fds_count; n++) {
			struct lws *wsi = wsi_from_fd(context, pt->fds[n].fd);
			if (!wsi)
				continue;
			lws_close_free_wsi(wsi,
				LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY);
			n--;
		}
	}
	lwsl_info("%s: feels everything closed\n", __func__);
	if (context->count_wsi_allocated == 0)
		lws_libuv_kill(context);
}