send_param_adapter(): support hosts with sendfile64(), but with 32-bit off_t (i.e. Android)

This commit is contained in:
Evgeny Grin (Karlson2k)
2015-06-09 19:34:45 +00:00
parent a78b44a832
commit 2ece82f12e
3 changed files with 35 additions and 8 deletions
+1 -1
View File
@@ -608,7 +608,7 @@ AM_CONDITIONAL(HAVE_SPDYLAY, [test "x$have_spdylay" = "xyes"])
# large file support (> 4 GB)
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO
AC_CHECK_FUNCS([_lseeki64 lseek64])
AC_CHECK_FUNCS([_lseeki64 lseek64 sendfile64])
# optional: have error messages ?
AC_MSG_CHECKING(whether to generate error messages)
+12
View File
@@ -78,6 +78,10 @@
#endif /* !WIN32_LEAN_AND_MEAN */
#endif // _WIN32
#if LINUX+0 && (defined(HAVE_SENDFILE64) || defined(HAVE_LSEEK64)) && ! defined(_LARGEFILE64_SOURCE)
#define _LARGEFILE64_SOURCE 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -202,4 +206,12 @@ typedef MHD_socket MHD_pipe;
#define IPPROTO_IPV6 IPPROTO_IPV6
#endif
#ifndef OFF_T_MAX
#define OFF_T_MAX ((off_t) ~(((uint64_t) 1) << (8 * sizeof(off_t) - 1)))
#endif
#if defined(_LARGEFILE64_SOURCE) && !defined(OFF64_T_MAX)
#define OFF64_T_MAX ((off64_t) ~(((uint64_t) 1) << (8 * sizeof(off64_t) - 1)))
#endif
#endif
+22 -7
View File
@@ -117,6 +117,10 @@
#define EPOLL_CLOEXEC 0
#endif
#ifndef INT32_MAX
#define INT32_MAX ((int32_t)0x7FFFFFFF)
#endif /* !INT32_MAX */
/**
* Default implementation of the panic function,
@@ -1078,8 +1082,6 @@ send_param_adapter (struct MHD_Connection *connection,
const size_t requested_size = i;
#if LINUX
MHD_socket fd;
off_t offset;
off_t left;
#endif
if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
@@ -1105,14 +1107,27 @@ send_param_adapter (struct MHD_Connection *connection,
(-1 != (fd = connection->response->fd)) )
{
/* can use sendfile */
offset = (off_t) connection->response_write_position + connection->response->fd_off;
uint64_t left;
#ifndef HAVE_SENDFILE64
uint64_t offsetu64;
off_t offset;
#else /* HAVE_SENDFILE64 */
uint64_t offsetu64;
off64_t offset;
#endif /* HAVE_SENDFILE64 */
offsetu64 = connection->response_write_position + connection->response->fd_off;
left = connection->response->total_size - connection->response_write_position;
if (i > left)
i = left;
if (0 < (ret = sendfile (connection->socket_fd,
fd,
&offset,
i)))
#ifndef HAVE_SENDFILE64
offset = (off_t) offsetu64;
if ( (offsetu64 <= (uint64_t)OFF_T_MAX) &&
0 < (ret = sendfile (connection->socket_fd, fd, &offset, i)))
#else /* HAVE_SENDFILE64 */
offset = (off64_t) offsetu64;
if ( (offsetu64 <= (uint64_t)OFF64_T_MAX) &&
0 < (ret = sendfile64 (connection->socket_fd, fd, &offset, i)))
#endif /* HAVE_SENDFILE64 */
{
#if EPOLL_SUPPORT
if (requested_size > (size_t) ret)