restrict SO_REUSEPORT to multithreading only so no unexpected change otherwise
authorAndy Green <andy.green@linaro.org>
Fri, 29 Jan 2016 01:20:00 +0000 (09:20 +0800)
committerAndy Green <andy.green@linaro.org>
Fri, 29 Jan 2016 01:20:00 +0000 (09:20 +0800)
SO_REUSEPORT means you don't get any error any more if another
server instance is already running, this will be quite unexpected
for singlethreaded users.

Signed-off-by: Andy Green <andy.green@linaro.org>
lib/server.c

index 2009bf1..e743f45 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * libwebsockets - small server side websockets and web server implementation
  *
- * Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
+ * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -75,12 +75,13 @@ int lws_context_init_server(struct lws_context_creation_info *info,
                compatible_close(sockfd);
                return 1;
        }
-#if defined(__linux__) && defined(SO_REUSEPORT)
-       if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT,
-                      (const void *)&opt, sizeof(opt)) < 0) {
-               compatible_close(sockfd);
-               return 1;
-       }
+#if defined(__linux__) && defined(SO_REUSEPORT) && LWS_MAX_SMP > 1
+       if (context->count_threads > 1)
+               if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT,
+                               (const void *)&opt, sizeof(opt)) < 0) {
+                       compatible_close(sockfd);
+                       return 1;
+               }
 #endif
 #endif
        lws_plat_set_socket_options(context, sockfd);