libmicrohttpd

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

commit 18177698ac76827da36d5d3d93bc0a4c86e7f2f9
parent 74019e111cbdad0721c76018793e650b7d339ab1
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 18 Feb 2011 10:05:26 +0000

try to handle sendfile corner cases better

Diffstat:
MChangeLog | 5+++++
Msrc/daemon/daemon.c | 27+++++++++++++++++++++------
Msrc/include/microhttpd.h | 2+-
3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,8 @@ +Fri Feb 18 11:03:59 CET 2011 + Handle large (>2 GB) file transfers with sendfile on 32-bit + systems better; handle odd sendfile failures by libc/kernel + by falling back to standard 'SEND'. -CG + Sun Feb 13 10:52:29 CET 2011 Handle gnutls receive error(s) for interrupted SSL connections better. -MS diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -709,7 +709,8 @@ send_param_adapter (struct MHD_Connection *connection, #if LINUX int fd; off_t offset; - int ret; + off_t left; + ssize_t ret; #endif if (connection->socket_fd == -1) return -1; @@ -723,14 +724,28 @@ send_param_adapter (struct MHD_Connection *connection, { /* can use sendfile */ offset = (off_t) connection->response_write_position + connection->response->fd_off; + left = connection->response->total_size - offset; + if (left > SSIZE_MAX) + left = SSIZE_MAX; /* cap at return value limit */ ret = sendfile (connection->socket_fd, fd, &offset, - connection->response->total_size - offset); - if ( (ret == -1) && - (errno == EINTR) ) - return 0; - return ret; + left); + if (ret != -1) + return ret; + if (ret == -1) + { + if (EINTR == errno) + return 0; + if ( (EINVAL == errno) || + (EBADF == errno) || + (EAGAIN == errno) ) + return -1; + /* None of the 'usual' sendfile errors occurred, so we should try + to fall back to 'SEND'; see also this thread for info on + odd libc/Linux behavior with sendfile: + http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */ + } } #endif return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL | MSG_DONTWAIT); diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -106,7 +106,7 @@ extern "C" /** * Current version of the library. */ -#define MHD_VERSION 0x00090700 +#define MHD_VERSION 0x00090701 /** * MHD-internal return code for "YES".