New module 'shutdown'.
authorBruno Haible <bruno@clisp.org>
Sat, 11 Oct 2008 13:00:33 +0000 (15:00 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 11 Oct 2008 13:03:20 +0000 (15:03 +0200)
ChangeLog
doc/posix-functions/shutdown.texi
lib/sys_socket.in.h
lib/winsock.c
m4/sys_socket_h.m4
modules/shutdown [new file with mode: 0644]
modules/sys_socket

index ab45de1..9793c42 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-10-11  Bruno Haible  <bruno@clisp.org>
+
+       New module 'shutdown'.
+       * modules/shutdown: New file.
+       * lib/sys_socket.in.h (shutdown): New declaration.
+       * lib/winsock.c (shutdown): New function.
+       * m4/sys_socket_h.m4 (gl_SYS_SOCKET_H_DEFAULTS): Initialize
+       GNULIB_SHUTDOWN.
+       * modules/sys_socket (Makefile.am): Substitute GNULIB_SHUTDOWN.
+       * doc/posix-functions/shutdown.texi: Document the new module.
+
 2008-10-11  Jim Meyering  <meyering@redhat.com>
 
        * lib/fclose.c: Fix typo in comment: s/close/fclose/.
index fb374dc..794ddce 100644 (file)
@@ -4,15 +4,15 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/shutdown.html}
 
-Gnulib module: ---
+Gnulib module: shutdown
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+On Windows platforms (excluding Cygwin), error codes for @code{shutdown} are
+not placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-mingw.
 @end itemize
index ad0860c..1422fae 100644 (file)
@@ -364,6 +364,23 @@ extern int rpl_setsockopt (int, int, int, const void *, int);
       setsockopt (s, lvl, o, v, l))
 # endif
 
+# if @GNULIB_SHUTDOWN@
+#  if @HAVE_WINSOCK2_H@
+#   undef shutdown
+#   define shutdown            rpl_shutdown
+extern int rpl_shutdown (int, int);
+#  endif
+# elif @HAVE_WINSOCK2_H@
+#  undef shutdown
+#  define shutdown shutdown_used_without_requesting_gnulib_module_shutdown
+# elif defined GNULIB_POSIXCHECK
+#  undef shutdown
+#  define shutdown(s,h) \
+     (GL_LINK_WARNING ("shutdown is not always POSIX compliant - " \
+                       "use gnulib module shutdown for portability"), \
+      shutdown (s, h))
+# endif
+
 # if @HAVE_WINSOCK2_H@
 #  undef select
 #  define select               select_used_without_including_sys_select_h
index 8a3fb37..979360b 100644 (file)
 #undef recvfrom
 #undef sendto
 #undef setsockopt
+#undef shutdown
 
-# define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
-# define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
+#define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
+#define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
 
 
 static inline void
@@ -332,3 +333,16 @@ rpl_setsockopt (int fd, int level, int optname, const void *optval, int optlen)
   return r;
 }
 #endif
+
+#if GNULIB_SHUTDOWN
+int
+rpl_shutdown (int fd, int how)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = shutdown (sock, how);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
+#endif
index e60ce73..fc43d5c 100644 (file)
@@ -1,4 +1,4 @@
-# sys_socket_h.m4 serial 10
+# sys_socket_h.m4 serial 11
 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,
@@ -115,4 +115,5 @@ AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
   GNULIB_RECVFROM=0;    AC_SUBST([GNULIB_RECVFROM])
   GNULIB_SENDTO=0;      AC_SUBST([GNULIB_SENDTO])
   GNULIB_SETSOCKOPT=0;  AC_SUBST([GNULIB_SETSOCKOPT])
+  GNULIB_SHUTDOWN=0;    AC_SUBST([GNULIB_SHUTDOWN])
 ])
diff --git a/modules/shutdown b/modules/shutdown
new file mode 100644 (file)
index 0000000..e6d4178
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+shutdown() function: initiate a graceful shutdown of a socket.
+
+Files:
+lib/winsock.c
+
+Depends-on:
+sys_socket
+errno
+
+configure.ac:
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([winsock])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([shutdown])
+
+Makefile.am:
+
+Include:
+<sys/socket.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Paolo Bonzini, Simon Josefsson, Bruno Haible
index 016dedd..553b84b 100644 (file)
@@ -45,6 +45,7 @@ sys/socket.h: sys_socket.in.h
              -e 's|@''GNULIB_RECVFROM''@|$(GNULIB_RECVFROM)|g' \
              -e 's|@''GNULIB_SENDTO''@|$(GNULIB_SENDTO)|g' \
              -e 's|@''GNULIB_SETSOCKOPT''@|$(GNULIB_SETSOCKOPT)|g' \
+             -e 's|@''GNULIB_SHUTDOWN''@|$(GNULIB_SHUTDOWN)|g' \
              -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
              -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \