From: Shuanglei Tao Date: Mon, 20 Jan 2020 15:55:39 +0000 (+0800) Subject: server: print listen port on start X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=985885ce2d46a0d491f3ef29279d0b2a6ce68a1f;p=ttyd.git server: print listen port on start --- 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); }