bug-gnulib
[Top][All Lists]
Advanced

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

sys/socket.h on mingw32 vs socklen


From: Simon Josefsson
Subject: sys/socket.h on mingw32 vs socklen
Date: Fri, 16 Dec 2005 16:06:41 +0100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

Hi! The sys_socket module below will create a sys/socket.h file, primarily for mingw32, but it could be extended for other systems or missing sys/socket.h features in the future. This would solve the problem of accessing sys/socket.h stuff in applications. However, it does not solve the problem of accessing sys/socket.h inside autoconf tests, and in particular from the socklen module. Currently the socklen test fail on mingw32: checking for socklen_t... no checking for socklen_t equivalent... configure: error: Cannot find a type to use in place of socklen_t because: configure:3814: i586-mingw32msvc-gcc -c -g -O2 conftest.c >&5 conftest.c:23:26: sys/socket.h: No such file or directory I can think of three solutions: 0) In socklen, default the type to 'int' instead of aborting. This would be compatible with mingw32, they use 'typedef int socklen_t'. The patch below implement this. 1) Fix the socklen M4 test to check for the existence of socket.h, winsock2.h and ws2tcpip.h and include the appropriate headers when needed. This has the problem that the application will have to include the non-POSIX headers too, if they need socklen_t. The patch below implement this. 2) Create the gnulib sys/socket.h directly in the M4 macro, and set up CFLAGS to include the gnulib directory during ./configure. This has the problem that all modules invoked before the sys_socket module will not work. It seem wrong for those modules to depend on "sys_socket", because sys/socket.h is a POSIX header which most tests could assume. I think 0 and 1 should be done, together with installing the sys_socket module. Possibly, socklen should not test for ws2tcpip.h. It would still work on mingw32, but it would output a warning. I'm installing the socklen patch to GNU SASL, and the socklen patch and sys_socket module in GnuTLS now, to see how well this work in practice. What do you think? 2005-12-16 Simon Josefsson <address@hidden>

* socklen.m4: Don't abort if tests fail, warn and default to 'int'. Test for presence in ws2tcpip.h.

--- socklen.m4  03 Dec 2005 12:43:51 +0100      1.3
+++ socklen.m4  16 Dec 2005 15:59:31 +0100      
@@ -1,17 +1,18 @@
-# socklen.m4 serial 2
+# socklen.m4 serial 3
dnl Copyright (C) 2005 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

-dnl From Albert Chin.
+dnl From Albert Chin, Windows fixes from Simon Josefsson.

dnl Check for socklen_t: historically on BSD it is an int, and in
dnl POSIX 1g it is a type of its own, but some platforms use different
dnl types for the argument to getsockopt, getpeername, etc.  So we
dnl have to test to find something that will work.
AC_DEFUN([gl_TYPE_SOCKLEN_T],
-  [AC_CHECK_TYPE([socklen_t], ,
+  [AC_CHECK_HEADERS_ONCE([sys/socket.h ws2tcpip.h])
+   AC_CHECK_TYPE([socklen_t], ,
     [AC_MSG_CHECKING([for socklen_t equivalent])
      AC_CACHE_VAL([gl_cv_gl_cv_socklen_t_equiv],
        [# Systems have either "struct sockaddr *" or
@@ -21,7 +22,12 @@
           for t in int size_t "unsigned int" "long int" "unsigned long int"; do
             AC_TRY_COMPILE(
               [#include <sys/types.h>
+               #if HAVE_SYS_SOCKET_H
                #include <sys/socket.h>
+                #endif
+               #if HAVE_WS2TCPIP_H
+                # include <ws2tcpip.h>
+                #endif

                int getpeername (int, $arg2 *, $t *);],
               [$t len;
@@ -33,10 +39,16 @@
         done
      ])
      if test "$gl_cv_socklen_t_equiv" = ""; then
-       AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
+       AC_MSG_WARN([Cannot find a type to use in place of socklen_t, using 
int...])
+       gl_cv_socklen_t_equiv=int
      fi
      AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
      AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
        [type to use in place of socklen_t if not defined])],
     [#include <sys/types.h>
-      #include <sys/socket.h>])])
+      #if HAVE_SYS_SOCKET_H
+      # include <sys/socket.h>
+      #endif
+      #if HAVE_WS2TCPIP_H
+      # include <ws2tcpip.h>
+      #endif])])

Index: lib/socket_.h
===================================================================
RCS file: lib/socket_.h
diff -N lib/socket_.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/socket_.h       16 Dec 2005 15:04:41 -0000
@@ -0,0 +1,26 @@
+/* Provide a sys/socket header file for systems lacking it (read: mingw32).
+   Copyright (C) 2005 Free Software Foundation, Inc.
+   Written by Simon Josefsson.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _SYS_SOCKET_H
+#define _SYS_SOCKET_H
+
+#if HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif
+
+#endif /* _SYS_SOCKET_H */
Index: m4/sys_socket_h.m4
===================================================================
RCS file: m4/sys_socket_h.m4
diff -N m4/sys_socket_h.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ m4/sys_socket_h.m4  16 Dec 2005 15:04:41 -0000
@@ -0,0 +1,19 @@
+# sys_socket_h.m4 serial 1
+dnl Copyright (C) 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Simon Josefsson.
+
+AC_DEFUN([gl_HEADER_SYS_SOCKET],
+[
+  AC_CHECK_HEADERS_ONCE([sys/socket.h])
+  if test $ac_cv_header_sys_socket_h = yes; then
+    SYS_SOCKET_H=''
+  else
+    AC_CHECK_HEADERS_ONCE([winsock2.h])
+    SYS_SOCKET_H='sys/socket.h'
+  fi
+  AC_SUBST(SYS_SOCKET_H)
+])
Index: modules/sys_socket
===================================================================
RCS file: modules/sys_socket
diff -N modules/sys_socket
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ modules/sys_socket  16 Dec 2005 15:04:41 -0000
@@ -0,0 +1,36 @@
+Description:
+A <sys/socket.h> for systems lacking it.
+(Currently only useful for mingw32, it will simply include winsock2.h.)
+
+Files:
+lib/socket_.h
+m4/sys_socket_h.m4
+
+Depends-on:
+
+configure.ac:
+gl_HEADER_SYS_SOCKET
+
+Makefile.am:
+BUILT_SOURCES += $(SYS_SOCKET_H)
+EXTRA_DIST += socket_.h
+
+# We need the following in order to create <sys/socket.h> when the system
+# doesn't have one that works with the given compiler.
+sys/socket.h: socket_.h
+       mkdir sys
+       cp $(srcdir)/socket_.h address@hidden
+       mv address@hidden $@
+MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t
+
+mostlylocal-clean:
+       rmdir sys
+
+Include:
+#include <sys/socket.h>
+
+License:
+LGPL
+
+Maintainer:
+Simon Josefsson




reply via email to

[Prev in Thread] Current Thread [Next in Thread]