src/server/daemon/config.c

changeset 37
360b9aabe17e
parent 36
450d2d5f4735
child 38
d07810b02147
--- a/src/server/daemon/config.c	Sat Oct 06 13:00:07 2012 +0200
+++ b/src/server/daemon/config.c	Sat Dec 15 16:05:03 2012 +0100
@@ -123,7 +123,7 @@
      * convert ServerConfig to ServerConfiguration
      * 
      * its important to do this in the correct order:
-     * LogFile (we want an open log file first to log possible errors)
+     * LogFile (open log file first to log possible errors)
      * Runtime
      * Threadpool
      * EventHandler
@@ -159,14 +159,23 @@
     
     list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10));
     UCX_FOREACH(UcxList*, list, elm) {
-        ServerConfigObject *scfgobj = elm->data;
-        // TODO: threadpool
+        cfg_handle_threadpool(serverconfig, elm->data);
+    }
+    // check thread pool config
+    if(check_thread_pool_cfg() != 0) {
+        /* critical error */
+        return NULL;
     }
     
     list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12));
     UCX_FOREACH(UcxList*, list, elm) {
         cfg_handle_eventhandler(serverconfig, (ServerConfigObject*)elm->data);
     }
+    // check event handler config
+    if(check_event_handler_cfg() != 0) {
+        /* critical error */
+        return NULL;
+    }
     
     list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6));
     UCX_FOREACH(UcxList*, list, elm) {
@@ -185,18 +194,7 @@
         ServerConfigObject *scfgobj = elm->data;
         cfg_handle_vs(serverconfig, scfgobj);
     }
-
-    // check event handler config
-    if(check_event_handler_cfg() != 0) {
-        /* critical error */
-        return NULL;
-    }
     
-    // check thread pool config
-    if(check_thread_pool_cfg() != 0) {
-        /* critical error */
-        return NULL;
-    }
 
     // set VirtualServer for all listeners
     UcxList *ls = serverconfig->listeners;
@@ -271,6 +269,63 @@
     return ret;
 }
 
+int cfg_handle_threadpool(ServerConfiguration *cfg, ServerConfigObject *obj) {
+    ThreadPoolConfig poolcfg;
+    poolcfg.min_threads = 4;
+    poolcfg.min_threads = 4;
+    poolcfg.max_threads = 8;
+    poolcfg.queue_size = 64;
+    poolcfg.stack_size = 262144;
+    
+    sstr_t name = cfg_directivelist_get_str(
+            obj->directives,
+            sstr("Name"));
+    sstr_t min = cfg_directivelist_get_str(
+            obj->directives,
+            sstr("MinThreads"));
+    sstr_t max = cfg_directivelist_get_str(
+            obj->directives,
+            sstr("MaxThreads"));
+    sstr_t stack = cfg_directivelist_get_str(
+            obj->directives,
+            sstr("StackSize"));
+    sstr_t queue = cfg_directivelist_get_str(
+            obj->directives,
+            sstr("QueueSize"));
+    // TODO: Type
+    
+    if(name.length == 0) {
+        // TODO: log error
+        return 1;
+    }
+    
+    if(min.length != 0) {
+        min = sstrdup(min);
+        poolcfg.min_threads = atoi(min.ptr);
+        free(min.ptr);
+    }
+    
+    if(max.length != 0) {
+        max = sstrdup(max);
+        poolcfg.max_threads = atoi(max.ptr);
+        free(max.ptr);
+    }
+    
+    if(stack.length != 0) {
+        stack = sstrdup(stack);
+        poolcfg.stack_size = atoi(stack.ptr);
+        free(stack.ptr);
+    }
+    
+    if(queue.length != 0) {
+        queue = sstrdup(queue);
+        poolcfg.queue_size = atoi(queue.ptr);
+        free(queue.ptr);
+    }
+    
+    create_threadpool(name, &poolcfg);
+}
+
 int cfg_handle_eventhandler(ServerConfiguration *c, ServerConfigObject *obj) {
     EventHandlerConfig evcfg;
     
@@ -317,12 +372,16 @@
     lc.vs = sstrdup(cfg_directivelist_get_str(
             obj->directives,
             sstr("DefaultVS")));
+    lc.threadpool = sstrdup(cfg_directivelist_get_str(
+            obj->directives,
+            sstr("Threadpool")));
     
-
+    // TODO: check if all important configs are set
+    
     HttpListener *listener = http_listener_create(&lc);
     listener->default_vs.vs_name = lc.vs.ptr;
     cfg->listeners = ucx_list_append(cfg->listeners, listener); 
-
+    
     return 0;
 }
 

mercurial