libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit e127b8a6c4a0a72b5786c50a9b46196143e7af6c
parent 404d4b4472f5714a7e32422e5aa663b964f97652
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sun,  1 Oct 2017 18:44:45 +0300

Added detection for Linux form of sendfile(2)

Diffstat:
Mconfigure.ac | 39++++++++++++++++++++++++++++++++++++++-
Msrc/microhttpd/connection.c | 20++++++++++----------
Msrc/microhttpd/internal.h | 4++--
3 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -1229,7 +1229,43 @@ AM_CONDITIONAL([HAVE_LIBMAGIC], [[test "x$mhd_have_libmagic" = "xyes"]]) # large file support (> 4 GB) AC_SYS_LARGEFILE AC_FUNC_FSEEKO -AC_CHECK_FUNCS([lseek64 sendfile64 pread64 pread]) +AC_CHECK_FUNCS([lseek64 pread64 pread]) + +# check for various sendfile functions +found_sendfile="no" +AC_MSG_CHECKING([[for Linux-style sendfile(2)]]) +AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include <sys/sendfile.h> + +static void empty_func(void) +{ +/* Check for declaration */ + (void)sendfile; +} +/* Declare again to check form match */ +ssize_t sendfile(int, int, off_t*, size_t); + ]], + [[ + int fd1, fd2; + off_t o = 0; + size_t s = 5; + ssize_t r; + r = sendfile (fd1, fd2, &o, s); + empty_func(); + ]] + ) + ], + [ + AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).]) + found_sendfile="yes, linux-style" + AC_MSG_RESULT([[yes]]) + AC_CHECK_FUNCS([sendfile64]) + ], + [AC_MSG_RESULT([[no]]) + ] +) # optional: have error messages ? AC_MSG_CHECKING([[whether to generate error messages]]) @@ -1781,6 +1817,7 @@ AC_MSG_NOTICE([libmicrohttpd ${PACKAGE_VERSION} Configuration Summary: HTTPS support: ${MSG_HTTPS} poll support: ${enable_poll=no} epoll support: ${enable_epoll=no} + sendfile used: ${found_sendfile} build docs: ${enable_doc} build examples: ${enable_examples} ]) diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -36,9 +36,9 @@ #include "mhd_sockets.h" #include "mhd_compat.h" #include "mhd_itc.h" -#ifdef __linux__ +#ifdef HAVE_LINUX_SENDFILE #include <sys/sendfile.h> -#endif +#endif /* HAVE_LINUX_SENDFILE */ #ifdef HTTPS_SUPPORT #include "connection_https.h" #endif /* HTTPS_SUPPORT */ @@ -219,7 +219,7 @@ send_param_adapter (struct MHD_Connection *connection, } -#ifdef __linux__ +#ifdef HAVE_LINUX_SENDFILE /** * Function for sending responses backed by file FD. * @@ -303,7 +303,7 @@ sendfile_adapter (struct MHD_Connection *connection) #endif /* EPOLL_SUPPORT */ return ret; } -#endif /* __linux__ */ +#endif /* HAVE_LINUX_SENDFILE */ /** @@ -935,7 +935,7 @@ try_ready_normal_body (struct MHD_Connection *connection) (response->data_size + response->data_start > connection->response_write_position) ) return MHD_YES; /* response already ready */ -#if LINUX +#if defined(HAVE_LINUX_SENDFILE) if (MHD_resp_sender_sendfile == connection->resp_sender) { /* will use sendfile, no need to bother response crc */ @@ -2877,15 +2877,15 @@ MHD_connection_handle_write (struct MHD_Connection *connection) /* mutex was already unlocked by try_ready_normal_body */ return; } -#ifdef __linux__ +#if defined(HAVE_LINUX_SENDFILE) if (MHD_resp_sender_sendfile == connection->resp_sender) { ret = sendfile_adapter (connection); } else -#else /* ! __linux__ */ +#else /* ! HAVE_LINUX_SENDFILE */ if (1) -#endif /* ! __linux__ */ +#endif /* ! HAVE_LINUX_SENDFILE */ { data_write_offset = connection->response_write_position - response->data_start; @@ -3821,13 +3821,13 @@ MHD_queue_response (struct MHD_Connection *connection, MHD_increment_response_rc (response); connection->response = response; connection->responseCode = status_code; -#if LINUX +#if defined(HAVE_LINUX_SENDFILE) if ( (response->fd == -1) || (0 != (connection->daemon->options & MHD_USE_TLS)) ) connection->resp_sender = MHD_resp_sender_std; else connection->resp_sender = MHD_resp_sender_sendfile; -#endif /* LINUX */ +#endif /* HAVE_LINUX_SENDFILE */ if ( ( (NULL != connection->method) && (MHD_str_equal_caseless_ (connection->method, diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -806,13 +806,13 @@ struct MHD_Connection */ uint64_t response_write_position; -#ifdef __linux__ +#if defined(HAVE_LINUX_SENDFILE) enum MHD_resp_sender_ { MHD_resp_sender_std = 0, MHD_resp_sender_sendfile } resp_sender; -#endif /* __linux__ */ +#endif /* HAVE_LINUX_SENDFILE */ /** * Position in the 100 CONTINUE message that