listeners can be dynamically added

Sun, 23 Jun 2013 13:49:17 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 23 Jun 2013 13:49:17 +0200
changeset 74
5bc6d078fb2c
parent 71
069c152f6272
child 75
6195c92262a2

listeners can be dynamically added

src/server/daemon/config.c file | annotate | diff | comparison | revisions
src/server/daemon/configmanager.c file | annotate | diff | comparison | revisions
src/server/daemon/httplistener.c file | annotate | diff | comparison | revisions
src/server/daemon/httplistener.h file | annotate | diff | comparison | revisions
src/server/daemon/main.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/config.c	Fri Jun 21 12:10:44 2013 +0200
+++ b/src/server/daemon/config.c	Sun Jun 23 13:49:17 2013 +0200
@@ -656,14 +656,14 @@
         return NULL;
     }
 
-    /* create object config */
+    // create object config
     pool_handle_t *pool = pool_create();
     HTTPObjectConfig *conf = pool_calloc(pool, sizeof(HTTPObjectConfig), 1);
     conf->pool = pool;
 
-    /* convert ObjectConfig to HTTPObjectConfig */
+    // convert ObjectConfig to HTTPObjectConfig
 
-    /* add objects */
+    // add objects
     conf->nobj = ucx_dlist_size(cfg->objects);
     conf->objects = pool_calloc(pool, 1, sizeof(httpd_object*));
     
@@ -672,7 +672,7 @@
     while(objlist != NULL) {
         ConfigObject *cob = objlist->data;
 
-        /* get name and ppath */
+        // get name and ppath
         char *name = NULL;
         char *ppath = NULL;
         if(cob->name.length > 0) {
@@ -682,13 +682,13 @@
             ppath = sstrdup_pool(pool, cob->ppath).ptr;
         }
 
-        /* create and add object */
+        // create and add object
         httpd_object *obj = object_new(pool, name);
         obj->path = NULL;
 
         conf->objects[i] = obj; // TODO: beyond array bounds write
 
-        /* add directives */
+        // add directives
         for(int i=0;i<6;i++) {
             UcxDlist *dirs = cob->directives[i];
             while(dirs != NULL) {
@@ -698,7 +698,7 @@
                 d->cond = NULL;
                 d->param = pblock_create_pool(pool, 8);
 
-                /* add params */
+                // add params
                 UcxList *param = cfg_param_list(cfgdir->value, mp);
                 while(param != NULL) {
                     ConfigParam *p = param->data;
@@ -711,18 +711,18 @@
                     param = param->next;
                 }
 
-                /* get function */
+                // get function
                 char *func_name = pblock_findval("fn", d->param);
                 d->func = get_function(func_name);
 
                 dirs = dirs->next;
 
-                /* add function to dtable */
+                // add function to dtable
                 object_add_directive(obj, d, cfgdir->type_num);
             }
         }
 
-        /* next */
+        // next
         i++;
         objlist = objlist->next;
     }
--- a/src/server/daemon/configmanager.c	Fri Jun 21 12:10:44 2013 +0200
+++ b/src/server/daemon/configmanager.c	Sun Jun 23 13:49:17 2013 +0200
@@ -140,8 +140,7 @@
     }
 
     ServerConfiguration *config;
-    //if(sc_last_modified != s.st_mtim.tv_sec) {
-    if(cfgreload || !current_config) {
+    if(cfgreload || !current_config || sc_last_modified != s.st_mtime) {
         printf("cfgmgr load server.conf\n");
         config = load_server_conf(
             current_config,
--- a/src/server/daemon/httplistener.c	Fri Jun 21 12:10:44 2013 +0200
+++ b/src/server/daemon/httplistener.c	Sun Jun 23 13:49:17 2013 +0200
@@ -89,6 +89,7 @@
     newls->default_vs.vs_name = conf->vs.ptr;  
     newls->port = fl->port;
     newls->server_socket = fl->server_socket;
+    newls->running = 1;
     newls->ref = 2; // 1 reference is fl->next
     
     newls->session_handler = fl->session_handler; // TODO
@@ -139,6 +140,7 @@
     // end remove
 
     HttpListener *listener = malloc(sizeof(HttpListener));
+    listener->running = 0;
     listener->cfg = conf->cfg;
     listener->name = conf->name;
     listener->default_vs.vs_name = conf->vs.ptr;
@@ -194,6 +196,9 @@
 }
 
 int http_listener_start(HttpListener *listener) {
+    if(listener->running) {
+        return 0;
+    }
     printf("INFO: start listener\n");
     log_ereport(LOG_INFORM, "start listener on port %d", listener->port);
 
--- a/src/server/daemon/httplistener.h	Fri Jun 21 12:10:44 2013 +0200
+++ b/src/server/daemon/httplistener.h	Sun Jun 23 13:49:17 2013 +0200
@@ -72,6 +72,7 @@
     HttpListener         *next;
     Acceptor             **acceptors;
     int                  nacceptors;
+    int                  running;
     uint32_t             ref; // reference counter
 };
 
--- a/src/server/daemon/main.c	Fri Jun 21 12:10:44 2013 +0200
+++ b/src/server/daemon/main.c	Sun Jun 23 13:49:17 2013 +0200
@@ -42,6 +42,7 @@
 #include "webserver.h"
 #include "log.h"
 #include "httprequest.h"
+#include "httplistener.h"
 
 #include "configmanager.h"
 
@@ -63,6 +64,8 @@
     if(cfgmgr_load_config() != 0) {
         log_ereport(LOG_FAILURE, "cannot reload config");
     }
+    // start newly created listeners
+    start_all_listener();
 
     signal(SIGUSR1, sig_usr1_reload);
 }

mercurial