add option --session-max
authorJosé Bollo <jose.bollo@iot.bzh>
Mon, 30 May 2016 12:48:26 +0000 (14:48 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 30 May 2016 12:48:26 +0000 (14:48 +0200)
Change-Id: I0f1a3ea3099b6b4e5485efa927c98c316ae6d195
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-config.h
src/main.c

index 5fe87c6..b049326 100644 (file)
@@ -54,6 +54,7 @@ struct afb_config
   int  cacheTimeout;
   int  apiTimeout;
   int  cntxTimeout;        // Client Session Context timeout
+  int  nbSessionMax;   // max count of sessions
   int mode;           // mode of listening
   int aliascount;
   struct afb_config_item *items;
index 54cd6f6..9f5bc5c 100644 (file)
@@ -79,6 +79,8 @@
 #define DBUS_SERVICE       21
 #define SO_PLUGIN          22
 
+#define SET_SESSIONMAX     23
+
 // Command line structure hold cli --command + help text
 typedef struct {
   int  val;        // command number within application
@@ -103,7 +105,7 @@ static  AFB_options cliOptions [] = {
   
   {SET_APITIMEOUT   ,1,"apitimeout"      , "Plugin API timeout in seconds [default 10]"},
   {SET_CNTXTIMEOUT  ,1,"cntxtimeout"     , "Client Session Context Timeout [default 900]"},
-  {SET_CACHE_TIMEOUT,1,"cache-eol"       , "Client cache end of live [default 3600s]"},
+  {SET_CACHE_TIMEOUT,1,"cache-eol"       , "Client cache end of live [default 3600]"},
   
   {SET_SESSION_DIR  ,1,"sessiondir"      , "Sessions file path [default rootdir/sessions]"},
 
@@ -120,6 +122,8 @@ static  AFB_options cliOptions [] = {
   {DBUS_SERVICE     ,1,"dbus-server"     , "provides an afb service through dbus"},
   {SO_PLUGIN        ,1,"plugin"          , "load the plugin of path"},
 
+  {SET_SESSIONMAX   ,1,"session-max"     , "max count of session simultaneously [default 10]"},
+
   {0, 0, NULL, NULL}
  };
 
@@ -186,6 +190,10 @@ static void config_set_default (struct afb_config * config)
    if (config->cntxTimeout == 0)
                config->cntxTimeout = DEFLT_CNTX_TIMEOUT;
 
+   // max count of sessions
+   if (config->nbSessionMax == 0)
+       config->nbSessionMax = CTX_NBCLIENTS;
+
    if (config->rootdir == NULL) {
        config->rootdir = getenv("AFBDIR");
        if (config->rootdir == NULL) {
@@ -346,6 +354,11 @@ static void parse_arguments(int argc, char *argv[], struct afb_config *config)
        if (!sscanf (optarg, "%d", &config->cacheTimeout)) goto notAnInteger;
        break;
 
+    case  SET_SESSIONMAX:
+       if (optarg == 0) goto needValueForOption;
+       if (!sscanf (optarg, "%d", &config->nbSessionMax)) goto notAnInteger;
+       break;
+
     case SET_FORGROUND:
        if (optarg != 0) goto noValueForOption;
        config->background  = 0;
@@ -596,7 +609,7 @@ int main(int argc, char *argv[])  {
   start_items(config->items);
   config->items = NULL;
 
-  ctxStoreInit(CTX_NBCLIENTS, config->cntxTimeout, config->token, afb_apis_count());
+  ctxStoreInit(config->nbSessionMax, config->cntxTimeout, config->token, afb_apis_count());
   if (!afb_hreq_init_cookie(config->httpdPort, config->rootapi, DEFLT_CNTX_TIMEOUT)) {
      ERROR("initialisation of cookies failed");
      exit (1);