commit 727be7d294a49e8ec9553d541dec17c3e40ca386
parent 7ef7bab33db35986d3ced393ce8615f4a7c5a833
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Sun, 29 Nov 2020 22:06:59 +0300
mhd_send: use MSG_MORE only if it functions
Diffstat:
4 files changed, 12 insertions(+), 19 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -843,21 +843,6 @@ AC_SEARCH_LIBS(sendmsg, socket, AC_DEFINE([HAVE_SENDMSG],1,[Define if your platf
AC_MSG_CHECKING([whether writev is available])
AC_CHECK_FUNCS([writev])
-# check MSG_MORE defined
-AC_MSG_CHECKING([whether MSG_MORE is defined])
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
-#include <sys/types.h>
-#include <sys/socket.h>
-]],[[return MSG_MORE;]]
- )],
- [
- AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_MSG_MORE, [1], [have MSG_MORE])
- ],
- [
- AC_MSG_RESULT(no)
- ])
-
# set GCC options
# use '-fno-strict-aliasing', but only if the compiler
# and linker can take it
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
@@ -3507,7 +3507,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
}
return MHD_NO;
}
-#if defined(MHD_TCP_CORK_NOPUSH) || defined(HAVE_MSG_MORE)
+#if defined(MHD_TCP_CORK_NOPUSH) || defined(MHD_USE_MSG_MORE)
/* We will use TCP_CORK or TCP_NOPUSH or MSG_MORE to control
transmission, disable Nagle's algorithm (always) */
if ( (0 != MHD_socket_set_nodelay_ (s,
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
@@ -115,7 +115,7 @@ static void
pre_cork_setsockopt (struct MHD_Connection *connection,
bool want_cork)
{
-#if HAVE_MSG_MORE
+#ifdef MHD_USE_MSG_MORE
/* We use the MSG_MORE option for corking, no need for extra syscalls! */
(void) connection; /* Mute compiler warning. */
@@ -204,7 +204,7 @@ static void
post_cork_setsockopt (struct MHD_Connection *connection,
bool want_cork)
{
-#if HAVE_MSG_MORE
+#ifdef MHD_USE_MSG_MORE
/* We use the MSG_MORE option for corking, no need for extra syscalls! */
(void) connection; /* Mute compiler warning. */
@@ -398,7 +398,7 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
bool new_cork_state;
pre_cork_setsockopt (connection, want_cork);
-#if HAVE_MSG_MORE
+#ifdef MHD_USE_MSG_MORE
ret = send (s,
buffer,
buffer_size,
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
@@ -219,6 +219,14 @@ typedef SOCKET MHD_socket;
#define MHD_TCP_CORK_NOPUSH TCP_NOPUSH
#endif /* TCP_NOPUSH */
+#ifdef MSG_MORE
+#ifdef __linux__
+/* MSG_MORE signal kernel to buffer outbond data and works like
+ * TCP_CORK per call without actually setting TCP_CORK value.
+ * It's known to work on Linux. Add more OSes if they are compatible. */
+#define MHD_USE_MSG_MORE 1
+#endif /* __linux__ */
+#endif /* MSG_MORE */
/**
* MHD_SCKT_OPT_BOOL_ is type for bool parameters for setsockopt()/getsockopt()