aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-10-01 18:44:45 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-10-01 18:44:45 +0300
commite127b8a6c4a0a72b5786c50a9b46196143e7af6c (patch)
tree8f4da7818933d375ea812a2c6b70e25b0109c7ec
parent404d4b4472f5714a7e32422e5aa663b964f97652 (diff)
downloadlibmicrohttpd-e127b8a6c4a0a72b5786c50a9b46196143e7af6c.tar.gz
libmicrohttpd-e127b8a6c4a0a72b5786c50a9b46196143e7af6c.zip
Added detection for Linux form of sendfile(2)
-rw-r--r--configure.ac39
-rw-r--r--src/microhttpd/connection.c20
-rw-r--r--src/microhttpd/internal.h4
3 files changed, 50 insertions, 13 deletions
diff --git a/configure.ac b/configure.ac
index 683347ad..e4810e62 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1229,7 +1229,43 @@ AM_CONDITIONAL([HAVE_LIBMAGIC], [[test "x$mhd_have_libmagic" = "xyes"]])
1229# large file support (> 4 GB) 1229# large file support (> 4 GB)
1230AC_SYS_LARGEFILE 1230AC_SYS_LARGEFILE
1231AC_FUNC_FSEEKO 1231AC_FUNC_FSEEKO
1232AC_CHECK_FUNCS([lseek64 sendfile64 pread64 pread]) 1232AC_CHECK_FUNCS([lseek64 pread64 pread])
1233
1234# check for various sendfile functions
1235found_sendfile="no"
1236AC_MSG_CHECKING([[for Linux-style sendfile(2)]])
1237AC_LINK_IFELSE(
1238 [AC_LANG_PROGRAM(
1239 [[
1240#include <sys/sendfile.h>
1241
1242static void empty_func(void)
1243{
1244/* Check for declaration */
1245 (void)sendfile;
1246}
1247/* Declare again to check form match */
1248ssize_t sendfile(int, int, off_t*, size_t);
1249 ]],
1250 [[
1251 int fd1, fd2;
1252 off_t o = 0;
1253 size_t s = 5;
1254 ssize_t r;
1255 r = sendfile (fd1, fd2, &o, s);
1256 empty_func();
1257 ]]
1258 )
1259 ],
1260 [
1261 AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).])
1262 found_sendfile="yes, linux-style"
1263 AC_MSG_RESULT([[yes]])
1264 AC_CHECK_FUNCS([sendfile64])
1265 ],
1266 [AC_MSG_RESULT([[no]])
1267 ]
1268)
1233 1269
1234# optional: have error messages ? 1270# optional: have error messages ?
1235AC_MSG_CHECKING([[whether to generate error messages]]) 1271AC_MSG_CHECKING([[whether to generate error messages]])
@@ -1781,6 +1817,7 @@ AC_MSG_NOTICE([libmicrohttpd ${PACKAGE_VERSION} Configuration Summary:
1781 HTTPS support: ${MSG_HTTPS} 1817 HTTPS support: ${MSG_HTTPS}
1782 poll support: ${enable_poll=no} 1818 poll support: ${enable_poll=no}
1783 epoll support: ${enable_epoll=no} 1819 epoll support: ${enable_epoll=no}
1820 sendfile used: ${found_sendfile}
1784 build docs: ${enable_doc} 1821 build docs: ${enable_doc}
1785 build examples: ${enable_examples} 1822 build examples: ${enable_examples}
1786]) 1823])
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 2511230d..a7ad7220 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -36,9 +36,9 @@
36#include "mhd_sockets.h" 36#include "mhd_sockets.h"
37#include "mhd_compat.h" 37#include "mhd_compat.h"
38#include "mhd_itc.h" 38#include "mhd_itc.h"
39#ifdef __linux__ 39#ifdef HAVE_LINUX_SENDFILE
40#include <sys/sendfile.h> 40#include <sys/sendfile.h>
41#endif 41#endif /* HAVE_LINUX_SENDFILE */
42#ifdef HTTPS_SUPPORT 42#ifdef HTTPS_SUPPORT
43#include "connection_https.h" 43#include "connection_https.h"
44#endif /* HTTPS_SUPPORT */ 44#endif /* HTTPS_SUPPORT */
@@ -219,7 +219,7 @@ send_param_adapter (struct MHD_Connection *connection,
219} 219}
220 220
221 221
222#ifdef __linux__ 222#ifdef HAVE_LINUX_SENDFILE
223/** 223/**
224 * Function for sending responses backed by file FD. 224 * Function for sending responses backed by file FD.
225 * 225 *
@@ -303,7 +303,7 @@ sendfile_adapter (struct MHD_Connection *connection)
303#endif /* EPOLL_SUPPORT */ 303#endif /* EPOLL_SUPPORT */
304 return ret; 304 return ret;
305} 305}
306#endif /* __linux__ */ 306#endif /* HAVE_LINUX_SENDFILE */
307 307
308 308
309/** 309/**
@@ -935,7 +935,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
935 (response->data_size + response->data_start > 935 (response->data_size + response->data_start >
936 connection->response_write_position) ) 936 connection->response_write_position) )
937 return MHD_YES; /* response already ready */ 937 return MHD_YES; /* response already ready */
938#if LINUX 938#if defined(HAVE_LINUX_SENDFILE)
939 if (MHD_resp_sender_sendfile == connection->resp_sender) 939 if (MHD_resp_sender_sendfile == connection->resp_sender)
940 { 940 {
941 /* will use sendfile, no need to bother response crc */ 941 /* will use sendfile, no need to bother response crc */
@@ -2877,15 +2877,15 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2877 /* mutex was already unlocked by try_ready_normal_body */ 2877 /* mutex was already unlocked by try_ready_normal_body */
2878 return; 2878 return;
2879 } 2879 }
2880#ifdef __linux__ 2880#if defined(HAVE_LINUX_SENDFILE)
2881 if (MHD_resp_sender_sendfile == connection->resp_sender) 2881 if (MHD_resp_sender_sendfile == connection->resp_sender)
2882 { 2882 {
2883 ret = sendfile_adapter (connection); 2883 ret = sendfile_adapter (connection);
2884 } 2884 }
2885 else 2885 else
2886#else /* ! __linux__ */ 2886#else /* ! HAVE_LINUX_SENDFILE */
2887 if (1) 2887 if (1)
2888#endif /* ! __linux__ */ 2888#endif /* ! HAVE_LINUX_SENDFILE */
2889 { 2889 {
2890 data_write_offset = connection->response_write_position 2890 data_write_offset = connection->response_write_position
2891 - response->data_start; 2891 - response->data_start;
@@ -3821,13 +3821,13 @@ MHD_queue_response (struct MHD_Connection *connection,
3821 MHD_increment_response_rc (response); 3821 MHD_increment_response_rc (response);
3822 connection->response = response; 3822 connection->response = response;
3823 connection->responseCode = status_code; 3823 connection->responseCode = status_code;
3824#if LINUX 3824#if defined(HAVE_LINUX_SENDFILE)
3825 if ( (response->fd == -1) || 3825 if ( (response->fd == -1) ||
3826 (0 != (connection->daemon->options & MHD_USE_TLS)) ) 3826 (0 != (connection->daemon->options & MHD_USE_TLS)) )
3827 connection->resp_sender = MHD_resp_sender_std; 3827 connection->resp_sender = MHD_resp_sender_std;
3828 else 3828 else
3829 connection->resp_sender = MHD_resp_sender_sendfile; 3829 connection->resp_sender = MHD_resp_sender_sendfile;
3830#endif /* LINUX */ 3830#endif /* HAVE_LINUX_SENDFILE */
3831 3831
3832 if ( ( (NULL != connection->method) && 3832 if ( ( (NULL != connection->method) &&
3833 (MHD_str_equal_caseless_ (connection->method, 3833 (MHD_str_equal_caseless_ (connection->method,
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 602a5d4f..f82a122c 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -806,13 +806,13 @@ struct MHD_Connection
806 */ 806 */
807 uint64_t response_write_position; 807 uint64_t response_write_position;
808 808
809#ifdef __linux__ 809#if defined(HAVE_LINUX_SENDFILE)
810 enum MHD_resp_sender_ 810 enum MHD_resp_sender_
811 { 811 {
812 MHD_resp_sender_std = 0, 812 MHD_resp_sender_std = 0,
813 MHD_resp_sender_sendfile 813 MHD_resp_sender_sendfile
814 } resp_sender; 814 } resp_sender;
815#endif /* __linux__ */ 815#endif /* HAVE_LINUX_SENDFILE */
816 816
817 /** 817 /**
818 * Position in the 100 CONTINUE message that 818 * Position in the 100 CONTINUE message that