Bruno Haible <[EMAIL PROTECTED]> writes: > Simon Josefsson wrote on 2005-12-17: >> 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. > > I like this idea. So we can get rid of #if HAVE_SYS_SOCKET_H in many places.
That's another feature I didn't think of. I like it. >> 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 > > Comments should indicate for which platforms this file is meant to be useful > and on which platforms you expect <winsock2.h> to be present. (Currently only > mingw, I think?) > > Also, this should include <ws2tcpip.h>, so that socklen_t is defined > (and a type redefinition error is avoided when the user includes > <ws2tcpip.h>). I added: /* This file is supposed to be used on platforms that lack sys/socket.h. It is intended to provide definitions and prototypes needed by an application. Currently only mingw32 is supported, which has the header files winsock2.h and ws2tcpip.h that declare the sys/socket.h definitions we need. */ >> +# 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 > > Create the directory only when it does not exist. (Otherwise the user is > blocked if he happens to press Ctrl-C after the sys directory has been > created but before sys/socket.h is present.) Done. >> + cp $(srcdir)/socket_.h [EMAIL PROTECTED] >> + mv [EMAIL PROTECTED] $@ >> +MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t >> + >> +mostlylocal-clean: > > Should be mostlyclean-local, not mostlylocal-clean. Oops, thanks. >> + rmdir sys > > Remove the directory only when it exists and is empty. (Some systems create > files in your directories without being asked for, e.g. .DS_Store on MacOS X.) How do I test for that in a portable way? >> 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. > > A fourth solution is > > 3) Set some configure variables during sys_socket_h.m4 that are used in the > socklen.m4 tests. That would make socklen.m4 a bit more complex, but seem doable. I now realized that the problem I mentioned in 1) isn't really a problem. Applications that need socklen_t should probably depend on the sys/socket.h module. Perhaps the socklen_t module should depend on the sys_socket module? That would make things the easiest for the application. > Ad 0): I don't like this, because socklen_t values are passed through a > pointer, and if the argument type of getpeername() is not 'int *', the > program will break horribly. Don't make the autoconf test less reliable than > it is now. Agreed. > Ad 1): Having socklen.m4 check for ws2tcpip.h is probably unavoidable, since > it is this header file which defines socklen_t on mingw, and winsock2.h > doesn't. > But let the sys_socket_h module do the rest, and let user programs use > only <sys/socket.h>. I don't like the two gnulib modules be so tied together, > but can't see a better solution. Ok. > Ad 2): Creating a file directly from within an m4 macro looks wrong. Reasons: > - Filenames don't belong in .m4 files. > - The removal of the file must be triggered by "make distclean", i.e. from a > Makefile. Then it's more symmetrical if the file is created by the same > Makefile. Agreed. >> I think 0 and 1 should be done, together with installing the >> sys_socket module. > > I think a mix of 1) and 3) is the best. Agreed. >> Possibly, socklen should not test for ws2tcpip.h. > > I think it needs to. Unless the socklen module depend on the sys_socket module, yes. Updated patch below. I haven't fixed the rmdir problem and the socklen issue, but I believe those can be handled later. Thanks, Simon 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 9 Jan 2006 16:24:40 -0000 @@ -0,0 +1,37 @@ +/* Provide a sys/socket header file for systems lacking it (read: mingw32). + Copyright (C) 2005, 2006 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 + +/* This file is supposed to be used on platforms that lack + sys/socket.h. It is intended to provide definitions and prototypes + needed by an application. + + Currently only mingw32 is supported, which has the header files + winsock2.h and ws2tcpip.h that declare the sys/socket.h definitions + we need. */ + +#if HAVE_WINSOCK2_H +# include <winsock2.h> +#endif +#if HAVE_WS2TCPIP_H +# include <ws2tcpip.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 9 Jan 2006 16:24:40 -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 9 Jan 2006 16:24:40 -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 + test -d sys || mkdir sys + cp $(srcdir)/socket_.h [EMAIL PROTECTED] + mv [EMAIL PROTECTED] $@ +MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t + +mostlyclean-local: + rmdir sys + +Include: +#include <sys/socket.h> + +License: +LGPL + +Maintainer: +Simon Josefsson _______________________________________________ bug-gnulib mailing list bug-gnulib@gnu.org http://lists.gnu.org/mailman/listinfo/bug-gnulib