summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2022-05-10 14:54:40 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2022-05-10 14:54:40 +0900
commit14068dfc74fffa9cdf2fd49712f4ffcfe6405ba0 (patch)
tree7fd07b1ae174dec36d65d6969bdc6c98e81e9947
parent09df630e4be7c44b89183181c1643f50ad606ae2 (diff)
dirmngr: Fix for Windows.
* dirmngr/http.c (EHOSTUNREACH, EAFNOSUPPORT): Define when not available. [HTTP_USE_GNUTLS] (my_gnutls_read): Use recv for Windows. [HTTP_USE_GNUTLS] (my_gnutls_write): Use send for Windows. -- Reported-by: Eli Zaretskii GnuPG-bug-id: 5899 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r--dirmngr/http.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/dirmngr/http.c b/dirmngr/http.c
index 1050d19ee..20f71f61b 100644
--- a/dirmngr/http.c
+++ b/dirmngr/http.c
@@ -64,6 +64,12 @@
# include <winsock2.h>
# endif
# include <windows.h>
+# ifndef EHOSTUNREACH
+# define EHOSTUNREACH WSAEHOSTUNREACH
+# endif
+# ifndef EAFNOSUPPORT
+# define EAFNOSUPPORT WSAEAFNOSUPPORT
+# endif
#else /*!HAVE_W32_SYSTEM*/
# include <sys/types.h>
# include <sys/socket.h>
@@ -440,20 +446,48 @@ static ssize_t
my_gnutls_read (gnutls_transport_ptr_t ptr, void *buffer, size_t size)
{
my_socket_t sock = ptr;
-#if USE_NPTH
+#ifdef HAVE_W32_SYSTEM
+ /* Under Windows we need to use recv for a socket. */
+ int nread;
+# if USE_NPTH
+ npth_unprotect ();
+# endif
+ nread = recv (FD2INT (sock->fd), buffer, size, 0);
+# if USE_NPTH
+ npth_protect ();
+# endif
+ return nread;
+
+#else /* !HAVE_W32_SYSTEM */
+# if USE_NPTH
return npth_read (sock->fd, buffer, size);
-#else
+# else
return read (sock->fd, buffer, size);
+# endif
#endif
}
static ssize_t
my_gnutls_write (gnutls_transport_ptr_t ptr, const void *buffer, size_t size)
{
my_socket_t sock = ptr;
-#if USE_NPTH
+#ifdef HAVE_W32_SYSTEM
+ int nwritten;
+# if USE_NPTH
+ npth_unprotect ();
+# endif
+ nwritten = send (FD2INT (sock->fd), buffer, size, 0);
+# if USE_NPTH
+ npth_protect ();
+# endif
+ return nwritten;
+
+#else /*!HAVE_W32_SYSTEM*/
+
+# if USE_NPTH
return npth_write (sock->fd, buffer, size);
-#else
+# else
return write (sock->fd, buffer, size);
+# endif
#endif
}
#endif /*HTTP_USE_GNUTLS*/