mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
web: retry binding to other ports if port is already in use by something else
This commit is contained in:
parent
3c33696265
commit
27a1ef0314
1 changed files with 14 additions and 8 deletions
22
lib/web.c
22
lib/web.c
|
@ -254,19 +254,25 @@ int web_start(struct web *w)
|
|||
|
||||
info("Starting Web sub-system: webroot=%s", w->htdocs);
|
||||
|
||||
{
|
||||
/* update web root of mount point */
|
||||
mounts[0].origin = w->htdocs;
|
||||
/* update web root of mount point */
|
||||
mounts[0].origin = w->htdocs;
|
||||
|
||||
w->context = lws_create_context(&ctx_info);
|
||||
if (w->context == NULL)
|
||||
error("WebSocket: failed to initialize server context");
|
||||
w->context = lws_create_context(&ctx_info);
|
||||
if (w->context == NULL)
|
||||
error("WebSocket: failed to initialize server context");
|
||||
|
||||
for (int tries = 10; tries > 0; tries--) {
|
||||
w->vhost = lws_create_vhost(w->context, &ctx_info);
|
||||
if (w->vhost == NULL)
|
||||
error("WebSocket: failed to initialize virtual host");
|
||||
if (w->vhost)
|
||||
break;
|
||||
|
||||
ctx_info.port++;
|
||||
warn("WebSocket: failed to setup vhost. Trying another port: %d", ctx_info.port);
|
||||
}
|
||||
|
||||
if (w->vhost == NULL)
|
||||
error("WebSocket: failed to initialize virtual host");
|
||||
|
||||
ret = pthread_create(&w->thread, NULL, web_worker, w);
|
||||
if (ret)
|
||||
error("Failed to start Web worker thread");
|
||||
|
|
Loading…
Add table
Reference in a new issue