From 47a2ecab8b9f84c86a294aec0edc791dd8a1fdd2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 11 Oct 2008 15:00:33 +0200 Subject: [PATCH] New module 'shutdown'. --- ChangeLog | 11 +++++++++++ doc/posix-functions/shutdown.texi | 8 ++++---- lib/sys_socket.in.h | 17 +++++++++++++++++ lib/winsock.c | 18 ++++++++++++++++-- m4/sys_socket_h.m4 | 3 ++- modules/shutdown | 27 +++++++++++++++++++++++++++ modules/sys_socket | 1 + 7 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 modules/shutdown diff --git a/ChangeLog b/ChangeLog index ab45de15f..9793c42e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-10-11 Bruno Haible + + 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 * lib/fclose.c: Fix typo in comment: s/close/fclose/. diff --git a/doc/posix-functions/shutdown.texi b/doc/posix-functions/shutdown.texi index fb374dce5..794ddced0 100644 --- a/doc/posix-functions/shutdown.texi +++ b/doc/posix-functions/shutdown.texi @@ -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 diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h index ad0860c70..1422faeff 100644 --- a/lib/sys_socket.in.h +++ b/lib/sys_socket.in.h @@ -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 diff --git a/lib/winsock.c b/lib/winsock.c index 8a3fb3785..979360b76 100644 --- a/lib/winsock.c +++ b/lib/winsock.c @@ -42,9 +42,10 @@ #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 diff --git a/m4/sys_socket_h.m4 b/m4/sys_socket_h.m4 index e60ce7337..fc43d5c5c 100644 --- a/m4/sys_socket_h.m4 +++ b/m4/sys_socket_h.m4 @@ -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 index 000000000..e6d417814 --- /dev/null +++ b/modules/shutdown @@ -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: + + +License: +LGPLv2+ + +Maintainer: +Paolo Bonzini, Simon Josefsson, Bruno Haible diff --git a/modules/sys_socket b/modules/sys_socket index 016dedd59..553b84b70 100644 --- a/modules/sys_socket +++ b/modules/sys_socket @@ -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)' \ -- 2.11.0