diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-11-26 15:18:48 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-11-26 15:18:48 +0300 |
commit | b3f1a958ce613f304234ecb6506976db26c117dc (patch) | |
tree | e8671ee93fa1cf0125d8836f174dd53a8ec27c15 | |
parent | 1d14778635f9c92ff314f48c744a44cf3853c857 (diff) | |
download | libmicrohttpd-b3f1a958ce613f304234ecb6506976db26c117dc.tar.gz libmicrohttpd-b3f1a958ce613f304234ecb6506976db26c117dc.zip |
Fixed sending on Linux responses backed with file which is not supported by sendfile()
-rw-r--r-- | src/microhttpd/connection.c | 11 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 3 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 8 |
3 files changed, 19 insertions, 3 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 186e9dd2..e6a26efc 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -681,8 +681,7 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
681 | connection->response_write_position) ) | 681 | connection->response_write_position) ) |
682 | return MHD_YES; /* response already ready */ | 682 | return MHD_YES; /* response already ready */ |
683 | #if LINUX | 683 | #if LINUX |
684 | if ( (MHD_INVALID_SOCKET != response->fd) && | 684 | if (MHD_resp_sender_sendfile == connection->resp_sender) |
685 | (0 == (connection->daemon->options & MHD_USE_TLS)) ) | ||
686 | { | 685 | { |
687 | /* will use sendfile, no need to bother response crc */ | 686 | /* will use sendfile, no need to bother response crc */ |
688 | return MHD_YES; | 687 | return MHD_YES; |
@@ -3488,6 +3487,14 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
3488 | MHD_increment_response_rc (response); | 3487 | MHD_increment_response_rc (response); |
3489 | connection->response = response; | 3488 | connection->response = response; |
3490 | connection->responseCode = status_code; | 3489 | connection->responseCode = status_code; |
3490 | #if LINUX | ||
3491 | if ( (response->fd == -1) || | ||
3492 | (0 != (connection->daemon->options & MHD_USE_TLS)) ) | ||
3493 | connection->resp_sender = MHD_resp_sender_std; | ||
3494 | else | ||
3495 | connection->resp_sender = MHD_resp_sender_sendfile; | ||
3496 | #endif /* LINUX */ | ||
3497 | |||
3491 | if ( ( (NULL != connection->method) && | 3498 | if ( ( (NULL != connection->method) && |
3492 | (MHD_str_equal_caseless_ (connection->method, | 3499 | (MHD_str_equal_caseless_ (connection->method, |
3493 | MHD_HTTP_METHOD_HEAD)) ) || | 3500 | MHD_HTTP_METHOD_HEAD)) ) || |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 6e97085b..1b0a42bb 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1852,7 +1852,7 @@ send_param_adapter (struct MHD_Connection *connection, | |||
1852 | if ( (connection->write_buffer_append_offset == | 1852 | if ( (connection->write_buffer_append_offset == |
1853 | connection->write_buffer_send_offset) && | 1853 | connection->write_buffer_send_offset) && |
1854 | (NULL != connection->response) && | 1854 | (NULL != connection->response) && |
1855 | (-1 != (fd = connection->response->fd)) ) | 1855 | (MHD_resp_sender_sendfile == connection->resp_sender) ) |
1856 | { | 1856 | { |
1857 | /* can use sendfile */ | 1857 | /* can use sendfile */ |
1858 | uint64_t left; | 1858 | uint64_t left; |
@@ -1904,6 +1904,7 @@ send_param_adapter (struct MHD_Connection *connection, | |||
1904 | to fall back to 'SEND'; see also this thread for info on | 1904 | to fall back to 'SEND'; see also this thread for info on |
1905 | odd libc/Linux behavior with sendfile: | 1905 | odd libc/Linux behavior with sendfile: |
1906 | http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */ | 1906 | http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */ |
1907 | connection->resp_sender = MHD_resp_sender_std; | ||
1907 | } | 1908 | } |
1908 | #endif | 1909 | #endif |
1909 | ret = MHD_send_ (connection->socket_fd, | 1910 | ret = MHD_send_ (connection->socket_fd, |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index ae63e79c..d92f76a1 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -752,6 +752,14 @@ struct MHD_Connection | |||
752 | */ | 752 | */ |
753 | uint64_t response_write_position; | 753 | uint64_t response_write_position; |
754 | 754 | ||
755 | #if LINUX | ||
756 | enum MHD_resp_sender_ | ||
757 | { | ||
758 | MHD_resp_sender_std = 0, | ||
759 | MHD_resp_sender_sendfile | ||
760 | } resp_sender; | ||
761 | #endif /* LINUX */ | ||
762 | |||
755 | /** | 763 | /** |
756 | * Position in the 100 CONTINUE message that | 764 | * Position in the 100 CONTINUE message that |
757 | * we need to send when receiving http 1.1 requests. | 765 | * we need to send when receiving http 1.1 requests. |