diff options
author | ng0 <ng0@n0.is> | 2019-07-26 20:43:14 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-07-26 20:43:14 +0000 |
commit | 2c1b1f146c4e54b3c6686742c5dd0b136e4c4fe8 (patch) | |
tree | f5e925d669aa167ee24dc9c5c12eb3cd752c5dd2 | |
parent | af387e7c28e930d93164edac4edf1bd07b2d83c5 (diff) | |
download | libmicrohttpd-2c1b1f146c4e54b3c6686742c5dd0b136e4c4fe8.tar.gz libmicrohttpd-2c1b1f146c4e54b3c6686742c5dd0b136e4c4fe8.zip |
for tests
-rw-r--r-- | src/microhttpd/mhd_send.c | 53 | ||||
-rw-r--r-- | src/microhttpd/mhd_sockets.c | 4 |
2 files changed, 35 insertions, 22 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index 5a8d9283..0946d96e 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -46,11 +46,12 @@ static void | |||
46 | post_cork_setsockopt (struct MHD_Connection *connection, | 46 | post_cork_setsockopt (struct MHD_Connection *connection, |
47 | bool want_cork) | 47 | bool want_cork) |
48 | { | 48 | { |
49 | #ifndef MSG_MORE | ||
49 | int ret; | 50 | int ret; |
50 | // const MHD_SCKT_OPT_BOOL_ state_val = val ? 1 : 0; | ||
51 | const MHD_SCKT_OPT_BOOL_ off_val = 0; | 51 | const MHD_SCKT_OPT_BOOL_ off_val = 0; |
52 | const MHD_SCKT_OPT_BOOL_ on_val = 1; | 52 | const MHD_SCKT_OPT_BOOL_ on_val = 1; |
53 | 53 | ||
54 | /* If sk_cork_on is already what we pass in, return. */ | ||
54 | if (connection->sk_cork_on == want_cork) | 55 | if (connection->sk_cork_on == want_cork) |
55 | { | 56 | { |
56 | /* nothing to do, success! */ | 57 | /* nothing to do, success! */ |
@@ -78,6 +79,7 @@ post_cork_setsockopt (struct MHD_Connection *connection, | |||
78 | connection->sk_cork_on = want_cork; | 79 | connection->sk_cork_on = want_cork; |
79 | } | 80 | } |
80 | return; | 81 | return; |
82 | #endif /* HAVE_MORE */ | ||
81 | } | 83 | } |
82 | 84 | ||
83 | /** | 85 | /** |
@@ -90,11 +92,12 @@ static void | |||
90 | pre_cork_setsockopt (struct MHD_Connection *connection, | 92 | pre_cork_setsockopt (struct MHD_Connection *connection, |
91 | bool want_cork) | 93 | bool want_cork) |
92 | { | 94 | { |
95 | #ifndef MSG_MORE | ||
93 | int ret; | 96 | int ret; |
94 | const MHD_SCKT_OPT_BOOL_ off_val = 0; | 97 | const MHD_SCKT_OPT_BOOL_ off_val = 0; |
95 | const MHD_SCKT_OPT_BOOL_ on_val = 1; | 98 | const MHD_SCKT_OPT_BOOL_ on_val = 1; |
96 | 99 | ||
97 | /* if sk_tcp_nodelay_on is already what we pass in, return. */ | 100 | /* If sk_cork_on is already what we pass in, return. */ |
98 | if (connection->sk_cork_on == want_cork) | 101 | if (connection->sk_cork_on == want_cork) |
99 | { | 102 | { |
100 | /* nothing to do, success! */ | 103 | /* nothing to do, success! */ |
@@ -128,6 +131,7 @@ pre_cork_setsockopt (struct MHD_Connection *connection, | |||
128 | connection->sk_cork_on = want_cork; | 131 | connection->sk_cork_on = want_cork; |
129 | } | 132 | } |
130 | return; | 133 | return; |
134 | #endif /* MSG_MORE */ | ||
131 | } | 135 | } |
132 | 136 | ||
133 | /** | 137 | /** |
@@ -162,6 +166,8 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
162 | const MHD_SCKT_OPT_BOOL_ off_val = 0; | 166 | const MHD_SCKT_OPT_BOOL_ off_val = 0; |
163 | const MHD_SCKT_OPT_BOOL_ on_val = 1; | 167 | const MHD_SCKT_OPT_BOOL_ on_val = 1; |
164 | 168 | ||
169 | connection->sk_cork_on = true; | ||
170 | |||
165 | /* error handling from send_param_adapter() */ | 171 | /* error handling from send_param_adapter() */ |
166 | if ((MHD_INVALID_SOCKET == s) || (MHD_CONNECTION_CLOSED == connection->state)) | 172 | if ((MHD_INVALID_SOCKET == s) || (MHD_CONNECTION_CLOSED == connection->state)) |
167 | { | 173 | { |
@@ -190,13 +196,8 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
190 | } | 196 | } |
191 | 197 | ||
192 | /* ! could be avoided by redefining the variable. */ | 198 | /* ! could be avoided by redefining the variable. */ |
193 | bool have_cork = ! connection->sk_tcp_nodelay_on; | 199 | // bool have_cork = ! connection->sk_tcp_nodelay_on; |
194 | 200 | bool have_cork = ! connection->sk_cork_on; | |
195 | #ifdef MSG_MORE | ||
196 | have_more = true; | ||
197 | #else | ||
198 | have_more = false; | ||
199 | #endif | ||
200 | 201 | ||
201 | #ifdef HTTPS_SUPPORT | 202 | #ifdef HTTPS_SUPPORT |
202 | using_tls = (0 != (connection->daemon->options & MHD_USE_TLS)); | 203 | using_tls = (0 != (connection->daemon->options & MHD_USE_TLS)); |
@@ -209,7 +210,6 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
209 | { | 210 | { |
210 | gnutls_record_cork (connection->tls_session); | 211 | gnutls_record_cork (connection->tls_session); |
211 | connection->sk_cork_on = false; | 212 | connection->sk_cork_on = false; |
212 | // connection->sk_tcp_nodelay_on = false; | ||
213 | } | 213 | } |
214 | if (buffer_size > SSIZE_MAX) | 214 | if (buffer_size > SSIZE_MAX) |
215 | buffer_size = SSIZE_MAX; | 215 | buffer_size = SSIZE_MAX; |
@@ -241,15 +241,13 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
241 | { | 241 | { |
242 | (void) gnutls_record_uncork (connection->tls_session, 0); | 242 | (void) gnutls_record_uncork (connection->tls_session, 0); |
243 | connection->sk_cork_on = true; | 243 | connection->sk_cork_on = true; |
244 | // connection->sk_tcp_nodelay_on = true; | ||
245 | } | 244 | } |
246 | } | 245 | } |
247 | else | 246 | else |
248 | #endif | 247 | #endif |
249 | { | 248 | { |
250 | /* plaintext transmission */ | 249 | /* plaintext transmission */ |
251 | if (! have_more) | 250 | pre_cork_setsockopt (connection, want_cork); |
252 | pre_cork_setsockopt (connection, want_cork); | ||
253 | #if MSG_MORE | 251 | #if MSG_MORE |
254 | ret = send (s, | 252 | ret = send (s, |
255 | buffer, | 253 | buffer, |
@@ -282,8 +280,8 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
282 | else if (buffer_size > (size_t) ret) | 280 | else if (buffer_size > (size_t) ret) |
283 | connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; | 281 | connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; |
284 | #endif /* EPOLL_SUPPORT */ | 282 | #endif /* EPOLL_SUPPORT */ |
285 | if (! have_more) | 283 | |
286 | post_cork_setsockopt (connection, want_cork); | 284 | post_cork_setsockopt (connection, want_cork); |
287 | } | 285 | } |
288 | 286 | ||
289 | return ret; | 287 | return ret; |
@@ -317,13 +315,15 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
317 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) | 315 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) |
318 | MHD_socket s = connection->socket_fd; | 316 | MHD_socket s = connection->socket_fd; |
319 | bool have_cork; | 317 | bool have_cork; |
320 | bool have_more; | ||
321 | int iovcnt; | 318 | int iovcnt; |
322 | int eno; | 319 | int eno; |
323 | const MHD_SCKT_OPT_BOOL_ off_val = 0; | 320 | const MHD_SCKT_OPT_BOOL_ off_val = 0; |
324 | struct iovec vector[2]; | 321 | struct iovec vector[2]; |
325 | 322 | ||
326 | have_cork = ! connection->sk_tcp_nodelay_on; | 323 | connection->sk_cork_on = true; |
324 | |||
325 | have_cork = ! connection->sk_cork_on; | ||
326 | /* | ||
327 | #if TCP_NODELAY | 327 | #if TCP_NODELAY |
328 | use_corknopush = false; | 328 | use_corknopush = false; |
329 | #elif TCP_CORK | 329 | #elif TCP_CORK |
@@ -331,13 +331,17 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
331 | #elif TCP_NOPUSH | 331 | #elif TCP_NOPUSH |
332 | use_corknopush = true; | 332 | use_corknopush = true; |
333 | #endif | 333 | #endif |
334 | */ | ||
334 | 335 | ||
336 | pre_cork_setsockopt (connection, want_cork); | ||
337 | /* | ||
335 | #if TCP_NODELAY | 338 | #if TCP_NODELAY |
336 | if ((! use_corknopush) && (! have_cork && want_cork)) | 339 | if ((! use_corknopush) && (! have_cork && want_cork)) |
337 | { | 340 | { |
338 | MHD_setsockopt_ (connection, TCP_NODELAY, false, false); | 341 | MHD_setsockopt_ (connection, TCP_NODELAY, false, false); |
339 | } | 342 | } |
340 | #endif | 343 | #endif |
344 | */ | ||
341 | 345 | ||
342 | vector[0].iov_base = header; | 346 | vector[0].iov_base = header; |
343 | vector[0].iov_len = strlen (header); | 347 | vector[0].iov_len = strlen (header); |
@@ -354,6 +358,9 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
354 | ret = writev (s, vector, iovcnt); | 358 | ret = writev (s, vector, iovcnt); |
355 | #endif | 359 | #endif |
356 | 360 | ||
361 | post_cork_setsockopt (connection, want_cork); | ||
362 | |||
363 | /* | ||
357 | #if TCP_CORK | 364 | #if TCP_CORK |
358 | if (use_corknopush) | 365 | if (use_corknopush) |
359 | { | 366 | { |
@@ -376,13 +383,15 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
376 | eno = errno; | 383 | eno = errno; |
377 | if (ret == header_len + buffer_len) | 384 | if (ret == header_len + buffer_len) |
378 | { | 385 | { |
379 | /* Response complete, set NOPUSH to off */ | 386 | // Response complete, set NOPUSH to off |
380 | MHD_setsockopt_ (connection, TCP_NOPUSH, false, false); | 387 | MHD_setsockopt_ (connection, TCP_NOPUSH, false, false); |
381 | } | 388 | } |
382 | errno = eno; | 389 | errno = eno; |
383 | } | 390 | } |
384 | return ret; | 391 | return ret; |
385 | #endif | 392 | #endif |
393 | */ | ||
394 | return ret; | ||
386 | 395 | ||
387 | #else | 396 | #else |
388 | return MHD_send_on_connection_ (connection, | 397 | return MHD_send_on_connection_ (connection, |
diff --git a/src/microhttpd/mhd_sockets.c b/src/microhttpd/mhd_sockets.c index 04405945..bc924651 100644 --- a/src/microhttpd/mhd_sockets.c +++ b/src/microhttpd/mhd_sockets.c | |||
@@ -474,20 +474,24 @@ MHD_socket_buffering_reset_ (MHD_socket sock) | |||
474 | #if defined(TCP_NODELAY) || defined(MHD_TCP_CORK_NOPUSH) | 474 | #if defined(TCP_NODELAY) || defined(MHD_TCP_CORK_NOPUSH) |
475 | const MHD_SCKT_OPT_BOOL_ off_val = 0; | 475 | const MHD_SCKT_OPT_BOOL_ off_val = 0; |
476 | #if defined(MHD_TCP_CORK_NOPUSH) | 476 | #if defined(MHD_TCP_CORK_NOPUSH) |
477 | #if OLD_SOCKOPT | ||
477 | /* Disable extra buffering */ | 478 | /* Disable extra buffering */ |
478 | res = (0 == setsockopt (sock, | 479 | res = (0 == setsockopt (sock, |
479 | IPPROTO_TCP, | 480 | IPPROTO_TCP, |
480 | MHD_TCP_CORK_NOPUSH, | 481 | MHD_TCP_CORK_NOPUSH, |
481 | (const void *) &off_val, | 482 | (const void *) &off_val, |
482 | sizeof (off_val))) && res; | 483 | sizeof (off_val))) && res; |
484 | #endif | ||
483 | #endif /* MHD_TCP_CORK_NOPUSH */ | 485 | #endif /* MHD_TCP_CORK_NOPUSH */ |
484 | #if defined(TCP_NODELAY) | 486 | #if defined(TCP_NODELAY) |
487 | #if OLD_SOCKOPT | ||
485 | /* Enable Nagle's algorithm for normal buffering */ | 488 | /* Enable Nagle's algorithm for normal buffering */ |
486 | res = (0 == setsockopt (sock, | 489 | res = (0 == setsockopt (sock, |
487 | IPPROTO_TCP, | 490 | IPPROTO_TCP, |
488 | TCP_NODELAY, | 491 | TCP_NODELAY, |
489 | (const void *) &off_val, | 492 | (const void *) &off_val, |
490 | sizeof (off_val))) && res; | 493 | sizeof (off_val))) && res; |
494 | #endif | ||
491 | #endif /* TCP_NODELAY */ | 495 | #endif /* TCP_NODELAY */ |
492 | #else /* !TCP_NODELAY && !MHD_TCP_CORK_NOPUSH */ | 496 | #else /* !TCP_NODELAY && !MHD_TCP_CORK_NOPUSH */ |
493 | (void) sock; | 497 | (void) sock; |