aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_sockets.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_sockets.c')
-rw-r--r--src/microhttpd/mhd_sockets.c88
1 files changed, 68 insertions, 20 deletions
diff --git a/src/microhttpd/mhd_sockets.c b/src/microhttpd/mhd_sockets.c
index 04405945..b4e73480 100644
--- a/src/microhttpd/mhd_sockets.c
+++ b/src/microhttpd/mhd_sockets.c
@@ -462,6 +462,64 @@ MHD_socket_noninheritable_ (MHD_socket sock)
462 462
463 463
464/** 464/**
465 * Disable Nagle's algorithm on @a sock. This is what we do by default for
466 * all TCP sockets in MHD, unless the platform does not support the MSG_MORE
467 * or MSG_CORK or MSG_NOPUSH options.
468 *
469 * @param sock socket to manipulate
470 * @param on value to use
471 * @return 0 on success
472 */
473int
474MHD_socket_set_nodelay_ (MHD_socket sock,
475 bool on)
476{
477#ifdef TCP_NODELAY
478 {
479 const MHD_SCKT_OPT_BOOL_ off_val = 0;
480 const MHD_SCKT_OPT_BOOL_ on_val = 1;
481 /* Disable Nagle's algorithm for normal buffering */
482 return setsockopt (sock,
483 IPPROTO_TCP,
484 TCP_NODELAY,
485 (const void *) (on) ? &on_val : &off_val,
486 sizeof (on_val));
487 }
488#else
489 (void) sock;
490 return 0;
491#endif /* TCP_NODELAY */
492}
493
494
495/**
496 * Enable/disable the cork option.
497 *
498 * @param sock socket to manipulate
499 * @param on set to true to enable CORK, false to disable
500 * @return non-zero if succeeded, zero otherwise
501 */
502int
503MHD_socket_cork_ (MHD_socket sock,
504 bool on)
505{
506#if defined(MHD_TCP_CORK_NOPUSH)
507 const MHD_SCKT_OPT_BOOL_ off_val = 0;
508 const MHD_SCKT_OPT_BOOL_ on_val = 1;
509
510 /* Disable extra buffering */
511 return (0 == setsockopt (sock,
512 IPPROTO_TCP,
513 MHD_TCP_CORK_NOPUSH,
514 (const void *) (on ? &on_val : &off_val),
515 sizeof (off_val)));
516#else
517 return 0;
518#endif /* MHD_TCP_CORK_NOPUSH */
519}
520
521
522/**
465 * Change socket buffering mode to default. 523 * Change socket buffering mode to default.
466 * 524 *
467 * @param sock socket to manipulate 525 * @param sock socket to manipulate
@@ -470,29 +528,19 @@ MHD_socket_noninheritable_ (MHD_socket sock)
470int 528int
471MHD_socket_buffering_reset_ (MHD_socket sock) 529MHD_socket_buffering_reset_ (MHD_socket sock)
472{ 530{
473 int res = !0;
474#if defined(TCP_NODELAY) || defined(MHD_TCP_CORK_NOPUSH)
475 const MHD_SCKT_OPT_BOOL_ off_val = 0;
476#if defined(MHD_TCP_CORK_NOPUSH) 531#if defined(MHD_TCP_CORK_NOPUSH)
532 int res = ! MHD_socket_set_nodelay_ (sock,
533 true);
477 /* Disable extra buffering */ 534 /* Disable extra buffering */
478 res = (0 == setsockopt (sock, 535 return MHD_socket_cork_ (sock,
479 IPPROTO_TCP, 536 false) && res;
480 MHD_TCP_CORK_NOPUSH, 537#elif defined(HAVE_MSG_MORE)
481 (const void *) &off_val, 538 return ! MHD_socket_set_nodelay_ (sock,
482 sizeof (off_val))) && res; 539 true);
540#else
541 return ! MHD_socket_set_nodelay_ (sock,
542 false);
483#endif /* MHD_TCP_CORK_NOPUSH */ 543#endif /* MHD_TCP_CORK_NOPUSH */
484#if defined(TCP_NODELAY)
485 /* Enable Nagle's algorithm for normal buffering */
486 res = (0 == setsockopt (sock,
487 IPPROTO_TCP,
488 TCP_NODELAY,
489 (const void *) &off_val,
490 sizeof (off_val))) && res;
491#endif /* TCP_NODELAY */
492#else /* !TCP_NODELAY && !MHD_TCP_CORK_NOPUSH */
493 (void) sock;
494#endif /* !TCP_NODELAY && !MHD_TCP_CORK_NOPUSH */
495 return res;
496} 544}
497 545
498 546