gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] 01/02: Do not use errno to return errors fr


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 01/02: Do not use errno to return errors from recv_param_adapter()/recv_tls_adapter()
Date: Sun, 04 Jun 2017 23:33:24 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 3777686c912cc6102694e55862302aec9a16812b
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Sun Jun 4 23:37:41 2017 +0300

    Do not use errno to return errors from 
recv_param_adapter()/recv_tls_adapter()
---
 src/microhttpd/connection.c       | 32 ++++++++++++++++++++------------
 src/microhttpd/connection.h       | 30 ++++++++++++++++++++++++++++++
 src/microhttpd/connection_https.c | 12 +++++-------
 3 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index baa5eb56..45cc6566 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -118,7 +118,8 @@
  * @param connection the MHD connection structure
  * @param other where to write received data to
  * @param i maximum size of other (in bytes)
- * @return number of bytes actually received
+ * @return positive value for number of bytes actually received or
+ *         negative value for error number MHD_ERR_xxx_
  */
 static ssize_t
 recv_param_adapter (struct MHD_Connection *connection,
@@ -130,8 +131,7 @@ recv_param_adapter (struct MHD_Connection *connection,
   if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
        (MHD_CONNECTION_CLOSED == connection->state) )
     {
-      MHD_socket_set_error_ (MHD_SCKT_ENOTCONN_);
-      return -1;
+      return MHD_ERR_NOTCONN_;
     }
   if (i > MHD_SCKT_SEND_MAX_SIZE_)
     i = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */
@@ -139,16 +139,26 @@ recv_param_adapter (struct MHD_Connection *connection,
   ret = MHD_recv_ (connection->socket_fd,
                    other,
                    i);
-#ifdef EPOLL_SUPPORT
   if (0 > ret)
     {
-      /* Got EAGAIN --- no longer read-ready */
-      if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()))
-        connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
+      const int err = MHD_socket_get_error_ ();
+      if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
+        {
+#ifdef EPOLL_SUPPORT
+          /* Got EAGAIN --- no longer read-ready */
+          connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
+#endif /* EPOLL_SUPPORT */
+          return MHD_ERR_AGAIN_;
+        }
+      if (MHD_SCKT_ERR_IS_EINTR_ (err))
+        return MHD_ERR_AGAIN_;
+      /* Treat any other error as hard error. */
+      return MHD_ERR_CONNRESET_;
     }
+#ifdef EPOLL_SUPPORT
   else if (i > (size_t)ret)
     connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
-#endif
+#endif /* EPOLL_SUPPORT */
   return ret;
 }
 
@@ -2660,11 +2670,9 @@ MHD_connection_handle_read (struct MHD_Connection 
*connection)
                                      connection->read_buffer_offset);
   if (bytes_read < 0)
     {
-      const int err = MHD_socket_get_error_ ();
-      if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
-          MHD_SCKT_ERR_IS_EAGAIN_ (err))
+      if (MHD_ERR_AGAIN_ == bytes_read)
           return MHD_YES; /* No new data to process. */
-      if (MHD_SCKT_ERR_IS_REMOTE_DISCNN_ (err))
+      if (MHD_ERR_CONNRESET_ == bytes_read)
         {
            CONNECTION_CLOSE_ERROR (connection,
                                    (MHD_CONNECTION_INIT == connection->state) ?
diff --git a/src/microhttpd/connection.h b/src/microhttpd/connection.h
index d885f3f7..147d7343 100644
--- a/src/microhttpd/connection.h
+++ b/src/microhttpd/connection.h
@@ -30,6 +30,36 @@
 
 #include "internal.h"
 
+/**
+ * Error code similar to EGAIN or EINTR
+ */
+#define MHD_ERR_AGAIN_ (-3073)
+
+/**
+ * "Connection (remote) reset" error code
+ */
+#define MHD_ERR_CONNRESET_ (-3074)
+
+/**
+ * "Not connected" error code
+ */
+#define MHD_ERR_NOTCONN_ (-3075)
+
+/**
+ * "Not enough memory" error code
+ */
+#define MHD_ERR_NOMEM_ (-3076)
+
+/**
+ * "Bad FD" error code
+ */
+#define MHD_ERR_BADF_ (-3077)
+
+/**
+ * Error code similar to EINVAL
+ */
+#define MHD_ERR_INVAL_ (-3078)
+
 
 /**
  * Set callbacks for this connection to those for HTTP.
diff --git a/src/microhttpd/connection_https.c 
b/src/microhttpd/connection_https.c
index dac4be65..14e129ad 100644
--- a/src/microhttpd/connection_https.c
+++ b/src/microhttpd/connection_https.c
@@ -41,7 +41,8 @@
  * @param connection the MHD_Connection structure
  * @param other where to write received data to
  * @param i maximum size of other (in bytes)
- * @return number of bytes actually received
+ * @return positive value for number of bytes actually received or
+ *         negative value for error number MHD_ERR_xxx_
  */
 static ssize_t
 recv_tls_adapter (struct MHD_Connection *connection,
@@ -59,21 +60,18 @@ recv_tls_adapter (struct MHD_Connection *connection,
   if ( (GNUTLS_E_AGAIN == res) ||
        (GNUTLS_E_INTERRUPTED == res) )
     {
-      MHD_socket_set_error_ (MHD_SCKT_EINTR_);
 #ifdef EPOLL_SUPPORT
       if (GNUTLS_E_AGAIN == res)
         connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
 #endif
-      return -1;
+      return MHD_ERR_AGAIN_;
     }
   if (res < 0)
     {
       /* Likely 'GNUTLS_E_INVALID_SESSION' (client communication
-         disrupted); set errno to something caller will interpret
-         correctly as a hard error */
-      MHD_socket_set_error_ (MHD_SCKT_ECONNRESET_);
+         disrupted); interpret as a hard error */
       connection->tls_read_ready = false;
-      return res;
+      return MHD_ERR_CONNRESET_;
     }
 
 #ifdef EPOLL_SUPPORT

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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