Author: cazfi
Date: Thu Oct 15 19:09:56 2015
New Revision: 30100

URL: http://svn.gna.org/viewcvs/freeciv?rev=30100&view=rev
Log:
Limit search for free port to 10000 ports instead of infinity if for
some reason it's not possible to bind() any ports.

See patch #6423

Modified:
    branches/S2_5/client/connectdlg_common.c
    branches/S2_5/utility/netintf.c
    branches/S2_5/utility/netintf.h

Modified: branches/S2_5/client/connectdlg_common.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/connectdlg_common.c?rev=30100&r1=30099&r2=30100&view=diff
==============================================================================
--- branches/S2_5/client/connectdlg_common.c    (original)
+++ branches/S2_5/client/connectdlg_common.c    Thu Oct 15 19:09:56 2015
@@ -174,8 +174,8 @@
 }   
 
 /**************************************************************** 
-forks a server if it can. returns FALSE is we find we couldn't start
-the server.
+  Forks a server if it can. Returns FALSE if we find we
+  couldn't start the server.
 *****************************************************************/ 
 bool client_start_server(void)
 {
@@ -220,9 +220,12 @@
    * used by standalone server on Windows where this is known to be buggy
    * by not starting from DEFAULT_SOCK_PORT but from one higher. */
   internal_server_port = find_next_free_port(DEFAULT_SOCK_PORT + 1,
+                                             DEFAULT_SOCK_PORT + 1 + 10000,
                                              family, "localhost", TRUE);
 
   if (internal_server_port < 0) {
+    log_verbose("None of the ports %d - %d is available to start freeciv 
server on.",
+                DEFAULT_SOCK_PORT + 1, DEFAULT_SOCK_PORT + 1 + 10000);
     output_window_append(ftc_client, _("Couldn't start the server."));
     output_window_append(ftc_client,
                          _("You'll have to start one manually. Sorry..."));

Modified: branches/S2_5/utility/netintf.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/utility/netintf.c?rev=30100&r1=30099&r2=30100&view=diff
==============================================================================
--- branches/S2_5/utility/netintf.c     (original)
+++ branches/S2_5/utility/netintf.c     Thu Oct 15 19:09:56 2015
@@ -520,7 +520,8 @@
 /************************************************************************** 
   Finds the next (lowest) free port.
 **************************************************************************/ 
-int find_next_free_port(int starting_port, enum fc_addr_family family,
+int find_next_free_port(int starting_port, int highest_port,
+                        enum fc_addr_family family,
                         char *net_interface, bool not_avail_ok)
 {
   int port;
@@ -550,7 +551,7 @@
      return -1;
   }
 
-  for (port = starting_port; !found ; port++) {
+  for (port = starting_port; !found && highest_port > port; port++) {
     /* HAVE_GETADDRINFO implies IPv6 support */
 #ifdef HAVE_GETADDRINFO
     struct addrinfo hints;
@@ -630,9 +631,13 @@
 #endif /* HAVE_GETADDRINFO */
   }
 
+  if (!found) {
+    return -1;
+  }
+
   /* Rollback the last increment from the loop, back to port
    * number found to be free. */
   port--;
-  
+
   return port;
 }

Modified: branches/S2_5/utility/netintf.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/utility/netintf.h?rev=30100&r1=30099&r2=30100&view=diff
==============================================================================
--- branches/S2_5/utility/netintf.h     (original)
+++ branches/S2_5/utility/netintf.h     Thu Oct 15 19:09:56 2015
@@ -126,7 +126,8 @@
 struct fc_sockaddr_list *net_lookup_service(const char *name, int port,
                                            enum fc_addr_family family);
 fz_FILE *fc_querysocket(int sock, void *buf, size_t size);
-int find_next_free_port(int starting_port, enum fc_addr_family family,
+int find_next_free_port(int starting_port, int highest_port,
+                        enum fc_addr_family family,
                         char *net_interface, bool not_avail_ok);
 
 void sockaddr_debug(union fc_sockaddr *addr);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to