aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-07-24 12:22:04 +0000
committerng0 <ng0@n0.is>2019-07-24 12:22:04 +0000
commit9a088e236f55f076d2500f023949bff74f72e930 (patch)
treec20ddcc33127d969a2e698f26e14b8c9b58f556f
parent304002d6b1d88baa747207f0d5d8ae77bda2b118 (diff)
downloadlibmicrohttpd-9a088e236f55f076d2500f023949bff74f72e930.tar.gz
libmicrohttpd-9a088e236f55f076d2500f023949bff74f72e930.zip
Add MHD_send_socket_state_cork_nodelay_ and use it.
-rw-r--r--src/microhttpd/mhd_send.c82
-rw-r--r--src/microhttpd/mhd_send.h7
2 files changed, 57 insertions, 32 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index 56461942..b235c6ff 100644
--- 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,
64} 64}
65 65
66/** 66/**
67 * Set TCP_NODELAY flag on socket and save the
68 * #sk_tcp_nodelay_on state.
69 *
70 * @param connection the MHD_Connection structure
71 * @param cork_value the state to set, boolean
72 * @param cork_state the boolean value passed to #sk_tcp_nodelay_on
73 * @param nodelay_value the state to set, boolean
74 * @param nodelay_state the boolean value passed to #sk_tcp_nodelay_on
75 */
76void
77MHD_send_socket_state_cork_nodelay_ (struct MHD_Connection *connection,
78 bool cork_value,
79 bool cork_state,
80 bool nodelay_value,
81 bool nodelay_state)
82{
83#if TCP_CORK && TCP_NODELAY
84 const MHD_SCKT_OPT_BOOL_ cork_state_val = cork_value ? 1 : 0;
85 const MHD_SCKT_OPT_BOOL_ nodelay_state_val = nodelay_value ? 1 : 0;
86
87 if (0 == setsockopt (connection->socket_fd,
88 IPPROTO_TCP,
89 TCP_CORK,
90 (const void *) &cork_state_val,
91 sizeof (cork_state_val)))
92 {
93 connection->sk_tcp_nodelay_on = cork_state;
94 }
95 else if (0 == setsockopt (connection->socket_fd,
96 IPPROTO_TCP,
97 TCP_NODELAY,
98 (const void *) &nodelay_state_val,
99 sizeof (nodelay_state_val)))
100 {
101 connection->sk_tcp_nodelay_on = nodelay_state;
102 }
103#endif
104}
105
106/**
67 * Set TCP_NOPUSH flag on socket and save the 107 * Set TCP_NOPUSH flag on socket and save the
68 * #sk_tcp_nodelay_on state. 108 * #sk_tcp_nodelay_on state.
69 * 109 *
@@ -183,22 +223,11 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
183 * No other system in 2019-06 has TCP_CORK. */ 223 * No other system in 2019-06 has TCP_CORK. */
184 if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork)) 224 if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork))
185 { 225 {
186 if (0 == setsockopt (s, 226 MHD_send_socket_state_cork_nodelay_ (connection,
187 IPPROTO_TCP, 227 false,
188 TCP_CORK, 228 true,
189 (const void *) &off_val, 229 true,
190 sizeof (off_val))) 230 true);
191 {
192 connection->sk_tcp_nodelay_on = true;
193 }
194 else if (0 == setsockopt (s,
195 IPPROTO_TCP,
196 TCP_NODELAY,
197 (const void *) &on_val,
198 sizeof (on_val)))
199 {
200 connection->sk_tcp_nodelay_on = true;
201 }
202 } 231 }
203#elif TCP_NOPUSH 232#elif TCP_NOPUSH
204 /* TCP_NOPUSH on FreeBSD is equal to cork on Linux, with the 233 /* TCP_NOPUSH on FreeBSD is equal to cork on Linux, with the
@@ -297,22 +326,11 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
297#if TCP_CORK 326#if TCP_CORK
298 if ((! using_tls) && (use_corknopush) && (! have_cork && want_cork && ! have_more)) 327 if ((! using_tls) && (use_corknopush) && (! have_cork && want_cork && ! have_more))
299 { 328 {
300 if (0 == setsockopt (s, 329 MHD_send_socket_state_cork_nodelay_ (connection,
301 IPPROTO_TCP, 330 true,
302 TCP_CORK, 331 false,
303 (const void *) &on_val, 332 false,
304 sizeof (on_val))) 333 false);
305 {
306 connection->sk_tcp_nodelay_on = false;
307 }
308 else if (0 == setsockopt (s,
309 IPPROTO_TCP,
310 TCP_NODELAY,
311 (const void *) &off_val,
312 sizeof (off_val)))
313 {
314 connection->sk_tcp_nodelay_on = false;
315 }
316 } 334 }
317#elif TCP_NOPUSH 335#elif TCP_NOPUSH
318 /* We don't have MSG_MORE. The OS which implement NOPUSH implement 336 /* 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
index c4a6d705..c01d9357 100644
--- 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,
86void 86void
87MHD_send_socket_state_nodelay_ (struct MHD_Connection *connection, 87MHD_send_socket_state_nodelay_ (struct MHD_Connection *connection,
88 bool value); 88 bool value);
89
90void
91MHD_send_socket_state_cork_nodelay_ (struct MHD_Connection *connection,
92 bool cork_value,
93 bool cork_state,
94 bool nodelay_value,
95 bool nodelay_state);
89#endif /* MHD_SEND_H */ 96#endif /* MHD_SEND_H */