diff options
Diffstat (limited to 'p11p-daemon/src/p11p_config.erl')
-rw-r--r-- | p11p-daemon/src/p11p_config.erl | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/p11p-daemon/src/p11p_config.erl b/p11p-daemon/src/p11p_config.erl index c4bfbcd..13723ce 100644 --- a/p11p-daemon/src/p11p_config.erl +++ b/p11p-daemon/src/p11p_config.erl @@ -31,7 +31,7 @@ name :: string(), timeout :: non_neg_integer(), failover :: non_neg_integer(), % How many failover attempts. - balance :: [non_neg_integer()], + balance :: [integer()], modules = #{} :: #{string() => p11module()} }). -type token() :: #token{}. @@ -177,15 +177,16 @@ new_token({Name, Settings}) -> name = Name, timeout = proplists:get_value(timeout, Settings, 25000), failover = proplists:get_value(failover, Settings, maps:size(Modules) - 1), - balance = balance(proplists:get_value(balance, Settings, []), - maps:size(Modules)), + balance = lists:map(fun(N) -> case N of 0 -> -1; _ -> N end end, + balance(proplists:get_value(balance, Settings, []), + maps:size(Modules))), modules = Modules }. -balance([], _) -> - []; +balance([], NModules) -> + balance([0], NModules - 1); balance(List, NModules) -> - List ++ [1 || _ <- lists:seq(1, NModules - length(List))]. + List ++ [0 || _ <- lists:seq(1, NModules - length(List))]. conf_modules(L) -> conf_modules(L, #{}). @@ -230,7 +231,7 @@ tokens_init_test_() -> {token,"vtoken0", 25000, 1, - [3,1], + [3,-1], #{"bogusmod0_0" => {p11module,"bogusmod0_0", "/path/to/bogusmod0_0", []}, "bogusmod0_1" => @@ -239,13 +240,10 @@ tokens_init_test_() -> {token,"vtoken1", 12000, 3, - [], + [-1], #{"bogusmod1_0" => {p11module,"bogusmod1_0", "/path/to/bogusmod1_0", []}, "bogusmod1_1" => {p11module,"bogusmod1_1", "/path/to/bogusmod1_1", [{"MYENV", "myenv"}]}}} }, Conf)] end}. -%% modules_for_token_test_() -> -%% {setup, -%% fun() -> |