gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (5bd045bd -> d1d96376)


From: gnunet
Subject: [libmicrohttpd] branch master updated (5bd045bd -> d1d96376)
Date: Wed, 16 Dec 2020 13:22:37 +0100

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 5bd045bd Updated W32 resource files
     new 259f7659 Fixed debug build without TLS support
     new 35c2a1eb mhd_send.c: minor code and comment fixes
     new d1d96376 mhd_send.c: added support for vector-send on W32

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/microhttpd/daemon.c   |   2 +
 src/microhttpd/mhd_send.c | 106 +++++++++++++++++++++++++++++++++-------------
 2 files changed, 78 insertions(+), 30 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 5666e4ee..fefcd8b4 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -7301,7 +7301,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
     mhd_assert (NULL == daemon->cleanup_head);
     mhd_assert (NULL == daemon->suspended_connections_head);
     mhd_assert (NULL == daemon->new_connections_head);
+#if defined(UPGRADE_SUPPORT) && defined (HTTPS_SUPPORT)
     mhd_assert (NULL == daemon->urh_head);
+#endif /* UPGRADE_SUPPORT && HTTPS_SUPPORT */
 
     if (MHD_ITC_IS_VALID_ (daemon->itc))
       MHD_itc_destroy_chk_ (daemon->itc);
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index bed850ce..a7125708 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -650,7 +650,7 @@ post_send_setopt (struct MHD_Connection *connection,
 #endif /* ! MHD_TCP_CORK_NOPUSH */
 #ifdef HAVE_MESSAGES
   MHD_DLOG (connection->daemon,
-            _ ("Failed to put the data from buffers to the network. "
+            _ ("Failed to push the data from buffers to the network. "
                "Client may experience some delay "
                "(usually in range 200ms - 5 sec).\n"));
 #endif /* HAVE_MESSAGES */
@@ -672,21 +672,21 @@ MHD_send_data_ (struct MHD_Connection *connection,
   const bool tls_conn = false;
 #endif /* ! HTTPS_SUPPORT */
 
-  /* error handling from send_param_adapter() */
   if ( (MHD_INVALID_SOCKET == s) ||
        (MHD_CONNECTION_CLOSED == connection->state) )
   {
     return MHD_ERR_NOTCONN_;
   }
 
+  if (buffer_size > SSIZE_MAX)
+  {
+    buffer_size = SSIZE_MAX; /* Max return value */
+    push_data = false; /* Incomplete send */
+  }
+
   if (tls_conn)
   {
 #ifdef HTTPS_SUPPORT
-    if (buffer_size > SSIZE_MAX)
-    {
-      buffer_size = SSIZE_MAX;
-      push_data = false; /* Incomplete send */
-    }
     pre_send_setopt (connection, (! tls_conn), push_data);
     ret = gnutls_record_send (connection->tls_session,
                               buffer,
@@ -723,7 +723,7 @@ MHD_send_data_ (struct MHD_Connection *connection,
     /* plaintext transmission */
     if (buffer_size > MHD_SCKT_SEND_MAX_SIZE_)
     {
-      buffer_size = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */
+      buffer_size = MHD_SCKT_SEND_MAX_SIZE_; /* send() return value limit */
       push_data = false; /* Incomplete send */
     }
 
@@ -781,6 +781,10 @@ MHD_send_data_ (struct MHD_Connection *connection,
 }
 
 
+#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) || defined(_WIN32)
+#define _MHD_USE_SEND_VEC          1
+#endif /* HAVE_SENDMSG || HAVE_WRITEV || _WIN32*/
+
 ssize_t
 MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
                         const char *header,
@@ -794,17 +798,30 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
   bool push_hdr;
   bool push_body;
   MHD_socket s = connection->socket_fd;
+#ifndef _WIN32
+#define _MHD_SEND_VEC_MAX   MHD_SCKT_SEND_MAX_SIZE_
+#else  /* ! _WIN32 */
+#define _MHD_SEND_VEC_MAX   UINT32_MAX
+#endif /* ! _WIN32 */
+#ifdef _MHD_USE_SEND_VEC
 #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
   struct iovec vector[2];
 #ifdef HAVE_SENDMSG
   struct msghdr msg;
 #endif /* HAVE_SENDMSG */
+#endif /* HAVE_SENDMSG || HAVE_WRITEV */
+#ifdef _WIN32
+  WSABUF vector[2];
+  uint32_t vec_sent;
+  int err;
+#endif /* _WIN32 */
 #ifdef HTTPS_SUPPORT
   const bool no_vec = (connection->daemon->options & MHD_USE_TLS);
 #else  /* ! HTTPS_SUPPORT */
   const bool no_vec = false;
 #endif /* ! HTTPS_SUPPORT */
-#endif /* HAVE_SENDMSG || HAVE_WRITEV */
+#endif /* _MHD_USE_SEND_VEC */
+
   mhd_assert ( (NULL != body) || (0 == body_size) );
 
   if ( (MHD_INVALID_SOCKET == s) ||
@@ -840,13 +857,14 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
     push_hdr = true; /* The header alone is equal to the whole response. */
 
   if (
-#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
+#ifdef _MHD_USE_SEND_VEC
     (no_vec) ||
     (0 == body_size) ||
-    ((size_t) SSIZE_MAX <= header_size)
-#else  /* ! (HAVE_SENDMSG || HAVE_WRITEV) */
+    ((size_t) SSIZE_MAX < header_size) ||
+    ((size_t) _MHD_SEND_VEC_MAX < header_size)
+#else  /* ! _MHD_USE_SEND_VEC */
     true
-#endif /* ! (HAVE_SENDMSG || HAVE_WRITEV) */
+#endif /* ! _MHD_USE_SEND_VEC */
     )
   {
     ret = MHD_send_data_ (connection,
@@ -855,14 +873,15 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
                           push_hdr);
 
     if ( (header_size == (size_t) ret) &&
-         (((size_t) SSIZE_MAX > header_size)) &&
+         ((size_t) SSIZE_MAX > header_size) &&
          (0 != body_size) )
     {
       ssize_t ret2;
       /* The header has been sent completely.
        * Try to send the reply body without waiting for
        * the next round. */
-      /* Make sure that sum of ret + ret2 will not exceed SSIZE_MAX. */
+      /* Make sure that sum of ret + ret2 will not exceed SSIZE_MAX as
+       * function needs to return positive value if succeed. */
       if ( (((size_t) SSIZE_MAX) - ((size_t) ret)) <  body_size)
       {
         body_size = (((size_t) SSIZE_MAX) - ((size_t) ret));
@@ -883,41 +902,69 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
     }
     return ret;
   }
-#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
+#ifdef _MHD_USE_SEND_VEC
 
   if ( ((size_t) SSIZE_MAX <= body_size) ||
        ((size_t) SSIZE_MAX < (header_size + body_size)) )
   {
+    /* Return value limit */
     body_size = SSIZE_MAX - header_size;
     complete_response = false;
     push_body = complete_response;
   }
+#if (SSIZE_MAX != _MHD_SEND_VEC_MAX) || (_MHD_SEND_VEC_MAX + 0 == 0)
+  if (((size_t) _MHD_SEND_VEC_MAX <= body_size) ||
+      ((size_t) _MHD_SEND_VEC_MAX < (header_size + body_size)))
+  {
+    /* Send value limit */
+    body_size = _MHD_SEND_VEC_MAX - header_size;
+    complete_response = false;
+    push_body = complete_response;
+  }
+#endif /* SSIZE_MAX != _MHD_SEND_VEC_MAX */
 
   pre_send_setopt (connection,
-#if HAVE_SENDMSG
+#ifdef HAVE_SENDMSG
                    true,
-#elif HAVE_WRITEV
+#else  /* ! HAVE_SENDMSG */
                    false,
-#endif /* HAVE_WRITEV */
+#endif /* ! HAVE_SENDMSG */
                    push_hdr || push_body);
-
+#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
   vector[0].iov_base = (void *) header;
   vector[0].iov_len = header_size;
   vector[1].iov_base = (void *) body;
   vector[1].iov_len = body_size;
 
-#if HAVE_SENDMSG
+#if define (HAVE_SENDMSG)
   memset (&msg, 0, sizeof(msg));
   msg.msg_iov = vector;
   msg.msg_iovlen = 2;
 
   ret = sendmsg (s, &msg, MSG_NOSIGNAL_OR_ZERO);
-#elif HAVE_WRITEV
+#elif defined (HAVE_WRITEV)
   ret = writev (s, vector, 2);
-#endif
+#endif /* HAVE_WRITEV */
+#endif /* HAVE_SENDMSG || HAVE_WRITEV */
+#ifdef _WIN32
+  vector[0].buf = (char *) header;
+  vector[0].len = (unsigned long) header_size;
+  vector[1].buf = (char *) body;
+  vector[1].len = (unsigned long) body_size;
+
+  err = WSASend (s, vector, 2, &vec_sent, 0, NULL, NULL);
+
+  if (0 == err)
+    ret = (ssize_t) vec_sent;
+  else
+    ret = -1;
+#endif /* _WIN32 */
+
   if (0 > ret)
   {
+#ifndef _WIN32
     const int err = MHD_socket_get_error_ ();
+#endif /* _WIN32 */
 
     if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
     {
@@ -953,11 +1000,11 @@ MHD_send_hdr_and_body_ (struct MHD_Connection 
*connection,
      * sendfile() will be used so assume that next final send() will be
      * the same, like for this response. */
     post_send_setopt (connection,
-#if HAVE_SENDMSG
+#ifdef HAVE_SENDMSG
                       true,
-#elif HAVE_WRITEV
+#else  /* ! HAVE_SENDMSG */
                       false,
-#endif /* HAVE_WRITEV */
+#endif /* ! HAVE_SENDMSG */
                       true);
   }
   else if ( (push_hdr) &&
@@ -965,8 +1012,7 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
   {
     /* The header has been sent completely and there is a
      * need to push the header data. */
-    /* Luckily it is know what type of send function will be used
-     * next.  */
+    /* Luckily the type of send function will be used next is known. */
     post_send_setopt (connection,
 #if defined(_MHD_HAVE_SENDFILE)
                       MHD_resp_sender_std == connection->resp_sender,
@@ -977,10 +1023,10 @@ MHD_send_hdr_and_body_ (struct MHD_Connection 
*connection,
   }
 
   return ret;
-#else  /* ! (HAVE_SENDMSG || HAVE_WRITEV) */
+#else  /* ! _MHD_USE_SEND_VEC */
   mhd_assert (false);
   return MHD_ERR_CONNRESET_; /* Unreachable. Mute warnings. */
-#endif /* ! (HAVE_SENDMSG || HAVE_WRITEV) */
+#endif /* ! _MHD_USE_SEND_VEC */
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]