aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-07-24 13:32:01 +0000
committerng0 <ng0@n0.is>2019-07-24 13:32:01 +0000
commitcf1206ff78e7e9d0d3e5eab7c05a06ab67cc2d8e (patch)
treedf934d5c042bcab523d2d514deffbcd68efc75d2 /src
parenta1a0bf1a0a1f6b4fcb55c9cb0262a31759b45a65 (diff)
downloadlibmicrohttpd-cf1206ff78e7e9d0d3e5eab7c05a06ab67cc2d8e.tar.gz
libmicrohttpd-cf1206ff78e7e9d0d3e5eab7c05a06ab67cc2d8e.zip
conditionally return and setsockopt.
Diffstat (limited to 'src')
-rw-r--r--src/microhttpd/connection.c64
1 files changed, 36 insertions, 28 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 4b8b7a4a..02f065a0 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -295,6 +295,7 @@ sendfile_adapter (struct MHD_Connection *connection)
295 bool using_tls = false; 295 bool using_tls = false;
296 296
297 ssize_t ret; 297 ssize_t ret;
298 ssize_t lo_ret;
298 const int file_fd = connection->response->fd; 299 const int file_fd = connection->response->fd;
299 uint64_t left; 300 uint64_t left;
300 uint64_t offsetu64; 301 uint64_t offsetu64;
@@ -461,51 +462,58 @@ sendfile_adapter (struct MHD_Connection *connection)
461 ret = (ssize_t)len; 462 ret = (ssize_t)len;
462#endif /* HAVE_FREEBSD_SENDFILE */ 463#endif /* HAVE_FREEBSD_SENDFILE */
463 464
464 /* ! could be avoided by redefining the variable. */ 465 ret = lo_ret;
465 have_cork = ! connection->sk_tcp_nodelay_on; 466 (if 0 > ret)
467 {
468 /* ! could be avoided by redefining the variable. */
469 have_cork = ! connection->sk_tcp_nodelay_on;
466 470
467#ifdef MSG_MORE 471#ifdef MSG_MORE
468 have_more = true; 472 have_more = true;
469#else 473#else
470 have_more = false; 474 have_more = false;
471#endif 475#endif
472 476
473#if TCP_NODELAY 477#if TCP_NODELAY
474 use_corknopush = false; 478 use_corknopush = false;
475#elif TCP_CORK 479#elif TCP_CORK
476 use_corknopush = true; 480 use_corknopush = true;
477#elif TCP_NOPUSH 481#elif TCP_NOPUSH
478 use_corknopush = true; 482 use_corknopush = true;
479#endif 483#endif
480 484
481#ifdef HTTPS_SUPPORT 485#ifdef HTTPS_SUPPORT
482 using_tls = (0 != (connection->daemon->options & MHD_USE_TLS)); 486 using_tls = (0 != (connection->daemon->options & MHD_USE_TLS));
483#endif 487#endif
484 488
485#if TCP_CORK 489#if TCP_CORK
486 /* When we have CORK, we can have NODELAY on the same system, 490 /* When we have CORK, we can have NODELAY on the same system,
487 * at least since Linux 2.2 and both can be combined since 491 * at least since Linux 2.2 and both can be combined since
488 * Linux 2.5.71. For more details refer to tcp(7) on Linux. 492 * Linux 2.5.71. For more details refer to tcp(7) on Linux.
489 * No other system in 2019-06 has TCP_CORK. */ 493 * No other system in 2019-06 has TCP_CORK. */
490 if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork)) 494 if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork))
491 { 495 {
492 MHD_send_socket_state_cork_nodelay_ (connection, 496 MHD_send_socket_state_cork_nodelay_ (connection,
493 false, 497 false,
494 true, 498 true,
495 true, 499 true,
496 true); 500 true);
497 } 501 }
498#elif TCP_NOPUSH 502#elif TCP_NOPUSH
499 /* TCP_NOPUSH on FreeBSD is equal to cork on Linux, with the 503 /* TCP_NOPUSH on FreeBSD is equal to cork on Linux, with the
500 * exception that we know that TCP_NOPUSH will definitely 504 * exception that we know that TCP_NOPUSH will definitely
501 * exist and we can disregard TCP_NODELAY unless requested. */ 505 * exist and we can disregard TCP_NODELAY unless requested. */
502 if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork)) 506 if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork))
507 {
508 MHD_send_socket_state_nopush_ (connection, true, false);
509 }
510#endif
511 return lo_ret;
512 }
513 else
503 { 514 {
504 MHD_send_socket_state_nopush_ (connection, true, false); 515 return ret;
505 } 516 }
506#endif
507
508 return ret;
509} 517}
510#endif /* _MHD_HAVE_SENDFILE */ 518#endif /* _MHD_HAVE_SENDFILE */
511 519