Skip to content

Commit ce8c342

Browse files
author
Kevin Smith
committed
Adding R14B02-style specs
1 parent d732113 commit ce8c342

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

rebar.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{erl_opts, [debug_info]}.

src/gen_nb_server.erl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,32 @@ behaviour_info(callbacks) ->
6363
behaviour_info(_) ->
6464
undefined.
6565

66-
%% @spec start_link(CallbackModule, InitParams) -> Result
67-
%% CallbackModule = atom()
68-
%% InitParams = [any()]
69-
%% Result = {ok, pid()} | {error, any()}
7066
%% @doc Start server listening on IpAddr:Port
67+
-spec start_link(atom(), [any()]) -> ok | ignore | {error, any()}.
7168
start_link(CallbackModule, InitParams) ->
7269
gen_server:start_link(?MODULE, [CallbackModule, InitParams], [{fullsweep_after, 0}]).
7370

74-
%% @spec start_link(Name, CallbackModule, InitParams) -> Result
75-
%% Name = {local, atom()} | {global, atom()}
76-
%% CallbackModule = atom()
77-
%% InitParams = [any()]
78-
%% Result = {ok, pid()} | {error, any()}
71+
7972
%% @doc Start server listening on IpAddr:Port registered as Name
73+
-spec start_link(atom(), atom(), [any()]) -> ok | ignore | {error, any()}.
8074
start_link(Name, CallbackModule, InitParams) ->
8175
gen_server:start_link(Name, ?MODULE, [CallbackModule, InitParams], [{fullsweep_after, 0}]).
8276

83-
%% @spec get_cb_state(#state{}) -> any()
8477
%% @doc Extracts the callback module's state from the server's overall state
8578
%% NOTE: Should only be called by the submodule
79+
-spec get_cb_state(#state{}) -> any().
8680
get_cb_state(#state{server_state=SState}) ->
8781
SState.
8882

89-
%% @spec store_cb_state(any(), #state{}) -> #state{}
9083
%% @doc Stores the callback module's state into the server's state
9184
%% NOTE: Should only be called by the submodule
85+
-spec store_cb_state(any(), #state{}) -> #state{}.
9286
store_cb_state(CBState, State) when is_record(State, state) ->
9387
State#state{server_state=CBState}.
9488

95-
%% @spec add_listen_socket({string(), integer()}, #state{}) -> {ok, #state{}} | {error, any()}
9689
%% @doc Adds a new listener socket to be managed by gen_nb_server
9790
%% NOTE: Should only be called by the submodule
91+
-spec add_listen_socket({string(), integer()}, #state{}) -> {ok, #state{}} | {error, any()}.
9892
add_listen_socket({IpAddr, Port}, #state{cb=Callback, addrs=Addrs, socks=Socks}=State) ->
9993
Key = {IpAddr, Port},
10094
case dict:find(Key, Socks) of
@@ -109,9 +103,10 @@ add_listen_socket({IpAddr, Port}, #state{cb=Callback, addrs=Addrs, socks=Socks}=
109103
Error
110104
end
111105
end.
112-
%% @spec remove_listen_socket({string(), integer()}, #state{}) -> {ok, #state{}} | {error, any()}
106+
113107
%% @doc Removes a new listener socket to be managed by gen_nb_server
114108
%% NOTE: Should only be called by the submodule
109+
-spec remove_listen_socket({string(), integer()}, #state{}) -> {error, not_listening} | {ok, #state{}}.
115110
remove_listen_socket({IpAddr, Port}, #state{socks=Socks, addrs=Addrs}=State) ->
116111
Key = {IpAddr, Port},
117112
case dict:find(Key, Socks) of
@@ -123,9 +118,8 @@ remove_listen_socket({IpAddr, Port}, #state{socks=Socks, addrs=Addrs}=State) ->
123118
addrs=dict:erase(Sock, Addrs)}}
124119
end.
125120

126-
%% @spec init(#state{}) -> Result
127-
%% Result = any()
128121
%% @doc Returns the callback module's state
122+
-spec init([atom()|any()]) -> {ok, #state{}} | {error, bad_init_state} | {error, any()}.
129123
init([CallbackModule, InitParams]) ->
130124
process_flag(trap_exit, true),
131125
State = #state{cb=CallbackModule},

0 commit comments

Comments
 (0)