libmicrohttpd

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

commit 9a088e236f55f076d2500f023949bff74f72e930
parent 304002d6b1d88baa747207f0d5d8ae77bda2b118
Author: ng0 <ng0@n0.is>
Date:   Wed, 24 Jul 2019 12:22:04 +0000

Add MHD_send_socket_state_cork_nodelay_ and use it.

Diffstat:
Msrc/microhttpd/mhd_send.c | 82++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Msrc/microhttpd/mhd_send.h | 7+++++++
2 files changed, 57 insertions(+), 32 deletions(-)

diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c @@ -64,6 +64,46 @@ MHD_send_socket_state_nodelay_ (struct MHD_Connection *connection, } /** + * Set TCP_NODELAY flag on socket and save the + * #sk_tcp_nodelay_on state. + * + * @param connection the MHD_Connection structure + * @param cork_value the state to set, boolean + * @param cork_state the boolean value passed to #sk_tcp_nodelay_on + * @param nodelay_value the state to set, boolean + * @param nodelay_state the boolean value passed to #sk_tcp_nodelay_on + */ +void +MHD_send_socket_state_cork_nodelay_ (struct MHD_Connection *connection, + bool cork_value, + bool cork_state, + bool nodelay_value, + bool nodelay_state) +{ +#if TCP_CORK && TCP_NODELAY + const MHD_SCKT_OPT_BOOL_ cork_state_val = cork_value ? 1 : 0; + const MHD_SCKT_OPT_BOOL_ nodelay_state_val = nodelay_value ? 1 : 0; + + if (0 == setsockopt (connection->socket_fd, + IPPROTO_TCP, + TCP_CORK, + (const void *) &cork_state_val, + sizeof (cork_state_val))) + { + connection->sk_tcp_nodelay_on = cork_state; + } + else if (0 == setsockopt (connection->socket_fd, + IPPROTO_TCP, + TCP_NODELAY, + (const void *) &nodelay_state_val, + sizeof (nodelay_state_val))) + { + connection->sk_tcp_nodelay_on = nodelay_state; + } +#endif +} + +/** * Set TCP_NOPUSH flag on socket and save the * #sk_tcp_nodelay_on state. * @@ -183,22 +223,11 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, * No other system in 2019-06 has TCP_CORK. */ if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork)) { - if (0 == setsockopt (s, - IPPROTO_TCP, - TCP_CORK, - (const void *) &off_val, - sizeof (off_val))) - { - connection->sk_tcp_nodelay_on = true; - } - else if (0 == setsockopt (s, - IPPROTO_TCP, - TCP_NODELAY, - (const void *) &on_val, - sizeof (on_val))) - { - connection->sk_tcp_nodelay_on = true; - } + MHD_send_socket_state_cork_nodelay_ (connection, + false, + true, + true, + true); } #elif TCP_NOPUSH /* TCP_NOPUSH on FreeBSD is equal to cork on Linux, with the @@ -297,22 +326,11 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, #if TCP_CORK if ((! using_tls) && (use_corknopush) && (! have_cork && want_cork && ! have_more)) { - if (0 == setsockopt (s, - IPPROTO_TCP, - TCP_CORK, - (const void *) &on_val, - sizeof (on_val))) - { - connection->sk_tcp_nodelay_on = false; - } - else if (0 == setsockopt (s, - IPPROTO_TCP, - TCP_NODELAY, - (const void *) &off_val, - sizeof (off_val))) - { - connection->sk_tcp_nodelay_on = false; - } + MHD_send_socket_state_cork_nodelay_ (connection, + true, + false, + false, + false); } #elif TCP_NOPUSH /* We don't have MSG_MORE. The OS which implement NOPUSH implement diff --git a/src/microhttpd/mhd_send.h b/src/microhttpd/mhd_send.h @@ -86,4 +86,11 @@ MHD_send_socket_state_nopush_ (struct MHD_Connection *connection, void MHD_send_socket_state_nodelay_ (struct MHD_Connection *connection, bool value); + +void +MHD_send_socket_state_cork_nodelay_ (struct MHD_Connection *connection, + bool cork_value, + bool cork_state, + bool nodelay_value, + bool nodelay_state); #endif /* MHD_SEND_H */