aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-12-19 12:47:23 +0000
committerChristian Grothoff <christian@grothoff.org>2010-12-19 12:47:23 +0000
commit52a579f8d16f106a83b4a5cab16bf32ba5b280dc (patch)
tree45db2e4b00bc5792f6565e1ae25549f90b2ded20
parente2b97b7e9c8577a58e22432529d935f189f51c02 (diff)
downloadlibmicrohttpd-52a579f8d16f106a83b4a5cab16bf32ba5b280dc.tar.gz
libmicrohttpd-52a579f8d16f106a83b4a5cab16bf32ba5b280dc.zip
option to set stack size
-rw-r--r--ChangeLog3
-rw-r--r--doc/microhttpd.texi9
-rw-r--r--src/daemon/daemon.c58
-rw-r--r--src/daemon/internal.h5
-rw-r--r--src/include/microhttpd.h10
5 files changed, 80 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 1150386e..067208eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
1Sun Dec 19 13:46:52 CET 2010
2 Added option to specify size of stacks for threads created by MHD. -CG
3
1Tue Nov 23 09:41:00 CET 2010 4Tue Nov 23 09:41:00 CET 2010
2 Releasing libmicrohttpd 0.9.3. -CG 5 Releasing libmicrohttpd 0.9.3. -CG
3 6
diff --git a/doc/microhttpd.texi b/doc/microhttpd.texi
index 9f509814..883018f1 100644
--- a/doc/microhttpd.texi
+++ b/doc/microhttpd.texi
@@ -562,6 +562,15 @@ updated. Note that the unescape function must not lengthen @code{s}
562(the result must be shorter than the input and still be 0-terminated). 562(the result must be shorter than the input and still be 0-terminated).
563@code{cls} will be set to the second argument following 563@code{cls} will be set to the second argument following
564MHD_OPTION_UNESCAPE_CALLBACK. 564MHD_OPTION_UNESCAPE_CALLBACK.
565
566
567@item MHD_OPTION_THREAD_STACK_SIZE
568@cindex stack, thread, pthread
569Maximum stack size for threads created by MHD. This option must be
570followed by a @code{size_t}). Not specifying this option or using
571a value of zero means using the system default (which is likely to
572differ based on your platform).
573
565@end table 574@end table
566@end deftp 575@end deftp
567 576
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index f16491c7..558954d6 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -753,6 +753,52 @@ socket_set_nonblocking (int fd)
753 753
754 754
755/** 755/**
756 * Create a thread and set the attributes according to our options.
757 *
758 * @param thread handle to initialize
759 * @param daemon daemon with options
760 * @param start_routine main function of thread
761 * @param arg argument for start_routine
762 * @return 0 on success
763 */
764static int
765create_thread (pthread_t * thread,
766 const struct MHD_Daemon *daemon,
767 void *(*start_routine)(void*),
768 void *arg)
769{
770 pthread_attr_t attr;
771 pthread_attr_t *pattr;
772 int ret;
773
774 if (daemon->thread_stack_size != 0)
775 {
776 if ( (0 != (ret = pthread_attr_init (&attr))) ||
777 (0 != (ret = pthread_attr_setstacksize (&attr, daemon->thread_stack_size))) )
778 {
779#if HAVE_MESSAGES
780 MHD_DLOG (daemon,
781 "Failed to set thread stack size\n");
782#endif
783 errno = EINVAL;
784 return ret;
785 }
786 pattr = &attr;
787 }
788 else
789 {
790 pattr = NULL;
791 }
792 ret = pthread_create (thread, pattr,
793 start_routine, arg);
794 if (pattr != NULL)
795 pthread_attr_destroy (&attr);
796 return ret;
797}
798
799
800
801/**
756 * Accept an incoming connection and create the MHD_Connection object for 802 * Accept an incoming connection and create the MHD_Connection object for
757 * it. This function also enforces policy by way of checking with the 803 * it. This function also enforces policy by way of checking with the
758 * accept policy callback. 804 * accept policy callback.
@@ -943,8 +989,8 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
943 /* attempt to create handler thread */ 989 /* attempt to create handler thread */
944 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 990 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
945 { 991 {
946 res_thread_create = pthread_create (&connection->pid, NULL, 992 res_thread_create = create_thread (&connection->pid, daemon,
947 &MHD_handle_connection, connection); 993 &MHD_handle_connection, connection);
948 if (res_thread_create != 0) 994 if (res_thread_create != 0)
949 { 995 {
950#if HAVE_MESSAGES 996#if HAVE_MESSAGES
@@ -1464,6 +1510,9 @@ parse_options_va (struct MHD_Daemon *daemon,
1464 va_arg (ap, void *); 1510 va_arg (ap, void *);
1465#endif 1511#endif
1466 break; 1512 break;
1513 case MHD_OPTION_THREAD_STACK_SIZE:
1514 daemon->thread_stack_size = va_arg (ap, size_t);
1515 break;
1467 case MHD_OPTION_ARRAY: 1516 case MHD_OPTION_ARRAY:
1468 oa = va_arg (ap, struct MHD_OptionItem*); 1517 oa = va_arg (ap, struct MHD_OptionItem*);
1469 i = 0; 1518 i = 0;
@@ -1473,6 +1522,7 @@ parse_options_va (struct MHD_Daemon *daemon,
1473 { 1522 {
1474 /* all options taking 'size_t' */ 1523 /* all options taking 'size_t' */
1475 case MHD_OPTION_CONNECTION_MEMORY_LIMIT: 1524 case MHD_OPTION_CONNECTION_MEMORY_LIMIT:
1525 case MHD_OPTION_THREAD_STACK_SIZE:
1476 if (MHD_YES != parse_options (daemon, 1526 if (MHD_YES != parse_options (daemon,
1477 servaddr, 1527 servaddr,
1478 opt, 1528 opt,
@@ -1904,7 +1954,7 @@ MHD_start_daemon_va (unsigned int options,
1904 ( (0 != (options & MHD_USE_SELECT_INTERNALLY)) && 1954 ( (0 != (options & MHD_USE_SELECT_INTERNALLY)) &&
1905 (0 == retVal->worker_pool_size)) ) && 1955 (0 == retVal->worker_pool_size)) ) &&
1906 (0 != (res_thread_create = 1956 (0 != (res_thread_create =
1907 pthread_create (&retVal->pid, NULL, &MHD_select_thread, retVal)))) 1957 create_thread (&retVal->pid, retVal, &MHD_select_thread, retVal))))
1908 { 1958 {
1909#if HAVE_MESSAGES 1959#if HAVE_MESSAGES
1910 MHD_DLOG (retVal, 1960 MHD_DLOG (retVal,
@@ -1982,7 +2032,7 @@ MHD_start_daemon_va (unsigned int options,
1982 ++d->max_connections; 2032 ++d->max_connections;
1983 2033
1984 /* Spawn the worker thread */ 2034 /* Spawn the worker thread */
1985 if (0 != (res_thread_create = pthread_create (&d->pid, NULL, &MHD_select_thread, d))) 2035 if (0 != (res_thread_create = create_thread (&d->pid, retVal, &MHD_select_thread, d)))
1986 { 2036 {
1987#if HAVE_MESSAGES 2037#if HAVE_MESSAGES
1988 MHD_DLOG (retVal, 2038 MHD_DLOG (retVal,
diff --git a/src/daemon/internal.h b/src/daemon/internal.h
index cdf93f51..be476f4b 100644
--- a/src/daemon/internal.h
+++ b/src/daemon/internal.h
@@ -825,6 +825,11 @@ struct MHD_Daemon
825 size_t pool_size; 825 size_t pool_size;
826 826
827 /** 827 /**
828 * Size of threads created by MHD.
829 */
830 size_t thread_stack_size;
831
832 /**
828 * Number of worker daemons 833 * Number of worker daemons
829 */ 834 */
830 unsigned int worker_pool_size; 835 unsigned int worker_pool_size;
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index de8468b0..a30f87a9 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -558,7 +558,15 @@ enum MHD_OPTION
558 * the nonce counter. This option should be followed by a "unsigend int" 558 * the nonce counter. This option should be followed by a "unsigend int"
559 * argument. 559 * argument.
560 */ 560 */
561 MHD_OPTION_NONCE_NC_SIZE = 18 561 MHD_OPTION_NONCE_NC_SIZE = 18,
562
563 /**
564 * Desired size of the stack for threads created by MHD. Followed
565 * by an argument of type 'size_t'. Use 0 for system 'default'.
566 */
567 MHD_OPTION_THREAD_STACK_SIZE = 19
568
569
562}; 570};
563 571
564 572