Allow no caching at all
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 14 Jun 2019 15:28:27 +0000 (17:28 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 14 Jun 2019 15:28:27 +0000 (17:28 +0200)
Change-Id: I73f7a7cc6ab96cc7e6064e267b126b883b94bc69
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/cache.c
src/cache.h
src/lib-compat.c
src/rcyn-client.c
src/rcyn-protocol.txt

index c8e7550..0759f1f 100644 (file)
@@ -255,10 +255,12 @@ cache_search(
 ) {
        item_t *item;
 
-       item = search(cache, key);
-       if (item) {
-               hit(cache, item);
-               return (int)item->value;
+       if (cache) {
+               item = search(cache, key);
+               if (item) {
+                       hit(cache, item);
+                       return (int)item->value;
+               }
        }
        return -ENOENT;
 }
@@ -281,18 +283,23 @@ cache_resize(
 ) {
        cache_t *c = *cache, *nc;
 
-       if (c)
-               while (c->used > newsize)
-                       drop_lre(c);
+       if (newsize == 0) {
+               free(c);
+               nc = NULL;
+       } else {
+               if (c)
+                       while (c->used > newsize)
+                               drop_lre(c);
 
-       nc = realloc(c, newsize - 1 + sizeof *c);
-       if (nc == NULL)
-               return -ENOMEM;
+               nc = realloc(c, newsize - 1 + sizeof *c);
+               if (nc == NULL)
+                       return -ENOMEM;
 
-       nc->count = newsize;
-       if (!c) {
-               nc->cacheid = 0;
-               nc->used = 0;
+               nc->count = newsize;
+               if (!c) {
+                       nc->cacheid = 0;
+                       nc->used = 0;
+               }
        }
        *cache = nc;
        return 0;
@@ -308,4 +315,3 @@ cache_create(
 }
 
 
-
index 4ddaa1e..dd37d92 100644 (file)
@@ -56,6 +56,3 @@ cache_create(
        cache_t **cache,
        uint32_t size
 );
-
-
-
index 175ec5f..8f27cf3 100644 (file)
@@ -147,7 +147,7 @@ struct cynara_admin;
 
 int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin)
 {
-       return from_status(rcyn_open((rcyn_t**)pp_cynara_admin, rcyn_Admin, 0, 0));
+       return from_status(rcyn_open((rcyn_t**)pp_cynara_admin, rcyn_Admin, 1, 0));
 }
 
 int cynara_admin_finish(struct cynara_admin *p_cynara_admin)
@@ -409,7 +409,7 @@ int cynara_async_initialize(cynara_async **pp_cynara, const cynara_async_configu
        if (p_cynara == NULL)
                ret = CYNARA_API_OUT_OF_MEMORY;
        else {
-               ret = from_status(rcyn_open(&p_cynara->rcyn, rcyn_Check, p_conf ? p_conf->szcache : 0, 0));
+               ret = from_status(rcyn_open(&p_cynara->rcyn, rcyn_Check, p_conf ? p_conf->szcache : 1, 0));
                if (ret != CYNARA_API_SUCCESS)
                        free(p_cynara);
                else {
@@ -557,7 +557,7 @@ int cynara_configuration_set_cache_size(cynara_configuration *p_conf,
 
 int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf)
 {
-       return from_status(rcyn_open((rcyn_t**)pp_cynara, rcyn_Check, p_conf ? p_conf->szcache : 0, 0));
+       return from_status(rcyn_open((rcyn_t**)pp_cynara, rcyn_Check, p_conf ? p_conf->szcache : 1, 0));
 }
 
 int cynara_finish(cynara *p_cynara)
index 769c6c0..152dc87 100644 (file)
@@ -38,6 +38,7 @@
 #include "socket.h"
 
 #define MIN_CACHE_SIZE 400
+#define CACHESIZE(x)  ((x) >= MIN_CACHE_SIZE ? (x) : (x) ? MIN_CACHE_SIZE : 0)
 
 struct asreq;
 typedef struct asreq asreq_t;
@@ -440,7 +441,7 @@ rcyn_open(
        strcpy((char*)(rcyn+1), socketspec);
 
        /* record type and weakly create cache */
-       cache_create(&rcyn->cache, cache_size < MIN_CACHE_SIZE ? MIN_CACHE_SIZE : cache_size);
+       cache_create(&rcyn->cache, CACHESIZE(cache_size));
        rcyn->type = type;
        rcyn->socketspec = socketspec;
        rcyn->async.controlcb = NULL;
@@ -550,7 +551,7 @@ check_or_test(
                rc = wait_pending_reply(rcyn);
                if (rc >= 0) {
                        rc = status_check(rcyn, &expire);
-                       if (rc >= 0)
+                       if (rcyn->cache && rc >= 0)
                                cache_put(rcyn->cache, key, rc, expire);
                }
        }
@@ -689,7 +690,7 @@ rcyn_cache_resize(
        rcyn_t *rcyn,
        uint32_t size
 ) {
-       return cache_resize(&rcyn->cache, size < MIN_CACHE_SIZE ? MIN_CACHE_SIZE : size);
+       return cache_resize(&rcyn->cache, CACHESIZE(size));
 }
 
 void
index 582a912..b2f1ae6 100644 (file)
@@ -57,9 +57,9 @@ register agent (agent):
   c->s agent NAME [ARGS...]
   s->c done|error ...
 
-asking (agent ask CLIENT SESSION USER PERMISSION):
+ask agent (agent):
 
-  s->c ask CLIENT SESSION USER PERMISSION
+  s->c ask NAME VALUE CLIENT SESSION USER PERMISSION
   c->s done | ([yes|no] [always|session|one-time|EXPIRE])