[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] use gnulib modules close (new) and open to hook into open/cl
From: |
Bruno Haible |
Subject: |
Re: [PATCH] use gnulib modules close (new) and open to hook into open/close |
Date: |
Fri, 10 Oct 2008 00:26:06 +0200 |
User-agent: |
KMail/1.5.4 |
And this is part 5.
2008-10-09 Paolo Bonzini <address@hidden>
Bruno Haible <address@hidden>
Combine the two replacements of 'close'.
* lib/sys_socket.in.h (close): Define to a reminder to include
<unistd.h>.
(_gl_close_fd_maybe_socket): New declaration.
(HAVE__GL_CLOSE_FD_MAYBE_SOCKET): New macro.
* lib/winsock.c (close): Remove undefinition.
(_gl_close_fd_maybe_socket): Renamed from rpl_close. Define only when
needed for the gnulib module 'close'.
* lib/unistd.in.h (close): If the gnulib module 'close' is not used,
define to an error symbol or to a warning, if suitable.
* lib/close.c: Include <sys/socket.h>.
(rpl_close): Invoke _gl_close_fd_maybe_socket when gnulib defines it.
* m4/sys_socket_h.m4 (gl_PREREQ_SYS_H_WINSOCK2): Set also
UNISTD_H_HAVE_WINSOCK2_H.
(gl_SYS_SOCKET_H_DEFAULTS): Require gl_UNISTD_H_DEFAULTS.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize
UNISTD_H_HAVE_WINSOCK2_H.
* modules/sys_socket (Files): Add m4/unistd_h.m4.
(configure.ac): Set a module indicator.
(Makefile.am): Substitute GNULIB_CLOSE.
* modules/unistd (Makefile.am): Substitute UNISTD_H_HAVE_WINSOCK2_H.
* modules/poll-tests (Depends-on): Add close.
* modules/select-tests (Depends-on): Likewise.
--- lib/sys_socket.in.h.orig 2008-10-10 00:13:54.000000000 +0200
+++ lib/sys_socket.in.h 2008-10-10 00:09:22.000000000 +0200
@@ -138,10 +138,9 @@
/* Wrap everything else to use libc file descriptors for sockets. */
-# if @HAVE_WINSOCK2_H@
+# if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
# undef close
-# define close rpl_close
-extern int rpl_close(int);
+# define close close_used_without_including_unistd_h
# endif
# if @GNULIB_SOCKET@
@@ -376,6 +375,12 @@
# define select select_used_without_including_sys_select_h
# endif
+# if @GNULIB_CLOSE@ && @HAVE_WINSOCK2_H@
+/* gnulib internal function. */
+# define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
+extern int _gl_close_fd_maybe_socket (int fd);
+# endif
+
# ifdef __cplusplus
}
# endif
--- lib/winsock.c.orig 2008-10-10 00:13:54.000000000 +0200
+++ lib/winsock.c 2008-10-10 00:10:49.000000000 +0200
@@ -25,7 +25,6 @@
#include <io.h>
#include <sys/socket.h>
-#undef close
#undef socket
#undef connect
#undef accept
@@ -44,10 +43,11 @@
# define SOCKET_TO_FD(fh) (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
-/* Wrappers for libc functions. */
+/* Hook for gnulib module close. */
+#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
int
-rpl_close (int fd)
+_gl_close_fd_maybe_socket (int fd)
{
SOCKET sock = FD_TO_SOCKET (fd);
WSANETWORKEVENTS ev;
@@ -67,6 +67,7 @@
else
return _close (fd);
}
+#endif
/* Wrappers for WinSock functions. */
--- lib/unistd.in.h.orig 2008-10-10 00:13:54.000000000 +0200
+++ lib/unistd.in.h 2008-10-10 00:09:57.000000000 +0200
@@ -82,6 +82,15 @@
# define close rpl_close
extern int close (int);
# endif
+#elif @UNISTD_H_HAVE_WINSOCK2_H@
+# undef close
+# define close close_used_without_requesting_gnulib_module_close
+#elif defined GNULIB_POSIXCHECK
+# undef close
+# define close(f) \
+ (GL_LINK_WARNING ("close does not portably work on sockets - " \
+ "use gnulib module close for portability"), \
+ close (f))
#endif
--- lib/close.c.orig 2008-10-10 00:13:53.000000000 +0200
+++ lib/close.c 2008-10-10 00:08:25.000000000 +0200
@@ -19,6 +19,10 @@
/* Specification. */
#include <unistd.h>
+#if GNULIB_SYS_SOCKET
+# include <sys/socket.h>
+#endif
+
/* Override close() to call into other gnulib modules. */
@@ -26,7 +30,11 @@
rpl_close (int fd)
#undef close
{
+#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
+ int retval = _gl_close_fd_maybe_socket (fd);
+#else
int retval = close (fd);
+#endif
#ifdef FCHDIR_REPLACEMENT
if (retval >= 0)
--- m4/sys_socket_h.m4.orig 2008-10-10 00:13:54.000000000 +0200
+++ m4/sys_socket_h.m4 2008-10-10 00:11:58.000000000 +0200
@@ -1,4 +1,4 @@
-# sys_socket_h.m4 serial 8
+# sys_socket_h.m4 serial 9
dnl Copyright (C) 2005-2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -71,6 +71,7 @@
# Sets and substitutes HAVE_WINSOCK2_H.
AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
[
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
AC_CHECK_HEADERS_ONCE([sys/socket.h])
if test $ac_cv_header_sys_socket_h != yes; then
dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
@@ -81,6 +82,7 @@
fi
if test "$ac_cv_header_winsock2_h" = yes; then
HAVE_WINSOCK2_H=1
+ UNISTD_H_HAVE_WINSOCK2_H=1
else
HAVE_WINSOCK2_H=0
fi
@@ -97,6 +99,7 @@
AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
[
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for GNULIB_CLOSE
GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET])
GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT])
GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT])
--- m4/unistd_h.m4.orig 2008-10-10 00:13:54.000000000 +0200
+++ m4/unistd_h.m4 2008-10-10 00:12:21.000000000 +0200
@@ -69,4 +69,5 @@
REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK])
REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE])
+ UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H])
])
--- modules/sys_socket.orig 2008-10-10 00:13:54.000000000 +0200
+++ modules/sys_socket 2008-10-10 00:13:00.000000000 +0200
@@ -6,6 +6,7 @@
lib/winsock.c
m4/sys_socket_h.m4
m4/sockpfaf.m4
+m4/unistd_h.m4
Depends-on:
include_next
@@ -14,6 +15,7 @@
configure.ac:
gl_HEADER_SYS_SOCKET
+gl_MODULE_INDICATOR([sys_socket])
AC_PROG_MKDIR_P
Makefile.am:
@@ -28,6 +30,7 @@
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
-e 's|@''NEXT_SYS_SOCKET_H''@|$(NEXT_SYS_SOCKET_H)|g' \
-e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \
+ -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \
-e 's|@''GNULIB_SOCKET''@|$(GNULIB_SOCKET)|g' \
-e 's|@''GNULIB_CONNECT''@|$(GNULIB_CONNECT)|g' \
-e 's|@''GNULIB_ACCEPT''@|$(GNULIB_ACCEPT)|g' \
--- modules/unistd.orig 2008-10-10 00:13:54.000000000 +0200
+++ modules/unistd 2008-10-10 00:13:20.000000000 +0200
@@ -60,6 +60,7 @@
-e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
-e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
-e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \
+ -e
's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \
-e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
< $(srcdir)/unistd.in.h; \
} > address@hidden
--- modules/poll-tests.orig 2008-10-10 00:13:54.000000000 +0200
+++ modules/poll-tests 2008-10-10 00:12:36.000000000 +0200
@@ -17,6 +17,7 @@
listen
connect
accept
+close
configure.ac:
AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h])
--- modules/select-tests.orig 2008-10-10 00:13:54.000000000 +0200
+++ modules/select-tests 2008-10-10 00:12:36.000000000 +0200
@@ -16,6 +16,7 @@
listen
connect
accept
+close
configure.ac:
- [PATCH] use gnulib modules close (new) and open to hook into open/close, Paolo Bonzini, 2008/10/07
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Simon Josefsson, 2008/10/08
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Bruno Haible, 2008/10/08
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Simon Josefsson, 2008/10/09
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Paolo Bonzini, 2008/10/09
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Bruno Haible, 2008/10/09
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Bruno Haible, 2008/10/09
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Bruno Haible, 2008/10/09
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Bruno Haible, 2008/10/09
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close,
Bruno Haible <=
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Bruno Haible, 2008/10/09
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Bruno Haible, 2008/10/11
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Paolo Bonzini, 2008/10/11
- Re: [PATCH] use gnulib modules close (new) and open to hook into open/close, Bruno Haible, 2008/10/09