Commit 41abcb92 authored by Geoff Simmons's avatar Geoff Simmons

first version in which the constructor has arguments to configure

the underlying hash, and getter methods return the config values
parent 574e89ff
......@@ -26,7 +26,7 @@ varnish v1 -vcl+backend {
import std;
sub vcl_init {
new inst = vtstor.vtstor();
new inst = vtstor.vtstor(0, 0, 0, 0);
}
sub vcl_recv {
......
varnishtest "vtstor-vmod: test the contructor"
server s1 {} -start
varnish v1 -vcl+backend {
import vtstor from "${vmod_topbuild}/src/.libs/libvmod_vtstor.so";
import std;
sub vcl_init {
new zero = vtstor.vtstor(0, 0, 0, 0);
}
sub vcl_recv {
return(synth(200, "OK"));
}
sub vcl_synth {
set resp.http.Zero-Buckets = zero.buckets();
set resp.http.Zero-Timeout = zero.timeout();
set resp.http.Zero-Keymax = zero.key_max();
set resp.http.Zero-Valmax = zero.value_max();
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Zero-Buckets == "1024"
expect resp.http.Zero-Timeout == "60"
expect resp.http.Zero-Keymax == "64"
expect resp.http.Zero-Valmax == "4096"
} -run
......@@ -61,8 +61,9 @@ selecthttp(VRT_CTX, enum gethdr_e where)
}
VCL_VOID __match_proto__(td_vmod_vtstor__init)
vmod_vtstor__init(VRT_CTX,
struct vmod_vtstor_vtstor **vmip, const char *vcl_name)
vmod_vtstor__init(VRT_CTX, struct vmod_vtstor_vtstor **vmip,
const char *vcl_name, VCL_INT nbuckets,
VCL_INT timeout, VCL_INT keymax, VCL_INT valmax)
{
struct vmod_vtstor_vtstor *vmi;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
......@@ -75,10 +76,19 @@ vmod_vtstor__init(VRT_CTX,
vmi->hash = vtstor_hash_sha256;
vmi->alloc = vtstor_alloc;
vmi->dealloc = vtstor_dealloc;
vmi->buckets = 1024;
vmi->timeout = 60;
vmi->key_max = 64;
vmi->value_max = 4096;
#define CONFIG(f,d,v) do { \
vmi->f = (d); \
if ((v) > 0) \
vmi->f = (v); \
} while (0)
CONFIG(buckets, DEFAULT_NBUCKETS, nbuckets);
CONFIG(timeout, DEFAULT_TIMEOUT, timeout);
CONFIG(key_max, DEFAULT_KEYMAX, keymax);
CONFIG(value_max, DEFAULT_VALMAX, valmax);
#undef CONFIG
vmi->map = vtstor_init(vmi);
*vmip = vmi;
CHECK_OBJ_NOTNULL(*vmip, VMOD_VTSTOR_VTSTOR_MAGIC);
......@@ -156,6 +166,42 @@ vmod_vtstor_delete(VRT_CTX, struct vmod_vtstor_vtstor *vmi, VCL_HEADER hdr)
}
}
VCL_INT __match_proto__(td_vmod_vtstor_buckets)
vmod_vtstor_buckets(VRT_CTX, struct vmod_vtstor_vtstor *vmi)
{
(void) ctx;
CHECK_OBJ_NOTNULL(vmi, VMOD_VTSTOR_VTSTOR_MAGIC);
return vmi->buckets;
}
VCL_INT __match_proto__(td_vmod_vtstor_timeout)
vmod_vtstor_timeout(VRT_CTX, struct vmod_vtstor_vtstor *vmi)
{
(void) ctx;
CHECK_OBJ_NOTNULL(vmi, VMOD_VTSTOR_VTSTOR_MAGIC);
return vmi->timeout;
}
VCL_INT __match_proto__(td_vmod_vtstor_keymax)
vmod_vtstor_key_max(VRT_CTX, struct vmod_vtstor_vtstor *vmi)
{
(void) ctx;
CHECK_OBJ_NOTNULL(vmi, VMOD_VTSTOR_VTSTOR_MAGIC);
return vmi->key_max;
}
VCL_INT __match_proto__(td_vmod_vtstor_value_max)
vmod_vtstor_value_max(VRT_CTX, struct vmod_vtstor_vtstor *vmi)
{
(void) ctx;
CHECK_OBJ_NOTNULL(vmi, VMOD_VTSTOR_VTSTOR_MAGIC);
return vmi->value_max;
}
VCL_STRING __match_proto__(td_vmod_vxid)
vmod_vxid(VRT_CTX)
{
......
......@@ -28,10 +28,14 @@
$Module vtstor 3
$Object vtstor()
$Object vtstor(INT, INT, INT, INT)
$Method VOID .store(STRING, HEADER)
$Method STRING .get(HEADER)
$Method VOID .delete(HEADER)
$Method INT .buckets()
$Method INT .timeout()
$Method INT .key_max()
$Method INT .value_max()
$Function STRING vxid()
......
......@@ -33,6 +33,11 @@
#include "vcc_if.h"
#define DEFAULT_NBUCKETS 1024
#define DEFAULT_TIMEOUT 60
#define DEFAULT_KEYMAX 64
#define DEFAULT_VALMAX 4096
struct vmod_vtstor_vtstor;
typedef size_t (*malloc_func)(struct vmod_vtstor_vtstor *, size_t, char **);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment