libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit c5b661b67239534f976da20f95a4f0ff53e7700e
parent 17934e4ebf550d3df5abe785bbdee34fd0c4b61b
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sun, 18 Apr 2021 17:13:01 +0300

mhd_send: more detailed error results

Diffstat:
Msrc/microhttpd/connection.h | 10++++++++++
Msrc/microhttpd/mhd_send.c | 46++++++++++++++++++++++++++++++++++++++++------
Msrc/microhttpd/mhd_sockets.h | 10++++++++--
3 files changed, 58 insertions(+), 8 deletions(-)

diff --git 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 @@ -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.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