From f0f5cb6b3e525f696b8820c517190e1d84f3b885 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 7 Nov 2014 18:21:50 +0100 Subject: [PATCH] w32: Fix http access module. * common/http.c (write_server) [W32]: Rework to use send() instead of write even when build with npth. (cookie_read) [W32]: Rework to use recv() instead of read even when build with npth. --- common/http.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/common/http.c b/common/http.c index 413efd840..f129010b3 100644 --- a/common/http.c +++ b/common/http.c @@ -2320,14 +2320,20 @@ write_server (int sock, const char *data, size_t length) nleft = length; while (nleft > 0) { -#if defined(HAVE_W32_SYSTEM) && !defined(USE_NPTH) +#if defined(HAVE_W32_SYSTEM) +# if defined(USE_NPTH) + npth_unprotect (); +# endif nwritten = send (sock, data, nleft, 0); +# if defined(USE_NPTH) + npth_protect (); +# endif if ( nwritten == SOCKET_ERROR ) { log_info ("network write failed: ec=%d\n", (int)WSAGetLastError ()); return gpg_error (GPG_ERR_NETWORK); } -#else /*!HAVE_W32_SYSTEM || USE_NPTH*/ +#else /*!HAVE_W32_SYSTEM*/ # ifdef USE_NPTH nwritten = npth_write (sock, data, nleft); # else @@ -2349,7 +2355,7 @@ write_server (int sock, const char *data, size_t length) log_info ("network write failed: %s\n", strerror (errno)); return gpg_error_from_syserror (); } -#endif /*!HAVE_W32_SYSTEM || USE_NPTH*/ +#endif /*!HAVE_W32_SYSTEM*/ nleft -= nwritten; data += nwritten; } @@ -2404,14 +2410,25 @@ cookie_read (void *cookie, void *buffer, size_t size) { do { -#ifdef USE_NPTH - nread = npth_read (c->sock->fd, buffer, size); -#elif defined(HAVE_W32_SYSTEM) +#ifdef HAVE_W32_SYSTEM /* Under Windows we need to use recv for a socket. */ +# if defined(USE_NPTH) + npth_unprotect (); +# endif nread = recv (c->sock->fd, buffer, size, 0); -#else +# if defined(USE_NPTH) + npth_protect (); +# endif + +#else /*!HAVE_W32_SYSTEM*/ + +# ifdef USE_NPTH + nread = npth_read (c->sock->fd, buffer, size); +# else nread = read (c->sock->fd, buffer, size); -#endif +# endif + +#endif /*!HAVE_W32_SYSTEM*/ } while (nread == -1 && errno == EINTR); }