gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (2a0c96ff -> e53b8c0b)


From: gnunet
Subject: [libmicrohttpd] branch master updated (2a0c96ff -> e53b8c0b)
Date: Sun, 18 Apr 2021 19:49:51 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 2a0c96ff response: simplified code
     new 61858b1e mhd_sockets: removed dead code
     new 17934e4e MHD_create_response_from_iovec(): more portable behavior
     new c5b661b6 mhd_send: more detailed error results
     new e53b8c0b connection: report socket error in MHD log

The 4 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/connection.c  | 77 ++++++++++++++++++++++++++++++++++++++-----
 src/microhttpd/connection.h  | 10 ++++++
 src/microhttpd/mhd_send.c    | 46 ++++++++++++++++++++++----
 src/microhttpd/mhd_sockets.c | 78 --------------------------------------------
 src/microhttpd/mhd_sockets.h | 44 +++++--------------------
 src/microhttpd/response.c    |  2 +-
 6 files changed, 128 insertions(+), 129 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index db130e18..baf0fcb4 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -125,6 +125,47 @@
  */
 #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000)
 
+/**
+ * Return text description for MHD_ERR_*_ codes
+ * @param mhd_err_code the error code
+ * @return pointer to static string with error description
+ */
+static const char *
+str_conn_error_ (ssize_t mhd_err_code)
+{
+#ifdef HAVE_MESSAGES
+  switch (mhd_err_code)
+  {
+  case MHD_ERR_AGAIN_:
+    return _ ("The operation would block, retry later");
+  case MHD_ERR_CONNRESET_:
+    return _ ("The connection was forcibly closed by remote peer");
+  case MHD_ERR_NOTCONN_:
+    return _ ("The socket is not connected");
+  case MHD_ERR_NOMEM_:
+    return _ ("Not enough system resources to serve the request");
+  case MHD_ERR_BADF_:
+    return _ ("Bad FD value");
+  case MHD_ERR_INVAL_:
+    return _ ("Argument value is invalid");
+  case MHD_ERR_OPNOTSUPP_:
+    return _ ("Argument value is not supported");
+  case MHD_ERR_PIPE_:
+    return _ ("The socket is no longer available for sending");
+  default:
+    break;   /* Mute compiler warning */
+  }
+  if (0 <= mhd_err_code)
+    return _ ("Not an error code");
+
+  mhd_assert (0); /* Should never be reachable */
+  return _ ("Wrong error code value");
+#else  /* ! HAVE_MESSAGES */
+  return "";
+#endif /* ! HAVE_MESSAGES */
+}
+
+
 /**
  * Callback for receiving data from the socket.
  *
@@ -2999,9 +3040,15 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
       {
         if (MHD_ERR_AGAIN_ == ret)
           return;
+#ifdef HAVE_MESSAGES
+        MHD_DLOG (connection->daemon,
+                  _ ("Failed to send the response headers for the " \
+                     "request for `%s'. Error: %s\n"),
+                  connection->url,
+                  str_conn_error_ (ret));
+#endif
         CONNECTION_CLOSE_ERROR (connection,
-                                _ (
-                                  "Connection was closed while sending 
response headers.\n"));
+                                NULL);
         return;
       }
       /* 'ret' is not negative, it's safe to cast it to 'size_t'. */
@@ -3087,8 +3134,10 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
           return;
 #ifdef HAVE_MESSAGES
         MHD_DLOG (connection->daemon,
-                  _ ("Failed to send data in request for `%s'.\n"),
-                  connection->url);
+                  _ ("Failed to send the response body for the " \
+                     "request for `%s'. Error: %s\n"),
+                  connection->url,
+                  str_conn_error_ (ret));
 #endif
         CONNECTION_CLOSE_ERROR (connection,
                                 NULL);
@@ -3115,9 +3164,15 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
     {
       if (MHD_ERR_AGAIN_ == ret)
         return;
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (connection->daemon,
+                _ ("Failed to send the chunked response body for the " \
+                   "request for `%s'. Error: %s\n"),
+                connection->url,
+                str_conn_error_ (ret));
+#endif
       CONNECTION_CLOSE_ERROR (connection,
-                              _ (
-                                "Connection was closed while sending response 
body.\n"));
+                              NULL);
       return;
     }
     connection->write_buffer_send_offset += ret;
@@ -3145,9 +3200,15 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
     {
       if (MHD_ERR_AGAIN_ == ret)
         return;
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (connection->daemon,
+                _ ("Failed to send the footers for the " \
+                   "request for `%s'. Error: %s\n"),
+                connection->url,
+                str_conn_error_ (ret));
+#endif
       CONNECTION_CLOSE_ERROR (connection,
-                              _ (
-                                "Connection was closed while sending response 
body.\n"));
+                              NULL);
       return;
     }
     connection->write_buffer_send_offset += ret;
diff --git a/src/microhttpd/connection.h b/src/microhttpd/connection.h
index 8b1a0946..f7d7b17a 100644
--- a/src/microhttpd/connection.h
+++ b/src/microhttpd/connection.h
@@ -61,6 +61,16 @@
  */
 #define MHD_ERR_INVAL_ (-3078)
 
+/**
+ * Argument values are not supported
+ */
+#define MHD_ERR_OPNOTSUPP_ (-3079)
+
+/**
+ * Socket is shut down for writing or no longer connected
+ */
+#define MHD_ERR_PIPE_ (-3080)
+
 
 /**
  * Set callbacks for this connection to those for HTTP.
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index a1c50917..049034c9 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -789,6 +789,8 @@ MHD_send_data_ (struct MHD_Connection *connection,
       return MHD_ERR_AGAIN_;
     if ( (GNUTLS_E_ENCRYPTION_FAILED == ret) ||
          (GNUTLS_E_INVALID_SESSION == ret) )
+      return MHD_ERR_INVAL_;
+    if (GNUTLS_E_PREMATURE_TERMINATION == ret)
       return MHD_ERR_CONNRESET_;
     if (GNUTLS_E_MEMORY_ERROR == ret)
       return MHD_ERR_NOMEM_;
@@ -841,11 +843,21 @@ MHD_send_data_ (struct MHD_Connection *connection,
       }
       if (MHD_SCKT_ERR_IS_EINTR_ (err))
         return MHD_ERR_AGAIN_;
-      if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_))
+      if (MHD_SCKT_ERR_IS_REMOTE_DISCNN_ (err))
         return MHD_ERR_CONNRESET_;
+      if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EPIPE_))
+        return MHD_ERR_PIPE_;
+      if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EOPNOTSUPP_))
+        return MHD_ERR_OPNOTSUPP_;
+      if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ENOTCONN_))
+        return MHD_ERR_NOTCONN_;
+      if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EINVAL_))
+        return MHD_ERR_INVAL_;
       if (MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err))
         return MHD_ERR_NOMEM_;
-      /* Treat any other error as hard error. */
+      if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EBADF_))
+        return MHD_ERR_BADF_;
+      /* Treat any other error as a hard error. */
       return MHD_ERR_NOTCONN_;
     }
 #if EPOLL_SUPPORT
@@ -1075,11 +1087,21 @@ MHD_send_hdr_and_body_ (struct MHD_Connection 
*connection,
     }
     if (MHD_SCKT_ERR_IS_EINTR_ (err))
       return MHD_ERR_AGAIN_;
-    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_))
+    if (MHD_SCKT_ERR_IS_REMOTE_DISCNN_ (err))
       return MHD_ERR_CONNRESET_;
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EPIPE_))
+      return MHD_ERR_PIPE_;
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EOPNOTSUPP_))
+      return MHD_ERR_OPNOTSUPP_;
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ENOTCONN_))
+      return MHD_ERR_NOTCONN_;
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EINVAL_))
+      return MHD_ERR_INVAL_;
     if (MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err))
       return MHD_ERR_NOMEM_;
-    /* Treat any other error as hard error. */
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EBADF_))
+      return MHD_ERR_BADF_;
+    /* Treat any other error as a hard error. */
     return MHD_ERR_NOTCONN_;
   }
 #if EPOLL_SUPPORT
@@ -1439,9 +1461,21 @@ send_iov_nontls (struct MHD_Connection *connection,
     }
     if (MHD_SCKT_ERR_IS_EINTR_ (err))
       return MHD_ERR_AGAIN_;
-    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_))
+    if (MHD_SCKT_ERR_IS_REMOTE_DISCNN_ (err))
       return MHD_ERR_CONNRESET_;
-    /* Treat any other error as hard error. */
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EPIPE_))
+      return MHD_ERR_PIPE_;
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EOPNOTSUPP_))
+      return MHD_ERR_OPNOTSUPP_;
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ENOTCONN_))
+      return MHD_ERR_NOTCONN_;
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EINVAL_))
+      return MHD_ERR_INVAL_;
+    if (MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err))
+      return MHD_ERR_NOMEM_;
+    if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EBADF_))
+      return MHD_ERR_BADF_;
+    /* Treat any other error as a hard error. */
     return MHD_ERR_NOTCONN_;
   }
 
diff --git a/src/microhttpd/mhd_sockets.c b/src/microhttpd/mhd_sockets.c
index fef7085c..aae8a496 100644
--- a/src/microhttpd/mhd_sockets.c
+++ b/src/microhttpd/mhd_sockets.c
@@ -489,84 +489,6 @@ MHD_socket_set_nodelay_ (MHD_socket sock,
 }
 
 
-/**
- * Enable/disable the cork option.
- *
- * @param sock socket to manipulate
- * @param on set to true to enable CORK, false to disable
- * @return non-zero if succeeded, zero otherwise
- */
-int
-MHD_socket_cork_ (MHD_socket sock,
-                  bool on)
-{
-#if defined(MHD_TCP_CORK_NOPUSH)
-  const MHD_SCKT_OPT_BOOL_ off_val = 0;
-  const MHD_SCKT_OPT_BOOL_ on_val = 1;
-
-  /* Disable extra buffering */
-  if (MHD_INVALID_SOCKET == sock)
-  {
-    errno = EBADF;
-    return 0; /* failed */
-  }
-  if (0 != setsockopt (sock,
-                       IPPROTO_TCP,
-                       MHD_TCP_CORK_NOPUSH,
-                       (const void *) (on ? &on_val : &off_val),
-                       sizeof (off_val)))
-    return 0; /* failed */
-#if defined(_MHD_CORK_RESET_PUSH_DATA)
-  return 1;
-#else  /* ! _MHD_CORK_RESET_PUSH_DATA */
-  if (! on)
-  {
-    const int dummy = 0;
-    /* Force flush data with zero send otherwise Darwin and some BSD systems
-       will add 5 seconds delay. Not required with TCP_CORK as switching off
-       TCP_CORK always flushes socket buffer. */
-    if (0 > send (sock,
-                  &dummy,
-                  0,
-                  0))
-      return 0; /* even force flush failed!? */
-    return 1; /* success */
-  }
-  return 1;
-#endif /* ! _MHD_CORK_RESET_PUSH_DATA */
-#else  /* ! MHD_TCP_CORK_NOPUSH */
-  /* do not have MHD_TCP_CORK_NOPUSH at all */
-  (void) sock; (void) on; /* Mute compiler warnings */
-  return 0;
-#endif /* ! MHD_TCP_CORK_NOPUSH */
-}
-
-
-/**
- * Change socket buffering mode to default.
- *
- * @param sock socket to manipulate
- * @return non-zero if succeeded, zero otherwise
- */
-int
-MHD_socket_buffering_reset_ (MHD_socket sock)
-{
-#if defined(MHD_TCP_CORK_NOPUSH)
-  int res = ! MHD_socket_set_nodelay_ (sock,
-                                       true);
-  /* Disable extra buffering */
-  return MHD_socket_cork_ (sock,
-                           false) && res;
-#elif defined(HAVE_MSG_MORE)
-  return ! MHD_socket_set_nodelay_ (sock,
-                                    true);
-#else
-  return ! MHD_socket_set_nodelay_ (sock,
-                                    false);
-#endif /* MHD_TCP_CORK_NOPUSH */
-}
-
-
 /**
  * Create a listen socket, with noninheritable flag if possible.
  *
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
index b16a8b1a..56ea64db 100644
--- a/src/microhttpd/mhd_sockets.h
+++ b/src/microhttpd/mhd_sockets.h
@@ -557,6 +557,11 @@ typedef int MHD_SCKT_SEND_SIZE_;
 #  else  /* ! EINVAL */
 #    define MHD_SCKT_EINVAL_      MHD_SCKT_MISSING_ERR_CODE_
 #  endif /* ! EINVAL */
+#  ifdef EPIPE
+#    define MHD_SCKT_EPIPE_       EPIPE
+#  else  /* ! EPIPE */
+#    define MHD_SCKT_EPIPE_       MHD_SCKT_MISSING_ERR_CODE_
+#  endif /* ! EPIPE */
 #  ifdef EFAULT
 #    define MHD_SCKT_EFAUL_       EFAULT
 #  else  /* ! EFAULT */
@@ -568,9 +573,9 @@ typedef int MHD_SCKT_SEND_SIZE_;
 #    define MHD_SCKT_ENOSYS_      MHD_SCKT_MISSING_ERR_CODE_
 #  endif /* ! ENOSYS */
 #  ifdef ENOPROTOOPT
-#    define MHD_SCKT_ENOPROTOOPT_       ENOPROTOOPT
+#    define MHD_SCKT_ENOPROTOOPT_      ENOPROTOOPT
 #  else  /* ! ENOPROTOOPT */
-#    define MHD_SCKT_ENOSYS_      MHD_SCKT_MISSING_ERR_CODE_
+#    define MHD_SCKT_ENOPROTOOPT_      MHD_SCKT_MISSING_ERR_CODE_
 #  endif /* ! ENOPROTOOPT */
 #  ifdef ENOTSUP
 #    define MHD_SCKT_ENOTSUP_     ENOTSUP
@@ -606,6 +611,7 @@ typedef int MHD_SCKT_SEND_SIZE_;
 #  define MHD_SCKT_EBADF_         WSAEBADF
 #  define MHD_SCKT_ENOTSOCK_      WSAENOTSOCK
 #  define MHD_SCKT_EINVAL_        WSAEINVAL
+#  define MHD_SCKT_EPIPE_         WSAESHUTDOWN
 #  define MHD_SCKT_EFAUL_         WSAEFAULT
 #  define MHD_SCKT_ENOSYS_        MHD_SCKT_MISSING_ERR_CODE_
 #  define MHD_SCKT_ENOPROTOOPT_   WSAENOPROTOOPT
@@ -892,40 +898,6 @@ int
 MHD_socket_noninheritable_ (MHD_socket sock);
 
 
-/**
- * Enable/disable the cork option.
- *
- * TCP_NOPUSH has the same logic as MSG_MSG_MORE.
- * The two are more or less equivalent by a source
- * transformation (ie
- * send(MSG_MORE) => "set TCP_NOPUSH + send() + clear TCP_NOPUSH".
- * Both of them are really fairly "local", but TCP_NOPUSH has a
- * _notion_ of persistency that is entirely lacking in MSG_MORE.
- * ... with TCP_NOPUSH you basically have to know what your last
- * write is, and clear the bit _before_ that write if you want
- * to avoid bad latencies.
- *
- * See also: https://yarchive.net/comp/linux/sendfile.html
- *
- * @param sock socket to manipulate
- * @param on set to true to enable CORK, false to disable
- * @return non-zero if succeeded, zero otherwise
- */
-int
-MHD_socket_cork_ (MHD_socket sock,
-                  bool on);
-
-
-/**
- * Change socket buffering mode to default.
- *
- * @param sock socket to manipulate
- * @return non-zero if succeeded, zero otherwise
- */
-int
-MHD_socket_buffering_reset_ (MHD_socket sock);
-
-
 #if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
 static const int _MHD_socket_int_one = 1;
 /**
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 5dcdca18..ab8a56e8 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -895,7 +895,7 @@ MHD_create_response_from_iovec (const struct MHD_IoVec *iov,
     }
     if ( (total_size > (total_size + iov[i].iov_len)) ||
          (INT_MAX == i_cp) ||
-         (SSIZE_MAX < iov[i].iov_len) )
+         (SSIZE_MAX < (total_size + iov[i].iov_len)) )
     {
       i_cp = -1;     /* overflow */
       break;

-- 
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]