glom r1453 - in branches/glom-1-6: . glom/libglom po



Author: murrayc
Date: Mon Mar 10 13:42:04 2008
New Revision: 1453
URL: http://svn.gnome.org/viewvc/glom?rev=1453&view=rev

Log:
2008-03-10  Murray Cumming  <murrayc murrayc com>

* glom/libglom/connectionpool.cc:
discover_first_free_port() Reformat the code to make the use of 
ifdefs for various platforms clearer. Include errno.h and add a comment 
about how this is essential to make the code actually work.
This stops Glom from starting a postgres instance on the same port that 
is used by an existing instance.

Modified:
   branches/glom-1-6/ChangeLog
   branches/glom-1-6/glom/libglom/connectionpool.cc
   branches/glom-1-6/po/Makefile.in.in

Modified: branches/glom-1-6/glom/libglom/connectionpool.cc
==============================================================================
--- branches/glom-1-6/glom/libglom/connectionpool.cc	(original)
+++ branches/glom-1-6/glom/libglom/connectionpool.cc	Mon Mar 10 13:42:04 2008
@@ -35,7 +35,8 @@
 
 #include <sys/types.h>
 #include <sys/socket.h> 
-#include <sys/socket.h>
+#include <errno.h>
+
 #include <netinet/in.h> //For sockaddr_in
 
 #include <signal.h> //To catch segfaults
@@ -973,31 +974,53 @@
     sa.sin_port = htons(port_to_try);
 
     const int result = bind(fd, (sockaddr*)&sa, sizeof(sa));
-    if((result == 0) || ((result < 0)
-#ifdef EADDRINUSE //Some BSDs don't have this.
-    && (errno != EADDRINUSE)
-#endif 
-#ifdef EPORTINUSE //Linux doesn't have this.
-    && (errno != EPORTINUSE)
-#endif
-    ))
+    bool available = false;
+    if(result == 0)
+       available = true;
+    else if (result < 0)
     {
-      close(fd);
+      #ifdef G_OS_WIN32
+      available = (WSAGetLastError() != WSAEADDRINUSE);
+      #endif // G_OS_WIN32
+
+      //Some BSDs don't have this.
+      //But watch out - if you don't include errno.h then this won't be 
+      //defined on Linux either, but you really do need to check for it.
+      #ifdef EADDRINUSE
+      available = (errno != EADDRINUSE);
+      #endif
+
+      #ifdef EPORTINUSE //Linux doesn't have this.
+      available = (errno != EPORTINUSE);
+      #endif
+
+      if(available)
+      {
+        #ifdef G_OS_WIN32
+        closesocket(fd);
+        #else
+        close(fd);
+        #endif //G_OS_WIN32
 
-      std::cout << "debug: ConnectionPool::discover_first_free_port(): Found: returning " << port_to_try << std::endl;
-      return port_to_try;
+        //std::cout << "debug: ConnectionPool::discover_first_free_port(): Found: returning " << port_to_try << std::endl;
+        return port_to_try;
+      }
     }
     else
     {
-      std::cout << "debug: ConnectionPool::discover_first_free_port(): port in use: " << port_to_try << std::endl;
+      //std::cout << "debug: ConnectionPool::discover_first_free_port(): port in use: " << port_to_try << std::endl;
     }
 
     ++port_to_try;
   }
 
+#ifdef G_OS_WIN32
+  closesocket(fd);
+#else
   close(fd);
+#endif
 
-  std::cout << "debug: ConnectionPool::discover_first_free_port(): No port was available." << std::endl;
+  std::cerr << "debug: ConnectionPool::discover_first_free_port(): No port was available." << std::endl;
   return 0;
 }
 #endif // !GLOM_ENABLE_CLIENT_ONLY

Modified: branches/glom-1-6/po/Makefile.in.in
==============================================================================
--- branches/glom-1-6/po/Makefile.in.in	(original)
+++ branches/glom-1-6/po/Makefile.in.in	Mon Mar 10 13:42:04 2008
@@ -1,10 +1,10 @@
 # Makefile for program source directory in GNU NLS utilities package.
 # Copyright (C) 1995, 1996, 1997 by Ulrich Drepper <drepper gnu ai mit edu>
+# Copyright (C) 2004-2008 Rodney Dawes <dobey pwns gmail com>
 #
-# This file file be copied and used freely without restrictions.  It can
-# be used in projects which are not available under the GNU Public License
+# This file may be copied and used freely without restrictions.  It may
+# be used in projects which are not available under a GNU Public License,
 # but which still want to provide support for the GNU gettext functionality.
-# Please note that the actual code is *not* freely available.
 #
 # - Modified by Owen Taylor <otaylor redhat com> to use GETTEXT_PACKAGE
 #   instead of PACKAGE and to look for po2tbl in ./ not in intl/
@@ -12,7 +12,7 @@
 # - Modified by jacob berkman <jacob ximian com> to install
 #   Makefile.in.in and po2tbl.sed.in for use with glib-gettextize
 #
-# - Modified by Rodney Dawes <dobey novell com> for use with intltool
+# - Modified by Rodney Dawes <dobey pwns gmail com> for use with intltool
 #
 # We have the following line for use by intltoolize:
 # INTLTOOL_MAKEFILE



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]