Skip to content

Commit fc59463

Browse files
authored
feat(listener): enforce reload conn and stream opts (#346)
* feat(listener): support reload conn and stream opts * chore: listener_opts type
1 parent fa2f8da commit fc59463

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

src/quicer.erl

+2-3
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@
184184
probe_res/0
185185
]).
186186

187-
-type connection_opts() :: proplists:proplist() | conn_opts().
188-
-type listener_opts() :: proplists:proplist() | listen_opts().
187+
-type listener_opts() :: quicer_listener:listener_opts().
189188

190189
%% @doc Return ABI version of the library.
191190
-spec abi_version() -> quicer_nif:abi_version().
@@ -316,7 +315,7 @@ stop_listener(Handle) ->
316315
-spec spawn_listener(
317316
Appname :: atom() | listener_handle(),
318317
listen_on(),
319-
{listener_opts(), connection_opts(), stream_opts() | user_opts()}
318+
listener_opts()
320319
) ->
321320
{ok, pid()} | {error, any()}.
322321
spawn_listener(AppName, Port, Options) when is_atom(AppName) ->

src/quicer_listener.erl

+18-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
-behaviour(gen_server).
1919

20+
-include("quicer_types.hrl").
21+
2022
%% API
2123
-export([
2224
start_link/3,
@@ -49,10 +51,19 @@
4951
opts_tab :: ets:tid()
5052
}).
5153

52-
-export_type([listener_name/0]).
54+
-export_type([
55+
listener_name/0,
56+
listener_opts/0
57+
]).
5358

5459
-type listener_name() :: atom().
5560

61+
-type listener_opts() :: {
62+
listen_opts() | proplists:proplist(),
63+
conn_opts() | proplists:proplist(),
64+
stream_opts() | proplists:proplist()
65+
}.
66+
5667
%%%===================================================================
5768
%%% API
5869
%%%===================================================================
@@ -101,7 +112,7 @@ reload(Pid, NewConf) ->
101112
%% @NOTE: the acceptor opts and stream opts are not reloaded.
102113
%%% if you want to reload them, you should restart the listener (terminate and spawn).
103114
%% @end
104-
-spec reload(pid(), quicer:listen_on(), NewConf :: map() | {map(), map(), map()}) ->
115+
-spec reload(pid(), quicer:listen_on(), NewConf :: listener_opts()) ->
105116
ok | {error, _}.
106117
reload(Pid, ListenOn, NewConf) ->
107118
gen_server:call(Pid, {reload, ListenOn, NewConf}, infinity).
@@ -116,7 +127,7 @@ count_conns(Pid) ->
116127
gen_server:call(Pid, count_conns, infinity).
117128

118129
%% @doc get the listener configuration
119-
-spec get_conf(pid(), timeout()) -> {map(), map(), map()}.
130+
-spec get_conf(pid(), timeout()) -> listener_opts().
120131
get_conf(Pid, Timeout) ->
121132
gen_server:call(Pid, get_conf, Timeout).
122133

@@ -262,14 +273,14 @@ terminate(_Reason, #state{listener = L}) ->
262273
_ = quicer:close_listener(L),
263274
ok.
264275

265-
-spec do_reload(quicer:listen_on(), map() | {map(), map(), map()}, #state{}) ->
276+
-spec do_reload(quicer:listen_on(), listener_opts(), #state{}) ->
266277
{ok | {error, any()}, #state{}}.
267-
do_reload(ListenOn, NewConf, #state{opts_tab = OptsTab} = State) ->
278+
do_reload(ListenOn, {LOpts, _, _} = NewConf, #state{opts_tab = OptsTab} = State) ->
268279
_ = quicer:stop_listener(State#state.listener),
269280
Res = quicer:start_listener(
270281
State#state.listener,
271282
ListenOn,
272-
NewConf
283+
LOpts
273284
),
274285
case Res of
275286
ok ->
@@ -291,9 +302,7 @@ conf_tab_refresh(Tab, {LOpts, COpts, SOpts}) ->
291302
{l_opts, to_map(LOpts)},
292303
{c_opts, to_map(COpts)},
293304
{s_opts, to_map(SOpts)}
294-
]);
295-
conf_tab_refresh(Tab, LOpts) ->
296-
ets:insert(Tab, {l_opts, to_map(LOpts)}).
305+
]).
297306

298307
to_map(Opts) when is_list(Opts) ->
299308
maps:from_list(Opts);

test/quicer_listener_SUITE.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ tc_listener_conf_reload(Config) ->
528528
{cacertfile, filename:join(DataDir, "other-ca.pem")}
529529
],
530530
NewListenerOpts = ListenerOpts ++ NewCerts,
531-
ok = quicer_listener:reload(QuicApp, NewListenerOpts),
531+
ok = quicer_listener:reload(QuicApp, {NewListenerOpts, ConnectionOpts, StreamOpts}),
532532
%% THEN: the listener handle is unchanged
533533
?assertEqual({ok, LHandle}, quicer_listener:get_handle(QuicApp, 5000)),
534534

@@ -619,7 +619,7 @@ tc_listener_conf_reload_listen_on(Config) ->
619619
{ok, LHandle} = quicer_listener:get_handle(QuicApp, 5000),
620620
%% WHEN: the listener is reloaded with ListenOn (new bind address)
621621
NewPort = select_port(),
622-
ok = quicer_listener:reload(QuicApp, NewPort, ListenerOpts),
622+
ok = quicer_listener:reload(QuicApp, NewPort, Options),
623623
%% THEN: the listener handle is unchanged
624624
%%
625625
?assertEqual({ok, LHandle}, quicer_listener:get_handle(QuicApp, 5000)),
@@ -702,7 +702,7 @@ tc_listener_conf_reload_listen_on_neg(Config) ->
702702
%% WHEN: the listener is reloaded with ListenOn (new invalid bind address)
703703
NewPort = 1,
704704
%% THEN: We get error
705-
{error, _, _} = quicer_listener:reload(QuicApp, NewPort, ListenerOpts),
705+
{error, _, _} = quicer_listener:reload(QuicApp, NewPort, Options),
706706
%% THEN: the listener handle is unchanged
707707
?assertEqual({ok, LHandle}, quicer_listener:get_handle(QuicApp, 5000)),
708708

0 commit comments

Comments
 (0)