[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libmicrohttpd] 25/154: inline TLS logic
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libmicrohttpd] 25/154: inline TLS logic |
Date: |
Mon, 19 Aug 2019 10:15:37 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository libmicrohttpd.
commit 5847d13f470d525502b991f94bd5e0f77c302368
Author: Christian Grothoff <address@hidden>
AuthorDate: Fri Jul 19 19:19:39 2019 +0200
inline TLS logic
---
src/microhttpd/mhd_send.c | 76 ++++++++++++++++++++++++++++++-----------------
1 file changed, 49 insertions(+), 27 deletions(-)
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index 315ee563..d713f1a8 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -85,7 +85,7 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
/* The socket. */
MHD_socket s = connection->socket_fd;
int eno;
- int ret;
+ ssize_t ret;
int optval;
const MHD_SCKT_OPT_BOOL_ off_val = 0;
const MHD_SCKT_OPT_BOOL_ on_val = 1;
@@ -205,11 +205,36 @@ MHD_send_on_connection_ (struct MHD_Connection
*connection,
#ifdef HTTPS_SUPPORT
if (using_tls)
{
- send_tls_adapter(connection, buffer, buffer_size);
+ if (i > SSIZE_MAX)
+ i = SSIZE_MAX;
+ ret = gnutls_record_send (connection->tls_session,
+ buffer,
+ buffer_size);
+ if ( (GNUTLS_E_AGAIN == ret) ||
+ (GNUTLS_E_INTERRUPTED == ret) )
+ {
+#ifdef EPOLL_SUPPORT
+ if (GNUTLS_E_AGAIN == ret)
+ connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
+#endif
+ return MHD_ERR_AGAIN_;
+ }
+ if (ret < 0)
+ {
+ /* Likely 'GNUTLS_E_INVALID_SESSION' (client communication
+ disrupted); interpret as a hard error */
+ return MHD_ERR_NOTCONN_;
+ }
+#ifdef EPOLL_SUPPORT
+ /* Unlike non-TLS connections, do not reset "write-ready" if
+ * sent amount smaller than provided amount, as TLS
+ * connections may break data into smaller parts for sending. */
+#endif /* EPOLL_SUPPORT */
}
else
#endif
{
+ /* plaintext transmission */
#if MSG_MORE
ret = send (connection->socket_fd,
buffer,
@@ -218,6 +243,28 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
#else
ret = send (connection->socket_fd, buffer, buffer_size, 0);
#endif
+
+ if (0 > ret)
+ {
+ if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
+ {
+#if EPOLL_SUPPORT
+ /* EAGAIN, no longer write-ready */
+ connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
+#endif /* EPOLL_SUPPORT */
+ return MHD_ERR_AGAIN_;
+ }
+ if (MHD_SCKT_ERR_IS_EINTR_ (err))
+ return MHD_ERR_AGAIN_;
+ if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_))
+ return MHD_ERR_CONNRESET_;
+ /* Treat any other error as hard error. */
+ return MHD_ERR_NOTCONN_;
+ }
+#if EPOLL_SUPPORT
+ else if (buffer_size > (size_t) ret)
+ connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
+#endif /* EPOLL_SUPPORT */
}
#if TCP_CORK
if (use_corknopush)
@@ -273,31 +320,6 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
gnutls_record_uncork(connection->tls_session);
*/
- // shouldn't we return 0 or -1? Why re-use the _ERR_ functions?
- // error handling from send_param_adapter():
- if (0 > ret)
- {
- if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
- {
-#if EPOLL_SUPPORT
- /* EAGAIN, no longer write-ready */
- connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
-#endif /* EPOLL_SUPPORT */
- return MHD_ERR_AGAIN_;
- }
- if (MHD_SCKT_ERR_IS_EINTR_ (err))
- return MHD_ERR_AGAIN_;
- if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_))
- return MHD_ERR_CONNRESET_;
- /* Treat any other error as hard error. */
- return MHD_ERR_NOTCONN_;
- }
-#if EPOLL_SUPPORT
- else if (buffer_size > (size_t) ret)
- connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
-#endif /* EPOLL_SUPPORT */
- // return ret; // should be return at the end of the function?
- // previous error save:
errno = eno;
return ret;
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [GNUnet-SVN] [libmicrohttpd] 22/154: mhd_send.c: call send_tls_adapter() when TLS is used., (continued)
- [GNUnet-SVN] [libmicrohttpd] 22/154: mhd_send.c: call send_tls_adapter() when TLS is used., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 24/154: move TLS branch to right position, gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 37/154: flatten if statements, add initial TCP_NOPUSH to MHD_send_on_connection2_, gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 39/154: indent, gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 33/154: replace connection->send_cls(), gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 13/154: mhd_send.c: fix compiler error about MSG_MORE when MSG_MORE is undefined., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 18/154: more from connection.c, without checks so far., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 16/154: mhd_send: Use MHD_SCKT_OPT_BOOL_ for setsockopt optval., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 28/154: fixes, gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 43/154: move comment above function., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 25/154: inline TLS logic,
gnunet <=
- [GNUnet-SVN] [libmicrohttpd] 15/154: iAdd headerfile for mhd_send., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 26/154: indentation, comments, issue, gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 29/154: fix err logic, gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 10/154: mhd_send: Restructure., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 27/154: fixes, gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 32/154: setsockopt(): check return value., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 21/154: mhd_send.c: Use daemon from connection struct., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 45/154: fix compiler error., gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 44/154: remove verbose comments in mhd_send.c, gnunet, 2019/08/19
- [GNUnet-SVN] [libmicrohttpd] 55/154: doxygen: MHD_SSO, gnunet, 2019/08/19