aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac47
-rw-r--r--src/include/mhd_options.h4
-rw-r--r--src/microhttpd/connection.c44
-rw-r--r--src/microhttpd/internal.h4
4 files changed, 83 insertions, 16 deletions
diff --git a/configure.ac b/configure.ac
index e61cc1c3..6123ef2b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1312,6 +1312,53 @@ int sendfile(int, int, off_t, size_t,
1312 ] 1312 ]
1313) 1313)
1314 1314
1315AS_VAR_IF([[found_sendfile]], [["no"]],
1316 [
1317 AC_MSG_CHECKING([[for Solaris-style sendfile(3)]])
1318 SAVE_LIBS="$LIBS"
1319 LIBS="$LIBS -lsendfile"
1320 AC_LINK_IFELSE(
1321 [AC_LANG_PROGRAM(
1322 [[
1323#include <sys/types.h>
1324#include <sys/socket.h>
1325#include <sys/sendfile.h>
1326
1327static void empty_func(void)
1328{
1329/* Check for declaration */
1330 (void)sendfile;
1331}
1332/* Declare again to check form match */
1333ssize_t sendfile(int out_fd, int in_fd,
1334 off_t *off, size_t len);
1335 ]],
1336 [[
1337 int fd1=0, fd2=1;
1338 off_t o = 0;
1339 size_t l = 5;
1340 ssize_t r;
1341 r = sendfile (fd1, fd2, &o, l);
1342 if (r)
1343 empty_func();
1344 ]]
1345 )
1346 ],
1347 [
1348 AC_DEFINE([HAVE_SOLARIS_SENDFILE], [1], [Define to 1 if you have Solaris-style sendfile(3).])
1349 found_sendfile="yes, Solaris-style"
1350 MHD_LIBDEPS="-lsendfile $MHD_LIBDEPS"
1351 MHD_LIBDEPS_PKGCFG="-lsendfile $MHD_LIBDEPS_PKGCFG"
1352 AC_MSG_RESULT([[yes]])
1353 AC_CHECK_FUNCS([sendfile64])
1354 ],
1355 [AC_MSG_RESULT([[no]])
1356 ]
1357 )
1358 LIBS="$SAVE_LIBS"
1359 ]
1360)
1361
1315# optional: have error messages ? 1362# optional: have error messages ?
1316AC_MSG_CHECKING([[whether to generate error messages]]) 1363AC_MSG_CHECKING([[whether to generate error messages]])
1317AC_ARG_ENABLE([messages], 1364AC_ARG_ENABLE([messages],
diff --git a/src/include/mhd_options.h b/src/include/mhd_options.h
index 36a5f575..d009630e 100644
--- a/src/include/mhd_options.h
+++ b/src/include/mhd_options.h
@@ -65,6 +65,10 @@
65#define _MHD_FD_SETSIZE_IS_DEFAULT 1 65#define _MHD_FD_SETSIZE_IS_DEFAULT 1
66#endif /* !FD_SETSIZE && !WinSock*/ 66#endif /* !FD_SETSIZE && !WinSock*/
67 67
68#if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_SOLARIS_SENDFILE)
69#define MHD_LINUX_SOLARIS_SENDFILE 1
70#endif /* HAVE_LINUX_SENDFILE || HAVE_SOLARIS_SENDFILE */
71
68#if OS390 72#if OS390
69#define _OPEN_THREADS 73#define _OPEN_THREADS
70#define _OPEN_SYS_SOCK_IPV6 74#define _OPEN_SYS_SOCK_IPV6
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index b19c67fa..623b40a5 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 HAVE_LINUX_SENDFILE 39#ifdef MHD_LINUX_SOLARIS_SENDFILE
40#include <sys/sendfile.h> 40#include <sys/sendfile.h>
41#endif /* HAVE_LINUX_SENDFILE */ 41#endif /* MHD_LINUX_SOLARIS_SENDFILE */
42#ifdef HAVE_FREEBSD_SENDFILE 42#ifdef HAVE_FREEBSD_SENDFILE
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/socket.h> 44#include <sys/socket.h>
@@ -272,7 +272,7 @@ send_param_adapter (struct MHD_Connection *connection,
272} 272}
273 273
274 274
275#if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE) 275#if defined(MHD_LINUX_SOLARIS_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE)
276/** 276/**
277 * Function for sending responses backed by file FD. 277 * Function for sending responses backed by file FD.
278 * 278 *
@@ -291,13 +291,13 @@ sendfile_adapter (struct MHD_Connection *connection)
291#else /* HAVE_SENDFILE64 */ 291#else /* HAVE_SENDFILE64 */
292 const uint64_t max_off_t = (uint64_t)OFF64_T_MAX; 292 const uint64_t max_off_t = (uint64_t)OFF64_T_MAX;
293#endif /* HAVE_SENDFILE64 */ 293#endif /* HAVE_SENDFILE64 */
294#ifdef HAVE_LINUX_SENDFILE 294#ifdef MHD_LINUX_SOLARIS_SENDFILE
295#ifndef HAVE_SENDFILE64 295#ifndef HAVE_SENDFILE64
296 off_t offset; 296 off_t offset;
297#else /* HAVE_SENDFILE64 */ 297#else /* HAVE_SENDFILE64 */
298 off64_t offset; 298 off64_t offset;
299#endif /* HAVE_SENDFILE64 */ 299#endif /* HAVE_SENDFILE64 */
300#endif /* HAVE_LINUX_SENDFILE */ 300#endif /* MHD_LINUX_SOLARIS_SENDFILE */
301#ifdef HAVE_FREEBSD_SENDFILE 301#ifdef HAVE_FREEBSD_SENDFILE
302 off_t sent_bytes; 302 off_t sent_bytes;
303 int flags = 0; 303 int flags = 0;
@@ -317,7 +317,7 @@ sendfile_adapter (struct MHD_Connection *connection)
317 connection->resp_sender = MHD_resp_sender_std; 317 connection->resp_sender = MHD_resp_sender_std;
318 return MHD_ERR_AGAIN_; 318 return MHD_ERR_AGAIN_;
319 } 319 }
320#ifdef HAVE_LINUX_SENDFILE 320#ifdef MHD_LINUX_SOLARIS_SENDFILE
321#ifndef HAVE_SENDFILE64 321#ifndef HAVE_SENDFILE64
322 offset = (off_t) offsetu64; 322 offset = (off_t) offsetu64;
323 ret = sendfile (connection->socket_fd, 323 ret = sendfile (connection->socket_fd,
@@ -344,6 +344,7 @@ sendfile_adapter (struct MHD_Connection *connection)
344 } 344 }
345 if (MHD_SCKT_ERR_IS_EINTR_ (err)) 345 if (MHD_SCKT_ERR_IS_EINTR_ (err))
346 return MHD_ERR_AGAIN_; 346 return MHD_ERR_AGAIN_;
347#ifdef HAVE_LINUX_SENDFILE
347 if (MHD_SCKT_ERR_IS_(err, 348 if (MHD_SCKT_ERR_IS_(err,
348 MHD_SCKT_EBADF_)) 349 MHD_SCKT_EBADF_))
349 return MHD_ERR_BADF_; 350 return MHD_ERR_BADF_;
@@ -354,6 +355,21 @@ sendfile_adapter (struct MHD_Connection *connection)
354 http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */ 355 http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */
355 connection->resp_sender = MHD_resp_sender_std; 356 connection->resp_sender = MHD_resp_sender_std;
356 return MHD_ERR_AGAIN_; 357 return MHD_ERR_AGAIN_;
358#else /* HAVE_SOLARIS_SENDFILE */
359 if ( (EAFNOSUPPORT == err) ||
360 (EINVAL == err) ||
361 (EOPNOTSUPP == err) )
362 { /* Retry with standard file reader. */
363 connection->resp_sender = MHD_resp_sender_std;
364 return MHD_ERR_AGAIN_;
365 }
366 if ( (ENOTCONN == err) ||
367 (EPIPE == err) )
368 {
369 return MHD_ERR_CONNRESET_;
370 }
371 return MHD_ERR_BADF_; /* Fail hard */
372#endif /* HAVE_SOLARIS_SENDFILE */
357 } 373 }
358#ifdef EPOLL_SUPPORT 374#ifdef EPOLL_SUPPORT
359 else if (send_size > (size_t)ret) 375 else if (send_size > (size_t)ret)
@@ -394,7 +410,7 @@ sendfile_adapter (struct MHD_Connection *connection)
394#endif /* HAVE_FREEBSD_SENDFILE */ 410#endif /* HAVE_FREEBSD_SENDFILE */
395 return ret; 411 return ret;
396} 412}
397#endif /* HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE */ 413#endif /* MHD_LINUX_SOLARIS_SENDFILE || HAVE_FREEBSD_SENDFILE */
398 414
399 415
400/** 416/**
@@ -1026,13 +1042,13 @@ try_ready_normal_body (struct MHD_Connection *connection)
1026 (response->data_size + response->data_start > 1042 (response->data_size + response->data_start >
1027 connection->response_write_position) ) 1043 connection->response_write_position) )
1028 return MHD_YES; /* response already ready */ 1044 return MHD_YES; /* response already ready */
1029#if defined(HAVE_LINUX_SENDFILE) || defined (HAVE_FREEBSD_SENDFILE) 1045#if defined(MHD_LINUX_SOLARIS_SENDFILE) || defined (HAVE_FREEBSD_SENDFILE)
1030 if (MHD_resp_sender_sendfile == connection->resp_sender) 1046 if (MHD_resp_sender_sendfile == connection->resp_sender)
1031 { 1047 {
1032 /* will use sendfile, no need to bother response crc */ 1048 /* will use sendfile, no need to bother response crc */
1033 return MHD_YES; 1049 return MHD_YES;
1034 } 1050 }
1035#endif /* HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE */ 1051#endif /* MHD_LINUX_SOLARIS_SENDFILE || HAVE_FREEBSD_SENDFILE */
1036 1052
1037 ret = response->crc (response->crc_cls, 1053 ret = response->crc (response->crc_cls,
1038 connection->response_write_position, 1054 connection->response_write_position,
@@ -2970,15 +2986,15 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2970 /* mutex was already unlocked by try_ready_normal_body */ 2986 /* mutex was already unlocked by try_ready_normal_body */
2971 return; 2987 return;
2972 } 2988 }
2973#if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE) 2989#if defined(MHD_LINUX_SOLARIS_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE)
2974 if (MHD_resp_sender_sendfile == connection->resp_sender) 2990 if (MHD_resp_sender_sendfile == connection->resp_sender)
2975 { 2991 {
2976 ret = sendfile_adapter (connection); 2992 ret = sendfile_adapter (connection);
2977 } 2993 }
2978 else 2994 else
2979#else /* ! (HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE) */ 2995#else /* ! (MHD_LINUX_SOLARIS_SENDFILE || HAVE_FREEBSD_SENDFILE) */
2980 if (1) 2996 if (1)
2981#endif /* ! (HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE) */ 2997#endif /* ! (MHD_LINUX_SOLARIS_SENDFILE || HAVE_FREEBSD_SENDFILE) */
2982 { 2998 {
2983 data_write_offset = connection->response_write_position 2999 data_write_offset = connection->response_write_position
2984 - response->data_start; 3000 - response->data_start;
@@ -3918,13 +3934,13 @@ MHD_queue_response (struct MHD_Connection *connection,
3918 MHD_increment_response_rc (response); 3934 MHD_increment_response_rc (response);
3919 connection->response = response; 3935 connection->response = response;
3920 connection->responseCode = status_code; 3936 connection->responseCode = status_code;
3921#if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE) 3937#if defined(MHD_LINUX_SOLARIS_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE)
3922 if ( (response->fd == -1) || 3938 if ( (response->fd == -1) ||
3923 (0 != (connection->daemon->options & MHD_USE_TLS)) ) 3939 (0 != (connection->daemon->options & MHD_USE_TLS)) )
3924 connection->resp_sender = MHD_resp_sender_std; 3940 connection->resp_sender = MHD_resp_sender_std;
3925 else 3941 else
3926 connection->resp_sender = MHD_resp_sender_sendfile; 3942 connection->resp_sender = MHD_resp_sender_sendfile;
3927#endif /* HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE */ 3943#endif /* MHD_LINUX_SOLARIS_SENDFILE || HAVE_FREEBSD_SENDFILE */
3928 3944
3929 if ( ( (NULL != connection->method) && 3945 if ( ( (NULL != connection->method) &&
3930 (MHD_str_equal_caseless_ (connection->method, 3946 (MHD_str_equal_caseless_ (connection->method,
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 25a24588..0c986196 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#if defined(HAVE_LINUX_SENDFILE) || defined(HAVE_FREEBSD_SENDFILE) 809#if defined(MHD_LINUX_SOLARIS_SENDFILE) || defined(HAVE_FREEBSD_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 /* HAVE_LINUX_SENDFILE || HAVE_FREEBSD_SENDFILE */ 815#endif /* MHD_LINUX_SOLARIS_SENDFILE || HAVE_FREEBSD_SENDFILE */
816 816
817 /** 817 /**
818 * Position in the 100 CONTINUE message that 818 * Position in the 100 CONTINUE message that