libmicrohttpd

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

commit b3f1a958ce613f304234ecb6506976db26c117dc
parent 1d14778635f9c92ff314f48c744a44cf3853c857
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sat, 26 Nov 2016 15:18:48 +0300

Fixed sending on Linux responses backed with file which is not supported by sendfile()

Diffstat:
Msrc/microhttpd/connection.c | 11+++++++++--
Msrc/microhttpd/daemon.c | 3++-
Msrc/microhttpd/internal.h | 8++++++++
3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -681,8 +681,7 @@ try_ready_normal_body (struct MHD_Connection *connection) connection->response_write_position) ) return MHD_YES; /* response already ready */ #if LINUX - if ( (MHD_INVALID_SOCKET != response->fd) && - (0 == (connection->daemon->options & MHD_USE_TLS)) ) + if (MHD_resp_sender_sendfile == connection->resp_sender) { /* will use sendfile, no need to bother response crc */ return MHD_YES; @@ -3488,6 +3487,14 @@ MHD_queue_response (struct MHD_Connection *connection, MHD_increment_response_rc (response); connection->response = response; connection->responseCode = status_code; +#if LINUX + if ( (response->fd == -1) || + (0 != (connection->daemon->options & MHD_USE_TLS)) ) + connection->resp_sender = MHD_resp_sender_std; + else + connection->resp_sender = MHD_resp_sender_sendfile; +#endif /* LINUX */ + if ( ( (NULL != connection->method) && (MHD_str_equal_caseless_ (connection->method, MHD_HTTP_METHOD_HEAD)) ) || diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -1852,7 +1852,7 @@ send_param_adapter (struct MHD_Connection *connection, if ( (connection->write_buffer_append_offset == connection->write_buffer_send_offset) && (NULL != connection->response) && - (-1 != (fd = connection->response->fd)) ) + (MHD_resp_sender_sendfile == connection->resp_sender) ) { /* can use sendfile */ uint64_t left; @@ -1904,6 +1904,7 @@ send_param_adapter (struct MHD_Connection *connection, 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 */ + connection->resp_sender = MHD_resp_sender_std; } #endif ret = MHD_send_ (connection->socket_fd, diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -752,6 +752,14 @@ struct MHD_Connection */ uint64_t response_write_position; +#if LINUX + enum MHD_resp_sender_ + { + MHD_resp_sender_std = 0, + MHD_resp_sender_sendfile + } resp_sender; +#endif /* LINUX */ + /** * Position in the 100 CONTINUE message that * we need to send when receiving http 1.1 requests.