[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libmicrohttpd] 03/04: Sending with sendfile: use chunks so
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libmicrohttpd] 03/04: Sending with sendfile: use chunks so MHD will be able to process other connections too. |
Date: |
Sun, 01 Oct 2017 16:02:56 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 5ac497e212525a12209a3c1007a129ae85055cf7
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Sun Oct 1 16:21:06 2017 +0300
Sending with sendfile: use chunks so MHD will be able to process other
connections too.
---
src/microhttpd/connection.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index daa49824..d80eabc5 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -238,12 +238,18 @@ sendfile_adapter (struct MHD_Connection *connection)
#else /* HAVE_SENDFILE64 */
off64_t offset;
#endif /* HAVE_SENDFILE64 */
+ const bool used_thr_p_c = (0 != (daemon->options &
MHD_USE_THREAD_PER_CONNECTION));
+ size_t send_size;
mhd_assert (MHD_resp_sender_sendfile == connection->resp_sender);
offsetu64 = connection->response_write_position +
connection->response->fd_off;
left = connection->response->total_size -
connection->response_write_position;
- if (left > SSIZE_MAX)
- left = SSIZE_MAX;
+ /* Do not allow system to stick sending on single fast connection:
+ * use 128KiB chunks (2MiB for thread-per-connection). */
+ if (!used_thr_p_c)
+ send_size = (left > 0x20000) ? 0x20000 : (size_t) left;
+ else
+ send_size = (left > 0x200000) ? 0x200000 : (size_t) left;
#ifndef HAVE_SENDFILE64
if ((uint64_t)OFF_T_MAX < offsetu64)
{ /* Retry to send with standard 'send()'. */
@@ -254,7 +260,7 @@ sendfile_adapter (struct MHD_Connection *connection)
ret = sendfile (connection->socket_fd,
file_fd,
&offset,
- left);
+ send_size);
#else /* HAVE_SENDFILE64 */
if ((uint64_t)OFF64_T_MAX < offsetu64)
{ /* Retry to send with standard 'send()'. */
@@ -265,7 +271,7 @@ sendfile_adapter (struct MHD_Connection *connection)
ret = sendfile64 (connection->socket_fd,
file_fd,
&offset,
- left);
+ send_size);
#endif /* HAVE_SENDFILE64 */
if (0 > ret)
{
@@ -292,7 +298,7 @@ sendfile_adapter (struct MHD_Connection *connection)
return MHD_ERR_AGAIN_;
}
#ifdef EPOLL_SUPPORT
- else if (left > (uint64_t)ret)
+ else if (send_size > (size_t)ret)
connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
#endif /* EPOLL_SUPPORT */
return ret;
--
To stop receiving notification emails like this one, please contact
address@hidden