aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r--src/daemon/daemon.c58
1 files changed, 54 insertions, 4 deletions
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,