libmicrohttpd

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

commit 26368ac8f1a32f49eaffae77abcfc595c62802bd
parent 97fd0a6557b98166f9617370e1497d47e80e9a04
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  1 Aug 2019 21:40:47 +0200

add ways for application to control corking for upgraded sockets

Diffstat:
Msrc/include/microhttpd.h | 12+++++++++++-
Msrc/microhttpd/connection.c | 2+-
Msrc/microhttpd/response.c | 38++++++++++++++++++++++++++++++++++++++
Msrc/microhttpd/test_upgrade.c | 2++
4 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -3132,7 +3132,17 @@ enum MHD_UpgradeAction * * Takes no extra arguments. */ - MHD_UPGRADE_ACTION_CLOSE = 0 + MHD_UPGRADE_ACTION_CLOSE = 0, + + /** + * Enable CORKing on the underlying socket. + */ + MHD_UPGRADE_ACTION_CORK_ON = 1, + + /** + * Disable CORKing on the underlying socket. + */ + MHD_UPGRADE_ACTION_CORK_OFF = 2 }; diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -3181,7 +3181,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) return; case MHD_CONNECTION_HEADERS_SENDING: { - const size_t wb_ready =connection->write_buffer_append_offset - + const size_t wb_ready = connection->write_buffer_append_offset - connection->write_buffer_send_offset; /* if the response body is not available, we use MHD_send_on_connection_() */ diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -825,6 +825,44 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, * be moved to cleanup list by MHD_resume_connection(). */ MHD_resume_connection (connection); return MHD_YES; + case MHD_UPGRADE_ACTION_CORK_ON: + if (connection->sk_cork_on) + return MHD_YES; +#ifdef HTTPS_SUPPORT + if (0 != (daemon->options & MHD_USE_TLS) ) + { + gnutls_record_cork (connection->tls_session); + connection->sk_cork_on = true; + return MHD_YES; + } + else +#else + { + if (0 == + MHD_socket_cork_ (connection->socket_fd, + true)) + connection->sk_cork_on = true; + } +#endif + case MHD_UPGRADE_ACTION_CORK_OFF: + if (! connection->sk_cork_on) + return MHD_YES; +#ifdef HTTPS_SUPPORT + if (0 != (daemon->options & MHD_USE_TLS) ) + { + gnutls_record_uncork (connection->tls_session, 0); + connection->sk_cork_on = false; + return MHD_YES; + } + else +#else + { + if (0 == + MHD_socket_cork_ (connection->socket_fd, + false)) + connection->sk_cork_on = false; + } +#endif default: /* we don't understand this one */ return MHD_NO; diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c @@ -685,6 +685,8 @@ run_usock (void *cls) { struct MHD_UpgradeResponseHandle *urh = cls; + MHD_upgrade_action (urh, + MHD_UPGRADE_ACTION_CORK_OFF); send_all (usock, "Hello"); recv_all (usock,