diff --git a/include/libwebsockets/lws-context-vhost.h b/include/libwebsockets/lws-context-vhost.h index e7bc620c8..152a79a26 100644 --- a/include/libwebsockets/lws-context-vhost.h +++ b/include/libwebsockets/lws-context-vhost.h @@ -203,6 +203,10 @@ enum lws_context_options { * on the client using http when he meant https... it's not * recommended. */ + LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND = (1 << 30), + /**< (VH) When instantiating a new vhost and the specified port is + * already in use, a null value shall be return to signal the error. + */ /****** add new things just above ---^ ******/ }; diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index 2523d7018..2433149b8 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -130,13 +130,15 @@ done_list: if (info) /* first time */ lwsl_err("VH %s: iface %s port %d DOESN'T EXIST\n", vhost->name, vhost->iface, vhost->listen_port); - return 1; + return (info->options & LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND) == LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND? + -1 : 1; case LWS_ITOSA_NOT_USABLE: /* can't add it */ if (info) /* first time */ lwsl_err("VH %s: iface %s port %d NOT USABLE\n", vhost->name, vhost->iface, vhost->listen_port); - return 1; + return (info->options & LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND) == LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND? + -1 : 1; } }