1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

vhost: bind: make failure to bind optionally fatal

When creating a vhost and the port is already bound to another process
this flag would allow the user code to choose to have the
lws_create_vhost function to fail and return a null pointer.
This commit is contained in:
Ilan Pegoraro 2019-06-27 12:14:50 +01:00 committed by Andy Green
parent 0ada40ce92
commit 0123b4381f
2 changed files with 8 additions and 2 deletions

View file

@ -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 ---^ ******/
};

View file

@ -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;
}
}