aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2015-06-09 19:34:45 +0000
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2015-06-09 19:34:45 +0000
commit2ece82f12eaa7710f044cadb87d7e9890e4c2e05 (patch)
tree09abcd266f6df8fdffcc98412f7a6af900de9ea2 /src
parenta78b44a8329d770e0c97e2f38c62c0a1c2bedc47 (diff)
downloadlibmicrohttpd-2ece82f12eaa7710f044cadb87d7e9890e4c2e05.tar.gz
libmicrohttpd-2ece82f12eaa7710f044cadb87d7e9890e4c2e05.zip
send_param_adapter(): support hosts with sendfile64(), but with 32-bit off_t (i.e. Android)
Diffstat (limited to 'src')
-rw-r--r--src/include/platform.h12
-rw-r--r--src/microhttpd/daemon.c29
2 files changed, 34 insertions, 7 deletions
diff --git a/src/include/platform.h b/src/include/platform.h
index 22dddddf..472696b6 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -78,6 +78,10 @@
78#endif /* !WIN32_LEAN_AND_MEAN */ 78#endif /* !WIN32_LEAN_AND_MEAN */
79#endif // _WIN32 79#endif // _WIN32
80 80
81#if LINUX+0 && (defined(HAVE_SENDFILE64) || defined(HAVE_LSEEK64)) && ! defined(_LARGEFILE64_SOURCE)
82#define _LARGEFILE64_SOURCE 1
83#endif
84
81#include <stdio.h> 85#include <stdio.h>
82#include <stdlib.h> 86#include <stdlib.h>
83#include <stdint.h> 87#include <stdint.h>
@@ -202,4 +206,12 @@ typedef MHD_socket MHD_pipe;
202#define IPPROTO_IPV6 IPPROTO_IPV6 206#define IPPROTO_IPV6 IPPROTO_IPV6
203#endif 207#endif
204 208
209#ifndef OFF_T_MAX
210#define OFF_T_MAX ((off_t) ~(((uint64_t) 1) << (8 * sizeof(off_t) - 1)))
211#endif
212
213#if defined(_LARGEFILE64_SOURCE) && !defined(OFF64_T_MAX)
214#define OFF64_T_MAX ((off64_t) ~(((uint64_t) 1) << (8 * sizeof(off64_t) - 1)))
215#endif
216
205#endif 217#endif
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 161d1011..b2a057b2 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -117,6 +117,10 @@
117#define EPOLL_CLOEXEC 0 117#define EPOLL_CLOEXEC 0
118#endif 118#endif
119 119
120#ifndef INT32_MAX
121#define INT32_MAX ((int32_t)0x7FFFFFFF)
122#endif /* !INT32_MAX */
123
120 124
121/** 125/**
122 * Default implementation of the panic function, 126 * Default implementation of the panic function,
@@ -1078,8 +1082,6 @@ send_param_adapter (struct MHD_Connection *connection,
1078 const size_t requested_size = i; 1082 const size_t requested_size = i;
1079#if LINUX 1083#if LINUX
1080 MHD_socket fd; 1084 MHD_socket fd;
1081 off_t offset;
1082 off_t left;
1083#endif 1085#endif
1084 1086
1085 if ( (MHD_INVALID_SOCKET == connection->socket_fd) || 1087 if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
@@ -1105,14 +1107,27 @@ send_param_adapter (struct MHD_Connection *connection,
1105 (-1 != (fd = connection->response->fd)) ) 1107 (-1 != (fd = connection->response->fd)) )
1106 { 1108 {
1107 /* can use sendfile */ 1109 /* can use sendfile */
1108 offset = (off_t) connection->response_write_position + connection->response->fd_off; 1110 uint64_t left;
1111#ifndef HAVE_SENDFILE64
1112 uint64_t offsetu64;
1113 off_t offset;
1114#else /* HAVE_SENDFILE64 */
1115 uint64_t offsetu64;
1116 off64_t offset;
1117#endif /* HAVE_SENDFILE64 */
1118 offsetu64 = connection->response_write_position + connection->response->fd_off;
1109 left = connection->response->total_size - connection->response_write_position; 1119 left = connection->response->total_size - connection->response_write_position;
1110 if (i > left) 1120 if (i > left)
1111 i = left; 1121 i = left;
1112 if (0 < (ret = sendfile (connection->socket_fd, 1122#ifndef HAVE_SENDFILE64
1113 fd, 1123 offset = (off_t) offsetu64;
1114 &offset, 1124 if ( (offsetu64 <= (uint64_t)OFF_T_MAX) &&
1115 i))) 1125 0 < (ret = sendfile (connection->socket_fd, fd, &offset, i)))
1126#else /* HAVE_SENDFILE64 */
1127 offset = (off64_t) offsetu64;
1128 if ( (offsetu64 <= (uint64_t)OFF64_T_MAX) &&
1129 0 < (ret = sendfile64 (connection->socket_fd, fd, &offset, i)))
1130#endif /* HAVE_SENDFILE64 */
1116 { 1131 {
1117#if EPOLL_SUPPORT 1132#if EPOLL_SUPPORT
1118 if (requested_size > (size_t) ret) 1133 if (requested_size > (size_t) ret)