commit f5170975b4fad18e6156884aef533b137843cff3
parent 1f08febcc06a20ba2ce4412b8a3b04943965d7d3
Author: Christian Grothoff <christian@grothoff.org>
Date: Fri, 19 Jul 2019 19:12:00 +0200
move TLS branch to right position
Diffstat:
1 file changed, 40 insertions(+), 36 deletions(-)
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
@@ -81,6 +81,7 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
bool want_cork;
bool have_cork;
bool have_more;
+ bool using_tls = false;
/* The socket. */
MHD_socket s = connection->socket_fd;
int eno;
@@ -137,6 +138,10 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
use_corknopush = true;
#endif
+#ifdef HTTPS_SUPPORT
+ using_tls = (0 != (connection->daemon->options & MHD_USE_TLS));
+#endif
+
#if TCP_CORK
if (use_corknopush)
{
@@ -197,16 +202,23 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
}
#endif
- // prepare the send() to return.
+#ifdef HTTPS_SUPPORT
+ if (using_tls)
+ {
+ send_tls_adapter(connection, buffer, buffer_size);
+ }
+ else
+#endif
+ {
#if MSG_MORE
- ret = send (connection->socket_fd,
- buffer,
- buffer_size,
- (want_cork ? MSG_MORE : 0));
+ ret = send (connection->socket_fd,
+ buffer,
+ buffer_size,
+ (want_cork ? MSG_MORE : 0));
#else
- ret = send (connection->socket_fd, buffer, buffer_size, 0);
+ ret = send (connection->socket_fd, buffer, buffer_size, 0);
#endif
-
+ }
#if TCP_CORK
if (use_corknopush)
{
@@ -261,39 +273,31 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
gnutls_record_uncork(connection->tls_session);
*/
- /* for TLS*/
-
- if (0 != (connection->daemon->options & MHD_USE_TLS))
- send_tls_adapter(connection, buffer, buffer_size);
- else {
-
- // 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_;
- }
+ // 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
- else if (buffer_size > (size_t) ret)
+ /* EAGAIN, no longer write-ready */
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:
- // eno = errno;
+ 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;
}