Split winsock.c into many smaller files.
authorSimon Josefsson <simon@josefsson.org>
Tue, 21 Oct 2008 10:17:19 +0000 (12:17 +0200)
committerSimon Josefsson <simon@josefsson.org>
Tue, 21 Oct 2008 10:17:19 +0000 (12:17 +0200)
* lib/close.c: Add _gl_close_fd_maybe_socket from winsock.c.
* lib/accept.c: New file, based on winsock.c.
* lib/bind.c: New file, based on winsock.c.
* lib/connect.c: New file, based on winsock.c.
* lib/getpeername.c: New file, based on winsock.c.
* lib/getsockname.c: New file, based on winsock.c.
* lib/getsockopt.c: New file, based on winsock.c.
* lib/ioctl.c: New file, based on winsock.c.
* lib/listen.c: New file, based on winsock.c.
* lib/recv.c: New file, based on winsock.c.
* lib/recvfrom.c: New file, based on winsock.c.
* lib/send.c: New file, based on winsock.c.
* lib/sendto.c: New file, based on winsock.c.
* lib/setsockopt.c: New file, based on winsock.c.
* lib/shutdown.c: New file, based on winsock.c.
* lib/socket.c: New file, based on winsock.c.
* lib/w32sock.h: New file, based on winsock.c.
* lib/winsock.c: Remove file.
* modules/accept: Likewise.
* modules/bind: Likewise.
* modules/connect: Likewise.
* modules/getpeername: Likewise.
* modules/getsockname: Likewise.
* modules/getsockopt: Likewise.
* modules/ioctl: Likewise.
* modules/listen: Likewise.
* modules/recv: Likewise.
* modules/recvfrom: Likewise.
* modules/send: Likewise.
* modules/sendto: Likewise.
* modules/setsockopt: Likewise.
* modules/shutdown: Likewise.
* modules/socket: Use socket.c instead of winsock.c.
* modules/sys_socket: Remove (unneeded?) dependency on winsock.c.
* doc/posix-functions/accept.texi: Doc fix.
* doc/posix-functions/bind.texi: Doc fix.
* doc/posix-functions/close.texi: Doc fix.
* doc/posix-functions/connect.texi: Doc fix.
* doc/posix-functions/getpeername.texi: Doc fix.
* doc/posix-functions/getsockname.texi: Doc fix.
* doc/posix-functions/getsockopt.texi: Doc fix.
* doc/posix-functions/ioctl.texi: Doc fix.
* doc/posix-functions/listen.texi: Doc fix.
* doc/posix-functions/recv.texi: Doc fix.
* doc/posix-functions/recvfrom.texi: Doc fix.
* doc/posix-functions/send.texi: Doc fix.
* doc/posix-functions/sendto.texi: Doc fix.
* doc/posix-functions/setsockopt.texi: Doc fix.
* doc/posix-functions/shutdown.texi: Doc fix.
* doc/posix-functions/socket.texi: Doc fix.

51 files changed:
ChangeLog
doc/posix-functions/accept.texi
doc/posix-functions/bind.texi
doc/posix-functions/close.texi
doc/posix-functions/connect.texi
doc/posix-functions/getpeername.texi
doc/posix-functions/getsockname.texi
doc/posix-functions/getsockopt.texi
doc/posix-functions/ioctl.texi
doc/posix-functions/listen.texi
doc/posix-functions/recv.texi
doc/posix-functions/recvfrom.texi
doc/posix-functions/send.texi
doc/posix-functions/sendto.texi
doc/posix-functions/setsockopt.texi
doc/posix-functions/shutdown.texi
doc/posix-functions/socket.texi
lib/accept.c [new file with mode: 0644]
lib/bind.c [new file with mode: 0644]
lib/close.c
lib/connect.c [new file with mode: 0644]
lib/getpeername.c [new file with mode: 0644]
lib/getsockname.c [new file with mode: 0644]
lib/getsockopt.c [new file with mode: 0644]
lib/ioctl.c [new file with mode: 0644]
lib/listen.c [new file with mode: 0644]
lib/recv.c [new file with mode: 0644]
lib/recvfrom.c [new file with mode: 0644]
lib/send.c [new file with mode: 0644]
lib/sendto.c [new file with mode: 0644]
lib/setsockopt.c [new file with mode: 0644]
lib/shutdown.c [new file with mode: 0644]
lib/socket.c [new file with mode: 0644]
lib/w32sock.h [new file with mode: 0644]
lib/winsock.c [deleted file]
modules/accept
modules/bind
modules/connect
modules/getpeername
modules/getsockname
modules/getsockopt
modules/ioctl
modules/listen
modules/recv
modules/recvfrom
modules/send
modules/sendto
modules/setsockopt
modules/shutdown
modules/socket
modules/sys_socket

index 86b9c189e058e7157bff6c3f2712e9b4ec5cb54c..d151664afc37ea6ff29b8351c55cce6277381836 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,56 @@
+2008-10-21  Simon Josefsson  <simon@josefsson.org>
+
+       * lib/close.c: Add _gl_close_fd_maybe_socket from winsock.c.
+       * lib/accept.c: New file, based on winsock.c.
+       * lib/bind.c: New file, based on winsock.c.
+       * lib/connect.c: New file, based on winsock.c.
+       * lib/getpeername.c: New file, based on winsock.c.
+       * lib/getsockname.c: New file, based on winsock.c.
+       * lib/getsockopt.c: New file, based on winsock.c.
+       * lib/ioctl.c: New file, based on winsock.c.
+       * lib/listen.c: New file, based on winsock.c.
+       * lib/recv.c: New file, based on winsock.c.
+       * lib/recvfrom.c: New file, based on winsock.c.
+       * lib/send.c: New file, based on winsock.c.
+       * lib/sendto.c: New file, based on winsock.c.
+       * lib/setsockopt.c: New file, based on winsock.c.
+       * lib/shutdown.c: New file, based on winsock.c.
+       * lib/socket.c: New file, based on winsock.c.
+       * lib/w32sock.h: New file, based on winsock.c.
+       * lib/winsock.c: Remove file.
+       * modules/accept: Likewise.
+       * modules/bind: Likewise.
+       * modules/connect: Likewise.
+       * modules/getpeername: Likewise.
+       * modules/getsockname: Likewise.
+       * modules/getsockopt: Likewise.
+       * modules/ioctl: Likewise.
+       * modules/listen: Likewise.
+       * modules/recv: Likewise.
+       * modules/recvfrom: Likewise.
+       * modules/send: Likewise.
+       * modules/sendto: Likewise.
+       * modules/setsockopt: Likewise.
+       * modules/shutdown: Likewise.
+       * modules/socket: Use socket.c instead of winsock.c.
+       * modules/sys_socket: Remove (unneeded?) dependency on winsock.c.
+       * doc/posix-functions/accept.texi: Doc fix.
+       * doc/posix-functions/bind.texi: Doc fix.
+       * doc/posix-functions/close.texi: Doc fix.
+       * doc/posix-functions/connect.texi: Doc fix.
+       * doc/posix-functions/getpeername.texi: Doc fix.
+       * doc/posix-functions/getsockname.texi: Doc fix.
+       * doc/posix-functions/getsockopt.texi: Doc fix.
+       * doc/posix-functions/ioctl.texi: Doc fix.
+       * doc/posix-functions/listen.texi: Doc fix.
+       * doc/posix-functions/recv.texi: Doc fix.
+       * doc/posix-functions/recvfrom.texi: Doc fix.
+       * doc/posix-functions/send.texi: Doc fix.
+       * doc/posix-functions/sendto.texi: Doc fix.
+       * doc/posix-functions/setsockopt.texi: Doc fix.
+       * doc/posix-functions/shutdown.texi: Doc fix.
+       * doc/posix-functions/socket.texi: Doc fix.
+
 2008-10-20  Bruno Haible  <bruno@clisp.org>
 
        Take into account the role of SIGABRT_COMPAT on Windows 2008.
index 18ddee7652de9b8f849872c0e518317d0b96aa49..99d539c3dbd5d29ffec263772aa598a6c615f63b 100644 (file)
@@ -14,8 +14,9 @@ the @code{accept} function can not be used in calls to @code{read},
 @code{write}, and @code{close}; you have to use @code{recv}, @code{send},
 @code{closesocket} in these cases instead.
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for @code{accept}
+are not placed in @code{errno}, and @code{WSAGetLastError} must be
+used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 0be155311a427993fd339859ed4a453471859770..ca629d3e7d18647560ad6d3b101945af033eb21f 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: bind
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for @code{bind}
+are not placed in @code{errno}, and @code{WSAGetLastError} must be
+used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 252caea61673512c34f0fef787a66eeb41e1ca02..7065efaca237846b30d0de722029a8d56f9b66d0 100644 (file)
@@ -12,6 +12,10 @@ Portability problems fixed by Gnulib:
 On Windows platforms (excluding Cygwin), @code{socket} and @code{accept}
 do not return file descriptors that can be closed by @code{close}.
 Instead, @code{closesocket} must be used.
+@item
+On Windows platforms (excluding Cygwin), error codes for @code{close}
+are not placed in @code{errno}, and @code{WSAGetLastError} must be
+used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index fe03a0b7546efdddc0d7b1f6acad34df7e77d3ca..8676055fda99f86dd21418cabaf5d1739530a9ee 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: connect
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for
+@code{connect} are not placed in @code{errno}, and
+@code{WSAGetLastError} must be used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 753533e50b470015b9ed89b0c057c2517ecb30c8..8fc7caaa4eba636d409453dfcb27e5451595a8db 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: getpeername
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for
+@code{getpeername} are not placed in @code{errno}, and
+@code{WSAGetLastError} must be used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index f8aadcb20dab4b74c6750e9936c3c590ab065d7a..ba9103e05935c512386f05c168b531f036ab4893 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: getsockname
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for
+@code{getsockname} are not placed in @code{errno}, and
+@code{WSAGetLastError} must be used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index c77617c9b408fdb16e613772e7fa4b461bf8c046..8197f3bf0ad6b487a63a9b7f8598738fa1115df7 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: getsockopt
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for
+@code{getsockopt} are not placed in @code{errno}, and
+@code{WSAGetLastError} must be used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 123069b8ccc783f330a8b9a11aa1d2422aa44867..85ba764a42f9daa3053ec1fa28790e77af70eb38 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: ioctl
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for @code{ioctl}
+are not placed in @code{errno}, and @code{WSAGetLastError} must be
+used instead.
 @item
 @code{ioctl} is called @code{ioctlsocket} under mingw
 @end itemize
index 176c56d5d96b2583fbc0341c52ba00468a59e0a9..3b19d18747fd2b7e90228240284b1ace27b41fbf 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: listen
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for @code{listen}
+are not placed in @code{errno}, and @code{WSAGetLastError} must be
+used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 63c3e0da0d3a8c08c677bb4d2f7d619803a0b724..ec664b8e22e4ed19b02c05bfa48c855b587eb408 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: recv
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for @code{recv}
+are not placed in @code{errno}, and @code{WSAGetLastError} must be
+used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 78e4c575b98e7aab4903450547984a81f1f0f765..0097fd411998b41036d05106f96822abda8b0e4d 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: recvfrom
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for
+@code{recvfrom} are not placed in @code{errno}, and
+@code{WSAGetLastError} must be used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index d9d8dedf6c8e232f3187eb142a77d01cf850ee6f..749f8da671b23d74979d7ca79080d95676f3070c 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: send
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for @code{send}
+are not placed in @code{errno}, and @code{WSAGetLastError} must be
+used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index e8b9083d73fcc97f8ea10c737a5c835e07683925..fa627397fe6f1f46b353aa1bb1cecfd82b903313 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: sendto
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for @code{sendto}
+are not placed in @code{errno}, and @code{WSAGetLastError} must be
+used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 5d05f8740a05453b8566754e5ffe6cf0f8b50ed4..0384e9a0e6c8f3152624c4897b711c0c21ff792e 100644 (file)
@@ -9,8 +9,9 @@ Gnulib module: setsockopt
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for
+@code{setsockopt} are not placed in @code{errno}, and
+@code{WSAGetLastError} must be used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 794ddced0f72f48e70aa6a087f56186cadb484bd..4fc8194a79659f8a4c56770844483a941a682bf2 100644 (file)
@@ -9,8 +9,9 @@ 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.
+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:
index 8b2f0b41f4c89520561f27ba5391e2de68a029a4..e07a70245e5b81c462cb9a61670f26705923e6f0 100644 (file)
@@ -14,8 +14,9 @@ the @code{socket} function can not be used in calls to @code{read},
 @code{write}, and @code{close}; you have to use @code{recv}, @code{send},
 @code{closesocket} in these cases instead.
 @item
-On Windows platforms (excluding Cygwin), error codes for @code{accept} are not
-placed in @code{errno}, and @code{WSAGetLastError} must be used instead.
+On Windows platforms (excluding Cygwin), error codes for @code{socket}
+are not placed in @code{errno}, and @code{WSAGetLastError} must be
+used instead.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/accept.c b/lib/accept.c
new file mode 100644 (file)
index 0000000..ae46537
--- /dev/null
@@ -0,0 +1,42 @@
+/* accept.c --- wrappers for Windows accept function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef accept
+
+int
+rpl_accept (int fd, struct sockaddr *addr, int *addrlen)
+{
+  SOCKET fh = accept (FD_TO_SOCKET (fd), addr, addrlen);
+  if (fh == INVALID_SOCKET)
+    {
+      set_winsock_errno ();
+      return -1;
+    }
+  else
+    return SOCKET_TO_FD (fh);
+}
diff --git a/lib/bind.c b/lib/bind.c
new file mode 100644 (file)
index 0000000..108a239
--- /dev/null
@@ -0,0 +1,40 @@
+/* bind.c --- wrappers for Windows bind function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef bind
+
+int
+rpl_bind (int fd, struct sockaddr *sockaddr, int len)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = bind (sock, sockaddr, len);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
index 9b050668a8ba9dc3e6b936ec83843ed48910fa34..79313c0082c29519f09415037012581c25a46e66 100644 (file)
 #include <unistd.h>
 
 #if GNULIB_SYS_SOCKET
+# define WIN32_LEAN_AND_MEAN
 # include <sys/socket.h>
 #endif
 
+#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+int
+_gl_close_fd_maybe_socket (int fd)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  WSANETWORKEVENTS ev;
+
+  ev.lNetworkEvents = 0xDEADBEEF;
+  WSAEnumNetworkEvents (sock, NULL, &ev);
+  if (ev.lNetworkEvents != 0xDEADBEEF)
+    {
+      /* FIXME: other applications, like squid, use an undocumented
+        _free_osfhnd free function.  But this is not enough: The 'osfile'
+        flags for fd also needs to be cleared, but it is hard to access it.
+        Instead, here we just close twice the file descriptor.  */
+      if (closesocket (sock))
+       {
+         set_winsock_errno ();
+         return -1;
+       }
+      else
+       {
+         /* This call frees the file descriptor and does a
+            CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails.  */
+         _close (fd);
+         return 0;
+       }
+    }
+  else
+    return _close (fd);
+}
+#endif
 
 /* Override close() to call into other gnulib modules.  */
 
diff --git a/lib/connect.c b/lib/connect.c
new file mode 100644 (file)
index 0000000..c7abf20
--- /dev/null
@@ -0,0 +1,47 @@
+/* connect.c --- wrappers for Windows connect function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef connect
+
+int
+rpl_connect (int fd, struct sockaddr *sockaddr, int len)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = connect (sock, sockaddr, len);
+  if (r < 0)
+    {
+      /* EINPROGRESS is not returned by WinSock 2.0; for backwards
+        compatibility, connect(2) uses EWOULDBLOCK.  */
+      if (WSAGetLastError () == WSAEWOULDBLOCK)
+       WSASetLastError (WSAEINPROGRESS);
+
+      set_winsock_errno ();
+    }
+
+  return r;
+}
diff --git a/lib/getpeername.c b/lib/getpeername.c
new file mode 100644 (file)
index 0000000..83491cb
--- /dev/null
@@ -0,0 +1,40 @@
+/* getpeername.c --- wrappers for Windows getpeername function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef getpeername
+
+int
+rpl_getpeername (int fd, struct sockaddr *addr, int *addrlen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = getpeername (sock, addr, addrlen);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/lib/getsockname.c b/lib/getsockname.c
new file mode 100644 (file)
index 0000000..97b8e8c
--- /dev/null
@@ -0,0 +1,40 @@
+/* getsockname.c --- wrappers for Windows getsockname function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef getsockname
+
+int
+rpl_getsockname (int fd, struct sockaddr *addr, int *addrlen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = getsockname (sock, addr, addrlen);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/lib/getsockopt.c b/lib/getsockopt.c
new file mode 100644 (file)
index 0000000..7be8bed
--- /dev/null
@@ -0,0 +1,40 @@
+/* getsockopt.c --- wrappers for Windows getsockopt function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef getsockopt
+
+int
+rpl_getsockopt (int fd, int level, int optname, void *optval, int *optlen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = getsockopt (sock, level, optname, optval, optlen);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/lib/ioctl.c b/lib/ioctl.c
new file mode 100644 (file)
index 0000000..98a94b6
--- /dev/null
@@ -0,0 +1,51 @@
+/* ioctl.c --- wrappers for Windows ioctl function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#include <stdarg.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef ioctl
+
+int
+rpl_ioctl (int fd, int req, ...)
+{
+  void *buf;
+  va_list args;
+  SOCKET sock;
+  int r;
+
+  va_start (args, req);
+  buf = va_arg (args, void *);
+  va_end (args);
+
+  sock = FD_TO_SOCKET (fd);
+  r = ioctlsocket (sock, req, buf);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/lib/listen.c b/lib/listen.c
new file mode 100644 (file)
index 0000000..49e0a08
--- /dev/null
@@ -0,0 +1,40 @@
+/* listen.c --- wrappers for Windows listen function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef listen
+
+int
+rpl_listen (int fd, int backlog)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = listen (sock, backlog);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/lib/recv.c b/lib/recv.c
new file mode 100644 (file)
index 0000000..78c0461
--- /dev/null
@@ -0,0 +1,40 @@
+/* recv.c --- wrappers for Windows recv function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef recv
+
+int
+rpl_recv (int fd, void *buf, int len, int flags)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = recv (sock, buf, len, flags);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/lib/recvfrom.c b/lib/recvfrom.c
new file mode 100644 (file)
index 0000000..52fa3c8
--- /dev/null
@@ -0,0 +1,48 @@
+/* recvfrom.c --- wrappers for Windows recvfrom function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef recvfrom
+
+int
+rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from,
+             int *fromlen)
+{
+  int frombufsize = *fromlen;
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = recvfrom (sock, buf, len, flags, from, fromlen);
+
+  if (r < 0)
+    set_winsock_errno ();
+
+  /* Winsock recvfrom() only returns a valid 'from' when the socket is
+     connectionless.  POSIX gives a valid 'from' for all types of sockets.  */
+  else if (*fromlen == frombufsize)
+    rpl_getpeername (fd, from, fromlen);
+
+  return r;
+}
diff --git a/lib/send.c b/lib/send.c
new file mode 100644 (file)
index 0000000..4d2ca16
--- /dev/null
@@ -0,0 +1,40 @@
+/* send.c --- wrappers for Windows send function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef send
+
+int
+rpl_send (int fd, const void *buf, int len, int flags)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = send (sock, buf, len, flags);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/lib/sendto.c b/lib/sendto.c
new file mode 100644 (file)
index 0000000..888b0f6
--- /dev/null
@@ -0,0 +1,41 @@
+/* sendto.c --- wrappers for Windows sendto function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef sendto
+
+int
+rpl_sendto (int fd, const void *buf, int len, int flags,
+           struct sockaddr *to, int tolen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = sendto (sock, buf, len, flags, to, tolen);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/lib/setsockopt.c b/lib/setsockopt.c
new file mode 100644 (file)
index 0000000..09f048e
--- /dev/null
@@ -0,0 +1,40 @@
+/* setsockopt.c --- wrappers for Windows setsockopt function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef setsockopt
+
+int
+rpl_setsockopt (int fd, int level, int optname, const void *optval, int optlen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = setsockopt (sock, level, optname, optval, optlen);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/lib/shutdown.c b/lib/shutdown.c
new file mode 100644 (file)
index 0000000..290d706
--- /dev/null
@@ -0,0 +1,40 @@
+/* shutdown.c --- wrappers for Windows shutdown function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef 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;
+}
diff --git a/lib/socket.c b/lib/socket.c
new file mode 100644 (file)
index 0000000..f14906a
--- /dev/null
@@ -0,0 +1,45 @@
+/* socket.c --- wrappers for Windows socket function
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef socket
+
+int
+rpl_socket (int domain, int type, int protocol)
+{
+  /* We have to use WSASocket() to create non-overlapped IO sockets.
+     Overlapped IO sockets cannot be used with read/write.  */
+  SOCKET fh = WSASocket (domain, type, protocol, NULL, 0, 0);
+
+  if (fh == INVALID_SOCKET)
+    {
+      set_winsock_errno ();
+      return -1;
+    }
+  else
+    return SOCKET_TO_FD (fh);
+}
diff --git a/lib/w32sock.h b/lib/w32sock.h
new file mode 100644 (file)
index 0000000..0622985
--- /dev/null
@@ -0,0 +1,62 @@
+/* w32sock.h --- internal auxilliary functions for Windows socket functions
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <errno.h>
+
+/* Get O_RDWR and O_BINARY.  */
+#include <fcntl.h>
+
+/* Get _get_osfhandle() and _open_osfhandle().  */
+#include <io.h>
+
+#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
+set_winsock_errno (void)
+{
+  int err = WSAGetLastError ();
+  WSASetLastError (0);
+
+  /* Map some WSAE* errors to the runtime library's error codes.  */
+  switch (err)
+    {
+    case WSA_INVALID_HANDLE:
+      errno = EBADF;
+      break;
+    case WSA_NOT_ENOUGH_MEMORY:
+      errno = ENOMEM;
+      break;
+    case WSA_INVALID_PARAMETER:
+      errno = EINVAL;
+      break;
+    case WSAEWOULDBLOCK:
+      errno = EWOULDBLOCK;
+      break;
+    case WSAENAMETOOLONG:
+      errno = ENAMETOOLONG;
+      break;
+    case WSAENOTEMPTY:
+      errno = ENOTEMPTY;
+      break;
+    default:
+      errno = (err > 10000 && err < 10025) ? err - 10000 : err;
+      break;
+    }
+}
diff --git a/lib/winsock.c b/lib/winsock.c
deleted file mode 100644 (file)
index 979360b..0000000
+++ /dev/null
@@ -1,348 +0,0 @@
-/* winsock.c --- wrappers for Windows socket functions
-
-   Copyright (C) 2008 Free Software Foundation, Inc.
-
-   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
-
-/* Written by Paolo Bonzini */
-
-#include <config.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <io.h>
-#include <sys/socket.h>
-#if GNULIB_IOCTL
-#include <sys/ioctl.h>
-#endif
-
-#undef socket
-#undef connect
-#undef accept
-#undef bind
-#undef getpeername
-#undef getsockname
-#undef getsockopt
-#undef listen
-#undef recv
-#undef send
-#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))
-
-
-static inline void
-set_winsock_errno (void)
-{
-  int err = WSAGetLastError ();
-  WSASetLastError (0);
-
-  /* Map some WSAE* errors to the runtime library's error codes.  */
-  switch (err)
-    {
-    case WSA_INVALID_HANDLE:
-      errno = EBADF;
-      break;
-    case WSA_NOT_ENOUGH_MEMORY:
-      errno = ENOMEM;
-      break;
-    case WSA_INVALID_PARAMETER:
-      errno = EINVAL;
-      break;
-    case WSAEWOULDBLOCK:
-      errno = EWOULDBLOCK;
-      break;
-    case WSAENAMETOOLONG:
-      errno = ENAMETOOLONG;
-      break;
-    case WSAENOTEMPTY:
-      errno = ENOTEMPTY;
-      break;
-    default:
-      errno = (err > 10000 && err < 10025) ? err - 10000 : err;
-      break;
-    }
-}
-
-
-/* Hook for gnulib module close.  */
-
-#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
-int
-_gl_close_fd_maybe_socket (int fd)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  WSANETWORKEVENTS ev;
-
-  ev.lNetworkEvents = 0xDEADBEEF;
-  WSAEnumNetworkEvents (sock, NULL, &ev);
-  if (ev.lNetworkEvents != 0xDEADBEEF)
-    {
-      /* FIXME: other applications, like squid, use an undocumented
-        _free_osfhnd free function.  But this is not enough: The 'osfile'
-        flags for fd also needs to be cleared, but it is hard to access it.
-        Instead, here we just close twice the file descriptor.  */
-      if (closesocket (sock))
-       {
-         set_winsock_errno ();
-         return -1;
-       }
-      else
-       {
-         /* This call frees the file descriptor and does a
-            CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails.  */
-         _close (fd);
-         return 0;
-       }
-    }
-  else
-    return _close (fd);
-}
-#endif
-
-
-/* Wrappers for WinSock functions.  */
-
-#if GNULIB_SOCKET
-int
-rpl_socket (int domain, int type, int protocol)
-{
-  /* We have to use WSASocket() to create non-overlapped IO sockets.
-     Overlapped IO sockets cannot be used with read/write.  */
-  SOCKET fh = WSASocket (domain, type, protocol, NULL, 0, 0);
-
-  if (fh == INVALID_SOCKET)
-    {
-      set_winsock_errno ();
-      return -1;
-    }
-  else
-    return SOCKET_TO_FD (fh);
-}
-#endif
-
-#if GNULIB_CONNECT
-int
-rpl_connect (int fd, struct sockaddr *sockaddr, int len)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = connect (sock, sockaddr, len);
-  if (r < 0)
-    {
-      /* EINPROGRESS is not returned by WinSock 2.0; for backwards
-        compatibility, connect(2) uses EWOULDBLOCK.  */
-      if (WSAGetLastError () == WSAEWOULDBLOCK)
-        WSASetLastError (WSAEINPROGRESS);
-
-      set_winsock_errno ();
-    }
-
-  return r;
-}
-#endif
-
-#if GNULIB_ACCEPT
-int
-rpl_accept (int fd, struct sockaddr *addr, int *addrlen)
-{
-  SOCKET fh = accept (FD_TO_SOCKET (fd), addr, addrlen);
-  if (fh == INVALID_SOCKET)
-    {
-      set_winsock_errno ();
-      return -1;
-    }
-  else
-    return SOCKET_TO_FD (fh);
-}
-#endif
-
-#if GNULIB_BIND
-int
-rpl_bind (int fd, struct sockaddr *sockaddr, int len)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = bind (sock, sockaddr, len);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_GETPEERNAME
-int
-rpl_getpeername (int fd, struct sockaddr *addr, int *addrlen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = getpeername (sock, addr, addrlen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_GETSOCKNAME
-int
-rpl_getsockname (int fd, struct sockaddr *addr, int *addrlen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = getsockname (sock, addr, addrlen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_GETSOCKOPT
-int
-rpl_getsockopt (int fd, int level, int optname, void *optval, int *optlen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = getsockopt (sock, level, optname, optval, optlen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_LISTEN
-int
-rpl_listen (int fd, int backlog)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = listen (sock, backlog);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_IOCTL
-int
-rpl_ioctl (int fd, int req, ...)
-{
-  void *buf;
-  va_list args;
-  SOCKET sock;
-  int r;
-
-  va_start (args, req);
-  buf = va_arg (args, void *);
-  va_end (args);
-
-  sock = FD_TO_SOCKET (fd);
-  r = ioctlsocket (sock, req, buf);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_RECV
-int
-rpl_recv (int fd, void *buf, int len, int flags)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = recv (sock, buf, len, flags);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_SEND
-int
-rpl_send (int fd, const void *buf, int len, int flags)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = send (sock, buf, len, flags);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_RECVFROM
-int
-rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from,
-             int *fromlen)
-{
-  int frombufsize = *fromlen;
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = recvfrom (sock, buf, len, flags, from, fromlen);
-
-  if (r < 0)
-    set_winsock_errno ();
-
-  /* Winsock recvfrom() only returns a valid 'from' when the socket is
-     connectionless.  POSIX gives a valid 'from' for all types of sockets.  */
-  else if (*fromlen == frombufsize)
-    rpl_getpeername (fd, from, fromlen);
-
-  return r;
-}
-#endif
-
-#if GNULIB_SENDTO
-int
-rpl_sendto (int fd, const void *buf, int len, int flags,
-           struct sockaddr *to, int tolen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = sendto (sock, buf, len, flags, to, tolen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  return r;
-}
-#endif
-
-#if GNULIB_SETSOCKOPT
-int
-rpl_setsockopt (int fd, int level, int optname, const void *optval, int optlen)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = setsockopt (sock, level, optname, optval, optlen);
-  if (r < 0)
-    set_winsock_errno ();
-
-  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 f78688200929c3fd1fb4d45f5f35224eeac8f19d..d1c954edbf8b1879ba06784100899f59abf15fcd 100644 (file)
@@ -2,7 +2,8 @@ Description:
 accept() function: accept a connection to a server socket.
 
 Files:
-lib/winsock.c
+lib/accept.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([accept])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([accept])
 
index 856148a9f131c28493875ee20ebd29a57724d72a..050f0e65c78ad61458982070d5cd8517fc0d85fc 100644 (file)
@@ -2,7 +2,8 @@ Description:
 bind() function: bind a server socket to a port.
 
 Files:
-lib/winsock.c
+lib/bind.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([bind])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([bind])
 
index 304e1076d8171bf67756e81955d56f53d3bcdddd..1381ffaf9173ae622000fe51d20bcce5edfd4b62 100644 (file)
@@ -2,7 +2,8 @@ Description:
 connect() function: connect a client socket.
 
 Files:
-lib/winsock.c
+lib/connect.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([connect])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([connect])
 
index f980bb80b9cdceaae379d8eef4becad9dce9f628..a8a4fcaff2099dee9e70b9d997ef00a539c36a3e 100644 (file)
@@ -3,7 +3,8 @@ getpeername() function: return information about the remote end of a connected
 socket.
 
 Files:
-lib/winsock.c
+lib/getpeername.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -12,7 +13,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([getpeername])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([getpeername])
 
index 2b4fd6469a4d6a7266691735001156929ba433da..a7f8881c74569ae67745c8ee6334d82e28447172 100644 (file)
@@ -3,7 +3,8 @@ getsockname() function: return information about the local end of a connected
 socket.
 
 Files:
-lib/winsock.c
+lib/getsockname.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -12,7 +13,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([getsockname])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([getsockname])
 
index a4e3131ddb1ae2953e02c37c03dfde0a67e3717b..efb762af52ecc2ac00eb3e770bc29711ffbe9c93 100644 (file)
@@ -2,7 +2,8 @@ Description:
 getsockopt() function: retrieve optional settings on a socket.
 
 Files:
-lib/winsock.c
+lib/getsockopt.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([getsockopt])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([getsockopt])
 
index b425dee9d1a37c32e76d7beac1bad2eeed8e3d23..08e595518db34cc7af00f43fc7c090ba4345ce53 100644 (file)
@@ -2,7 +2,8 @@ Description:
 ioctl() function: issue device specific requests on files, devices, or sockets.
 
 Files:
-lib/winsock.c
+lib/ioctl.c
+lib/w32sock.h
 
 Depends-on:
 sys_ioctl
@@ -12,7 +13,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([ioctl])
   gl_REPLACE_SYS_IOCTL_H
 fi
 gl_SYS_IOCTL_MODULE_INDICATOR([ioctl])
index bbaa7a5c4c4c02a9ffb239c29335e8dedebf2574..6912f5d6956e7ee75e73c69f657440cbd4fbc88a 100644 (file)
@@ -2,7 +2,8 @@ Description:
 listen() function: make a server socket ready for accepting connections.
 
 Files:
-lib/winsock.c
+lib/listen.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([listen])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([listen])
 
index a5322409e446b274d225bb1bb2735668d927a10a..04602f9801dc321d4fff551d2d401985e062a927 100644 (file)
@@ -2,7 +2,8 @@ Description:
 recv() function: receive (read) data from a connected socket.
 
 Files:
-lib/winsock.c
+lib/recv.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([recv])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([recv])
 
index 5fee0847161ff3617098b19e8f12583edbbaf7c3..8237565b9d43c64a02f12231fa15b1f66c66cda5 100644 (file)
@@ -2,7 +2,8 @@ Description:
 recvfrom() function: receive (read) data from a potentially unconnected socket.
 
 Files:
-lib/winsock.c
+lib/recvfrom.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -12,7 +13,7 @@ getpeername
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([recvfrom])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([recvfrom])
 
index 75309ce8b0dfbb2b9ccec74778ec906539064a54..4317d6fb916c4e779b6fbee97de192d1f5f13ee4 100644 (file)
@@ -2,7 +2,8 @@ Description:
 send() function: send (write) data to a connected socket.
 
 Files:
-lib/winsock.c
+lib/send.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([send])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([send])
 
index 888d0dc7f5c70c5551c3df9e94c360d7589e6919..d9a292c85734f212912dfb64c90ece82726c59cf 100644 (file)
@@ -2,7 +2,8 @@ Description:
 sendto() function: send (write) data to a potentially unconnected socket.
 
 Files:
-lib/winsock.c
+lib/sendto.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([sendto])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([sendto])
 
index 5cd3d1db0b7d0dd7d46f54ca8beb53559cc30e59..d665f8ee63c6123077a8e723d6b2cb9953e2a921 100644 (file)
@@ -2,7 +2,8 @@ Description:
 setsockopt() function: specify optional settings on a socket.
 
 Files:
-lib/winsock.c
+lib/setsockopt.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([setsockopt])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([setsockopt])
 
index e6d417814007d820044f360d9221a4d09f8d00e1..c1e062104dd85cefbd0b6091513453af76e9a606 100644 (file)
@@ -2,7 +2,8 @@ Description:
 shutdown() function: initiate a graceful shutdown of a socket.
 
 Files:
-lib/winsock.c
+lib/shutdown.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([shutdown])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([shutdown])
 
index 900d9ec95d5ef0c2a0a72329ea8be996d24a3f1f..070ba3f2f03b7226645b505369322ea4b94fea72 100644 (file)
@@ -2,7 +2,8 @@ Description:
 socket() function: create a socket.
 
 Files:
-lib/winsock.c
+lib/socket.c
+lib/w32sock.h
 
 Depends-on:
 sys_socket
@@ -11,7 +12,7 @@ errno
 configure.ac:
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
-  AC_LIBOBJ([winsock])
+  AC_LIBOBJ([socket])
 fi
 gl_SYS_SOCKET_MODULE_INDICATOR([socket])
 
index 553b84b7069721070017a90d74f54a4a057e1490..9505cafb81057e1a583798ee9be2a4d967b35c88 100644 (file)
@@ -3,7 +3,6 @@ A POSIX-like <sys/socket.h>.
 
 Files:
 lib/sys_socket.in.h
-lib/winsock.c
 m4/sys_socket_h.m4
 m4/sockpfaf.m4
 m4/unistd_h.m4