diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-05 10:12:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-05 10:12:10 +0000 |
commit | 6e07994a8bfa4227444ad5b178b4a54cb4ec69da (patch) | |
tree | f315a042e794ff227b4d7e1fa3d4d9074c3932cd | |
parent | 9fe0e9d41112f2a75ee4d9461f1b93b59131029d (diff) | |
download | libmicrohttpd-6e07994a8bfa4227444ad5b178b4a54cb4ec69da.tar.gz libmicrohttpd-6e07994a8bfa4227444ad5b178b4a54cb4ec69da.zip |
-fixing #2899: allow clients to customize MHD_BUF_INC_SIZE via option
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | doc/libmicrohttpd.texi | 9 | ||||
-rw-r--r-- | src/include/microhttpd.h | 8 | ||||
-rw-r--r-- | src/microhttpd/connection.c | 10 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 12 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 15 |
7 files changed, 45 insertions, 15 deletions
@@ -22,6 +22,7 @@ Matthew Moore | |||
22 | Colin Caughie <c.caughie@indigovision.com> | 22 | Colin Caughie <c.caughie@indigovision.com> |
23 | David Carvalho <andaris@gmail.com> | 23 | David Carvalho <andaris@gmail.com> |
24 | David Reiss <dreiss@facebook.com> | 24 | David Reiss <dreiss@facebook.com> |
25 | Matt Holiday | ||
25 | Mika Raento <mikie@iki.fi> | 26 | Mika Raento <mikie@iki.fi> |
26 | Mike Crowe <mac@mcrowe.com> | 27 | Mike Crowe <mac@mcrowe.com> |
27 | John Muth <muth@parascale.com> | 28 | John Muth <muth@parascale.com> |
@@ -1,3 +1,8 @@ | |||
1 | Fri Jul 5 12:05:01 CEST 2013 | ||
2 | Added MHD_OPTION_CONNECTION_MEMORY_INCREMENT to allow users | ||
3 | to specify a custom value for incrementing read buffer | ||
4 | sizes (#2899). -MH | ||
5 | |||
1 | Fri Jun 28 14:05:15 CEST 2013 | 6 | Fri Jun 28 14:05:15 CEST 2013 |
2 | If we shutdown connection for reading on POST due to error, | 7 | If we shutdown connection for reading on POST due to error, |
3 | really do not process further requests even if we already | 8 | really do not process further requests even if we already |
diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi index 377302ef..30e0355d 100644 --- a/doc/libmicrohttpd.texi +++ b/doc/libmicrohttpd.texi | |||
@@ -509,6 +509,15 @@ result in much benefit, as half of the memory will be typically used | |||
509 | for IO, and TCP buffers are unlikely to support window sizes above 64k | 509 | for IO, and TCP buffers are unlikely to support window sizes above 64k |
510 | on most systems. | 510 | on most systems. |
511 | 511 | ||
512 | @item MHD_OPTION_CONNECTION_MEMORY_INCREMENT | ||
513 | @cindex memory | ||
514 | Increment to use for growing the read buffer (followed by a | ||
515 | @code{size_t}). The default is 1024 (bytes). Increasing this value | ||
516 | will make MHD use memory for reading more aggressively, which can | ||
517 | reduce the number of @code{recvfrom} calls but may increase the number | ||
518 | of @code{sendto} calls. The given value must fit within | ||
519 | MHD_OPTION_CONNECTION_MEMORY_LIMIT. | ||
520 | |||
512 | @item MHD_OPTION_CONNECTION_LIMIT | 521 | @item MHD_OPTION_CONNECTION_LIMIT |
513 | @cindex connection, limiting number of connections | 522 | @cindex connection, limiting number of connections |
514 | Maximum number of concurrent connections to accept (followed by an | 523 | Maximum number of concurrent connections to accept (followed by an |
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index 318a8424..516faceb 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h | |||
@@ -673,7 +673,13 @@ enum MHD_OPTION | |||
673 | * HTTPS daemon for client authentification. | 673 | * HTTPS daemon for client authentification. |
674 | * This option should be followed by a "const char*" argument. | 674 | * This option should be followed by a "const char*" argument. |
675 | */ | 675 | */ |
676 | MHD_OPTION_HTTPS_MEM_TRUST = 20 | 676 | MHD_OPTION_HTTPS_MEM_TRUST = 20, |
677 | |||
678 | /** | ||
679 | * Increment to use for growing the read buffer (followed by a | ||
680 | * size_t). Must fit within MHD_OPTION_CONNECTION_MEMORY_LIMIT. | ||
681 | */ | ||
682 | MHD_OPTION_CONNECTION_MEMORY_INCREMENT = 21 | ||
677 | }; | 683 | }; |
678 | 684 | ||
679 | 685 | ||
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index e54ae1b6..70661f9c 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -37,14 +37,6 @@ | |||
37 | #include <netinet/tcp.h> | 37 | #include <netinet/tcp.h> |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | /** | ||
41 | * Minimum size by which MHD tries to increment read/write buffers. | ||
42 | * We usually begin with half the available pool space for the | ||
43 | * IO-buffer, but if absolutely needed we additively grow by the | ||
44 | * number of bytes given here (up to -- theoretically -- the full pool | ||
45 | * space). | ||
46 | */ | ||
47 | #define MHD_BUF_INC_SIZE 1024 | ||
48 | 40 | ||
49 | /** | 41 | /** |
50 | * Message to transmit when http 1.1 request is received | 42 | * Message to transmit when http 1.1 request is received |
@@ -1861,7 +1853,7 @@ MHD_connection_handle_read (struct MHD_Connection *connection) | |||
1861 | return MHD_YES; | 1853 | return MHD_YES; |
1862 | /* make sure "read" has a reasonable number of bytes | 1854 | /* make sure "read" has a reasonable number of bytes |
1863 | in buffer to use per system call (if possible) */ | 1855 | in buffer to use per system call (if possible) */ |
1864 | if (connection->read_buffer_offset + MHD_BUF_INC_SIZE > | 1856 | if (connection->read_buffer_offset + connection->daemon->pool_increment > |
1865 | connection->read_buffer_size) | 1857 | connection->read_buffer_size) |
1866 | try_grow_read_buffer (connection); | 1858 | try_grow_read_buffer (connection); |
1867 | if (MHD_NO == do_read (connection)) | 1859 | if (MHD_NO == do_read (connection)) |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 28ce1d80..41013db5 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1305,8 +1305,6 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
1305 | struct sockaddr *addr = (struct sockaddr *) &addrstorage; | 1305 | struct sockaddr *addr = (struct sockaddr *) &addrstorage; |
1306 | socklen_t addrlen; | 1306 | socklen_t addrlen; |
1307 | int s; | 1307 | int s; |
1308 | int flags; | ||
1309 | int need_fcntl; | ||
1310 | int fd; | 1308 | int fd; |
1311 | 1309 | ||
1312 | addrlen = sizeof (addrstorage); | 1310 | addrlen = sizeof (addrstorage); |
@@ -1315,10 +1313,8 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
1315 | return MHD_NO; | 1313 | return MHD_NO; |
1316 | #if HAVE_ACCEPT4 | 1314 | #if HAVE_ACCEPT4 |
1317 | s = accept4 (fd, addr, &addrlen, SOCK_CLOEXEC); | 1315 | s = accept4 (fd, addr, &addrlen, SOCK_CLOEXEC); |
1318 | need_fcntl = MHD_NO; | ||
1319 | #else | 1316 | #else |
1320 | s = ACCEPT (fd, addr, &addrlen); | 1317 | s = ACCEPT (fd, addr, &addrlen); |
1321 | need_fcntl = MHD_YES; | ||
1322 | #endif | 1318 | #endif |
1323 | if ((-1 == s) || (addrlen <= 0)) | 1319 | if ((-1 == s) || (addrlen <= 0)) |
1324 | { | 1320 | { |
@@ -1339,7 +1335,6 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
1339 | return MHD_NO; | 1335 | return MHD_NO; |
1340 | } | 1336 | } |
1341 | #if !HAVE_ACCEPT4 | 1337 | #if !HAVE_ACCEPT4 |
1342 | if (MHD_YES == need_fcntl) | ||
1343 | { | 1338 | { |
1344 | /* make socket non-inheritable */ | 1339 | /* make socket non-inheritable */ |
1345 | #ifdef WINDOWS | 1340 | #ifdef WINDOWS |
@@ -1356,6 +1351,8 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
1356 | #endif | 1351 | #endif |
1357 | } | 1352 | } |
1358 | #else | 1353 | #else |
1354 | int flags; | ||
1355 | |||
1359 | flags = fcntl (s, F_GETFD); | 1356 | flags = fcntl (s, F_GETFD); |
1360 | if ( ( (-1 == flags) || | 1357 | if ( ( (-1 == flags) || |
1361 | ( (flags != (flags | FD_CLOEXEC)) && | 1358 | ( (flags != (flags | FD_CLOEXEC)) && |
@@ -2377,6 +2374,9 @@ parse_options_va (struct MHD_Daemon *daemon, | |||
2377 | case MHD_OPTION_CONNECTION_MEMORY_LIMIT: | 2374 | case MHD_OPTION_CONNECTION_MEMORY_LIMIT: |
2378 | daemon->pool_size = va_arg (ap, size_t); | 2375 | daemon->pool_size = va_arg (ap, size_t); |
2379 | break; | 2376 | break; |
2377 | case MHD_OPTION_CONNECTION_MEMORY_INCREMENT: | ||
2378 | daemon->pool_increment= va_arg (ap, size_t); | ||
2379 | break; | ||
2380 | case MHD_OPTION_CONNECTION_LIMIT: | 2380 | case MHD_OPTION_CONNECTION_LIMIT: |
2381 | daemon->max_connections = va_arg (ap, unsigned int); | 2381 | daemon->max_connections = va_arg (ap, unsigned int); |
2382 | break; | 2382 | break; |
@@ -2500,6 +2500,7 @@ parse_options_va (struct MHD_Daemon *daemon, | |||
2500 | { | 2500 | { |
2501 | /* all options taking 'size_t' */ | 2501 | /* all options taking 'size_t' */ |
2502 | case MHD_OPTION_CONNECTION_MEMORY_LIMIT: | 2502 | case MHD_OPTION_CONNECTION_MEMORY_LIMIT: |
2503 | case MHD_OPTION_CONNECTION_MEMORY_INCREMENT: | ||
2503 | case MHD_OPTION_THREAD_STACK_SIZE: | 2504 | case MHD_OPTION_THREAD_STACK_SIZE: |
2504 | if (MHD_YES != parse_options (daemon, | 2505 | if (MHD_YES != parse_options (daemon, |
2505 | servaddr, | 2506 | servaddr, |
@@ -2786,6 +2787,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
2786 | daemon->default_handler_cls = dh_cls; | 2787 | daemon->default_handler_cls = dh_cls; |
2787 | daemon->max_connections = MHD_MAX_CONNECTIONS_DEFAULT; | 2788 | daemon->max_connections = MHD_MAX_CONNECTIONS_DEFAULT; |
2788 | daemon->pool_size = MHD_POOL_SIZE_DEFAULT; | 2789 | daemon->pool_size = MHD_POOL_SIZE_DEFAULT; |
2790 | daemon->pool_increment = MHD_BUF_INC_SIZE; | ||
2789 | daemon->unescape_callback = &MHD_http_unescape; | 2791 | daemon->unescape_callback = &MHD_http_unescape; |
2790 | daemon->connection_timeout = 0; /* no timeout */ | 2792 | daemon->connection_timeout = 0; /* no timeout */ |
2791 | daemon->wpipe[0] = -1; | 2793 | daemon->wpipe[0] = -1; |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 4603050a..61424ca5 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -48,6 +48,16 @@ | |||
48 | 48 | ||
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Minimum size by which MHD tries to increment read/write buffers. | ||
52 | * We usually begin with half the available pool space for the | ||
53 | * IO-buffer, but if absolutely needed we additively grow by the | ||
54 | * number of bytes given here (up to -- theoretically -- the full pool | ||
55 | * space). | ||
56 | */ | ||
57 | #define MHD_BUF_INC_SIZE 1024 | ||
58 | |||
59 | |||
60 | /** | ||
51 | * Handler for fatal errors. | 61 | * Handler for fatal errors. |
52 | */ | 62 | */ |
53 | extern MHD_PanicCallback mhd_panic; | 63 | extern MHD_PanicCallback mhd_panic; |
@@ -1002,6 +1012,11 @@ struct MHD_Daemon | |||
1002 | size_t pool_size; | 1012 | size_t pool_size; |
1003 | 1013 | ||
1004 | /** | 1014 | /** |
1015 | * Increment for growth of the per-connection memory pools. | ||
1016 | */ | ||
1017 | size_t pool_increment; | ||
1018 | |||
1019 | /** | ||
1005 | * Size of threads created by MHD. | 1020 | * Size of threads created by MHD. |
1006 | */ | 1021 | */ |
1007 | size_t thread_stack_size; | 1022 | size_t thread_stack_size; |