Skip to content

Commit

Permalink
chore: fix more types
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Dec 1, 2023
1 parent 4fa4fcc commit dbb7262
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
6 changes: 0 additions & 6 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,3 @@
{source_url, "https://github.com/emqx/quic"}
]}.

{dialyzer, [
{warnings, [unmatched_returns, error_handling]},
{plt_apps, all_apps},
{statistics, true}
]
}.
39 changes: 19 additions & 20 deletions src/quicer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,13 @@
%% export types
-export_type([listener_handle/0,
listener_opts/0,
listen_on/0,
connection_handle/0,
conn_opts/0,
stream_handle/0,
stream_opts/0
]).



-type connection_opts() :: proplists:proplist() | conn_opts().
-type listener_opts() :: proplists:proplist() | listen_opts().

Expand Down Expand Up @@ -173,32 +172,32 @@ close_lib() ->


%% @doc Create a new registration.
-spec new_registration(Name, Profile) ->
quicer_nif:new_registration(Name, Profile).
-spec new_registration(_Name, _Profile) ->
quicer_nif:new_registration().
new_registration(Name, Profile) ->
quicer_nif:new_registration(Name, Profile).

%% @doc Shutdown a registration.
-spec shutdown_registration(Handle) ->
quicer_nif:shutdown_registration(Handle).
-spec shutdown_registration(_Handle) ->
quicer_nif:shutdown_registration().
shutdown_registration(Handle) ->
quicer_nif:shutdown_registration(Handle).

%% @doc Shutdown a registration with error code and silent flag.
-spec shutdown_registration(Handle, IsSilent, ErrCode) ->
quicer_nif:shutdown_registration(Handle, IsSilent, ErrCode).
-spec shutdown_registration(reg_handle(), boolean(), uint64()) ->
quicer_nif:shutdown_registration().
shutdown_registration(Handle, IsSilent, ErrCode) ->
quicer_nif:shutdown_registration(Handle, IsSilent, ErrCode).

%% @doc close a registration.
-spec close_registration(Handle) ->
quicer_nif:close_registration(Handle).
-spec close_registration(reg_handle()) ->
quicer_nif:close_registration().
close_registration(Handle) ->
quicer_nif:close_registration(Handle).

%% @doc get registration name
-spec get_registration_name(Handle) ->
quicer_nif:get_registration_name(Handle).
-spec get_registration_name(reg_handle()) ->
quicer_nif:get_registration_name().
get_registration_name(Handle) ->
quicer_nif:get_registration_name(Handle).

Expand Down Expand Up @@ -958,7 +957,7 @@ peername(Handle) ->
%% @doc Peer Cert in DER-encoded binary
%% mimic {@link ssl:peername/1}
-spec peercert(connection_handle() | stream_handle()) ->
{ok, Cert:: public_key:der_encoded()} | {error, any()}.
{ok, CertDerEncoded :: binary()} | {error, any()}.
peercert(Handle) ->
quicer_nif:peercert(Handle).

Expand All @@ -983,15 +982,15 @@ open_connection() ->

%% @doc list all listeners
-spec listeners() -> [{{ quicer_listener:listener_name()
, quicer_listener:listen_on()},
, quicer:listen_on()},
pid()}].
listeners() ->
quicer_listener_sup:listeners().

%% @doc List listener with app name
-spec listener(quicer_listener:listener_name()
| {quicer_listener:listener_name(),
quicer_listener:listen_on()}) -> {ok, pid()} | {error, not_found}.
quicer:listen_on()}) -> {ok, pid()} | {error, not_found}.
listener(Name) ->
quicer_listener_sup:listener(Name).

Expand All @@ -1001,7 +1000,7 @@ get_listeners() ->
quicer_nif:get_listeners().

%% @doc Get a list of listeners under registration handle
-spec get_listeners(Reg | global) -> quicer_nif:get_listeners(Reg).
-spec get_listeners(reg_handle() | global) -> quicer_nif:get_listeners().
get_listeners(global) ->
quicer_nif:get_listeners();
get_listeners(Reg) ->
Expand All @@ -1014,21 +1013,21 @@ get_connections() ->
quicer_nif:get_connections().

%% @doc Get a list of connections under registration handle
-spec get_connections(Reg | global) -> quicer_nif:get_connections(Reg).
-spec get_connections(reg_handle() | global) -> quicer_nif:get_connections().
get_connections(global) ->
quicer_nif:get_connections();
get_connections(Reg) ->
quicer_nif:get_connections(Reg).

-spec get_conn_owner(C) -> quicer_nif:get_conn_owner(C).
-spec get_conn_owner(connection_handle()) -> quicer_nif:get_owner().
get_conn_owner(Conn) ->
quicer_nif:get_conn_owner(Conn).

-spec get_stream_owner(S) -> quicer_nif:get_stream_owner(S).
-spec get_stream_owner(stream_handle()) -> quicer_nif:get_owner().
get_stream_owner(Stream) ->
quicer_nif:get_stream_owner(Stream).

-spec get_listener_owner(L) -> quicer_nif:get_listener_owner(L).
-spec get_listener_owner(listener_handle()) -> quicer_nif:get_owner().
get_listener_owner(Listener) ->
quicer_nif:get_listener_owner(Listener).

Expand Down
6 changes: 3 additions & 3 deletions src/quicer_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
, alpn :: [string()]
}).

-export_type([listener_name/0]).

-type listener_name() :: atom().
-type listen_on() :: inet:port_number() | string(). %% "127.0.0.1:8080"
-type listener_opts() :: map().

%%%===================================================================
%%% API
Expand All @@ -47,7 +47,7 @@
%% @end
%%--------------------------------------------------------------------
-spec start_link(Name :: listener_name(),
ListenOn :: listen_on(),
ListenOn :: quicer:listen_on(),
Options ::
{ quicer:listener_opts()
, quicer:conn_opts()
Expand Down
47 changes: 34 additions & 13 deletions src/quicer_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@
%% for test
-export([init/1]).


-export_type([ abi_version/0,
new_registration/0,
shutdown_registration/0,
close_registration/0,
get_registration_name/0,
get_listeners/0,
get_connections/0,
get_owner/0
]).

%% NIF fuction return types
-type abi_version() :: integer().
-type new_registration() :: {ok, reg_handle()} | {error, atom_reason()}.
-type shutdown_registration() :: ok | {error, badarg}.
-type close_registration() :: ok | {error, badarg}.
-type get_registration_name() :: {ok, string()} | {error, badarg}.
-type get_listeners() :: [listener_handle()].
-type get_connections() :: [connection_handle()].
-type get_owner() :: {ok, pid()} | {error, undefined | badarg}.


%% @NOTE: In embedded mode, first all modules are loaded. Then all on_load functions are called.
-on_load(init/0).

Expand All @@ -75,7 +97,7 @@
-include("quicer_types.hrl").
-include("quicer_vsn.hrl").

-spec abi_version() -> integer().
-spec abi_version() -> abi_version().
abi_version() ->
?QUICER_ABI_VERSION.

Expand Down Expand Up @@ -144,25 +166,24 @@ reg_close() ->
erlang:nif_error(nif_library_not_loaded).


-spec new_registration(Name::string(), registration_profile()) ->
{ok, reg_handle()} | {error, atom_reason()}.
-spec new_registration(Name::string(), Profile :: registration_profile()) -> new_registration().
new_registration(_Name, _Profile) ->
erlang:nif_error(nif_library_not_loaded).

-spec shutdown_registration(reg_handle()) -> ok | {error | badarg}.
-spec shutdown_registration(reg_handle()) -> shutdown_registration().
shutdown_registration(_Handle) ->
erlang:nif_error(nif_library_not_loaded).

-spec shutdown_registration(reg_handle(), IsSilent::boolean(), ErrorCode::uint64())
-> ok | {error | badarg}.
-> shutdown_registration().
shutdown_registration(_Handle, _IsSilent, _ErrorCode) ->
erlang:nif_error(nif_library_not_loaded).

-spec close_registration(reg_handle()) -> ok | {error | badarg}.
-spec close_registration(reg_handle()) -> close_registration().
close_registration(_Handle) ->
erlang:nif_error(nif_library_not_loaded).

-spec get_registration_name(reg_handle()) -> {ok, string()} | {error, badarg}.
-spec get_registration_name(reg_handle()) -> get_registration_name().
get_registration_name(_Handle) ->
erlang:nif_error(nif_library_not_loaded).

Expand Down Expand Up @@ -306,27 +327,27 @@ controlling_process(_H, _P) ->
erlang:nif_error(nif_library_not_loaded).

-spec peercert(connection_handle() | stream_handle()) ->
{ok, Cert :: public_key:der_encoded()} | {error, any()}.
{ok, CertDerEncoded :: binary()} | {error, any()}.
peercert(_Handle) ->
erlang:nif_error(nif_library_not_loaded).

-spec get_conn_owner(connection_handle()) -> {ok, pid()} | {error, undefined | badarg}.
-spec get_conn_owner(connection_handle()) -> get_owner().
get_conn_owner(_) ->
erlang:nif_error(nif_library_not_loaded).

-spec get_stream_owner(connection_handle()) -> {ok, pid()} | {error, undefined | badarg}.
-spec get_stream_owner(connection_handle()) -> get_owner().
get_stream_owner(_) ->
erlang:nif_error(nif_library_not_loaded).

-spec get_listener_owner(listener_handle()) -> {ok, pid()} | {error, undefined | badarg}.
-spec get_listener_owner(listener_handle()) -> get_owner().
get_listener_owner(_) ->
erlang:nif_error(nif_library_not_loaded).

-spec get_listeners() -> [listener_handle()].
-spec get_listeners() -> get_listeners().
get_listeners() ->
erlang:nif_error(nif_library_not_loaded).

-spec get_listeners(reg_handle()) -> [listener_handle()] | {error, badarg}.
-spec get_listeners(reg_handle()) -> get_listeners().
get_listeners(_) ->
erlang:nif_error(nif_library_not_loaded).

Expand Down

0 comments on commit dbb7262

Please sign in to comment.