diff --git a/lib/server.c b/lib/server.c index 8f6652ca..02b04afb 100644 --- a/lib/server.c +++ b/lib/server.c @@ -164,7 +164,14 @@ lws_context_init_server(struct lws_context_creation_info *info, vhost->lserv_wsi = wsi; #if LWS_POSIX - listen(wsi->sock, LWS_SOMAXCONN); + n = listen(wsi->sock, LWS_SOMAXCONN); + if (n < 0) { + lwsl_err("listen failed with error %d\n", LWS_ERRNO); + vhost->lserv_wsi = NULL; + vhost->context->count_wsi_allocated--; + remove_wsi_socket_from_fds(wsi); + goto bail; + } } /* for each thread able to independently listen */ #else #if defined(LWS_WITH_ESP8266)