]> git.saurik.com Git - wxWidgets.git/commitdiff
Some platforms that use socklen_t don't use it for the fifth argument to
authorDavid Elliott <dfe@tgwbd.org>
Tue, 28 Dec 2004 03:17:50 +0000 (03:17 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Tue, 28 Dec 2004 03:17:50 +0000 (03:17 +0000)
getsockopt.  Do a separate test and define SOCKOPTLEN_T appropriately.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31159 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

configure.in
src/unix/gsocket.cpp

index fde8259a1f993b452573b1c892d5136966cbdbf1..6e3a733bc4a71710115854d0797d3613609fdf79 100644 (file)
@@ -5043,6 +5043,67 @@ if test "$wxUSE_SOCKETS" = "yes" ; then
         else
             AC_DEFINE_UNQUOTED(SOCKLEN_T, $wx_cv_type_getsockname3)
         fi
+        dnl Do this again for getsockopt as it may be different
+        AC_CACHE_CHECK([what is the type of the fifth argument of getsockopt],
+                       wx_cv_type_getsockopt5,
+            [
+                AC_TRY_COMPILE(
+                    [
+                        #include <sys/types.h>
+                        #include <sys/socket.h>
+                    ],
+                    [
+                        socklen_t len;
+                        getsockopt(0, 0, 0, 0, &len);
+                    ],
+                    wx_cv_type_getsockopt5=socklen_t,
+                    [
+                        dnl the compiler will compile the version with size_t
+                        dnl even if the real type of the last parameter is int
+                        dnl but it should give at least a warning about
+                        dnl converting between incompatible pointer types, so
+                        dnl try to use it to get the correct behaviour at
+                        dnl least with gcc (otherwise we'd always use size_t)
+                        CFLAGS_OLD="$CFLAGS"
+                        if test "$GCC" = yes ; then
+                            CFLAGS="$CFLAGS -Werror"
+                        fi
+
+                        AC_TRY_COMPILE(
+                            [
+                                #include <sys/types.h>
+                                #include <sys/socket.h>
+                            ],
+                            [
+                                size_t len;
+                                getsockopt(0, 0, 0, 0, &len);
+                            ],
+                            wx_cv_type_getsockopt5=size_t,
+                            AC_TRY_COMPILE(
+                                [
+                                    #include <sys/types.h>
+                                    #include <sys/socket.h>
+                                ],
+                                [
+                                    int len;
+                                    getsockopt(0, 0, 0, 0, &len);
+                                ],
+                                wx_cv_type_getsockopt5=int,
+                                wx_cv_type_getsockopt5=unknown
+                            )
+                        )
+
+                        CFLAGS="$CFLAGS_OLD"
+                    ]
+                )
+            ])
+
+        if test "$wx_cv_type_getsockopt5" = "unknown"; then
+            wxUSE_SOCKETS=no
+            AC_MSG_WARN([Couldn't find socklen_t synonym for this system])
+        else
+            AC_DEFINE_UNQUOTED(SOCKOPTLEN_T, $wx_cv_type_getsockopt5)
+        fi
         AC_LANG_POP
     fi
 fi
index e9796134eccd66125d579b21db86df9a1d60ed74..7864aa59f3e46e6a33a29e717cbca149d82e7920 100644 (file)
@@ -117,14 +117,12 @@ int _System soclose(int);
 #  endif
 #endif
 
-#else
-   /* undefine for OSX - its really an int */
-#  ifdef __DARWIN__
-#    undef SOCKLEN_T
-#    define SOCKLEN_T int
-#  endif
 #endif /* SOCKLEN_T */
 
+#ifndef SOCKOPTLEN_T
+#define SOCKOPTLEN_T SOCKLEN_T
+#endif
+
 /*
  * MSW defines this, Unices don't.
  */
@@ -698,7 +696,7 @@ GSocketError GSocket::Connect(GSocketStream stream)
       else
       {
         int error;
-        SOCKLEN_T len = sizeof(error);
+        SOCKOPTLEN_T len = sizeof(error);
 
         getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (char*) &error, &len);
 
@@ -983,7 +981,7 @@ GSocketEventFlags GSocket::Select(GSocketEventFlags flags)
       if (m_establishing && !m_server)
       {
         int error;
-        SOCKLEN_T len = sizeof(error);
+        SOCKOPTLEN_T len = sizeof(error);
 
         m_establishing = false;
 
@@ -1138,7 +1136,7 @@ void GSocket::UnsetCallback(GSocketEventFlags flags)
 GSocketError GSocket::GetSockOpt(int level, int optname,
                                 void *optval, int *optlen)
 {
-    if (getsockopt(m_fd, level, optname, (char*)optval, (SOCKLEN_T*)optlen) == 0)
+    if (getsockopt(m_fd, level, optname, (char*)optval, (SOCKOPTLEN_T*)optlen) == 0)
     {
         return GSOCK_NOERROR;
     }
@@ -1405,7 +1403,7 @@ void GSocket::Detected_Write()
   if (m_establishing && !m_server)
   {
     int error;
-    SOCKLEN_T len = sizeof(error);
+    SOCKOPTLEN_T len = sizeof(error);
 
     m_establishing = false;