From 985885ce2d46a0d491f3ef29279d0b2a6ce68a1f Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Mon, 20 Jan 2020 23:55:39 +0800 Subject: [PATCH] server: print listen port on start --- src/server.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/server.c b/src/server.c index d586c8a..2d84cec 100644 --- a/src/server.c +++ b/src/server.c @@ -475,17 +475,30 @@ main(int argc, char **argv) { void *foreign_loops[1]; foreign_loops[0] = server->loop; info.foreign_loops = foreign_loops; + info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS; #endif context = lws_create_context(&info); if (context == NULL) { - lwsl_err("libwebsockets init failed\n"); + lwsl_err("libwebsockets context creation failed\n"); return 1; } +#if LWS_LIBRARY_VERSION_MAJOR >= 3 + struct lws_vhost *vhost = lws_create_vhost(context, &info); + if (vhost == NULL) { + lwsl_err("libwebsockets vhost creation failed\n"); + return 1; + } + int port = lws_get_vhost_listen_port(vhost); +#else + int port = info.port; +#endif + lwsl_notice(" Listening on port: %d\n", port); + if (browser) { char url[30]; - sprintf(url, "%s://localhost:%d", ssl ? "https" : "http", info.port); + sprintf(url, "%s://localhost:%d", ssl ? "https" : "http", port); open_uri(url); } -- 2.43.4