Permalink
Browse files

Adding R14B02-style specs

  • Loading branch information...
1 parent d732113 commit ce8c342cb82b33368a6bc37893db116fd7d1f543 @kevsmith committed Mar 18, 2011
Showing with 10 additions and 15 deletions.
  1. +1 −0 rebar.config
  2. +9 −15 src/gen_nb_server.erl
View
@@ -0,0 +1 @@
+{erl_opts, [debug_info]}.
View
@@ -63,38 +63,32 @@ behaviour_info(callbacks) ->
behaviour_info(_) ->
undefined.
-%% @spec start_link(CallbackModule, InitParams) -> Result
-%% CallbackModule = atom()
-%% InitParams = [any()]
-%% Result = {ok, pid()} | {error, any()}
%% @doc Start server listening on IpAddr:Port
+-spec start_link(atom(), [any()]) -> ok | ignore | {error, any()}.
start_link(CallbackModule, InitParams) ->
gen_server:start_link(?MODULE, [CallbackModule, InitParams], [{fullsweep_after, 0}]).
-%% @spec start_link(Name, CallbackModule, InitParams) -> Result
-%% Name = {local, atom()} | {global, atom()}
-%% CallbackModule = atom()
-%% InitParams = [any()]
-%% Result = {ok, pid()} | {error, any()}
+
%% @doc Start server listening on IpAddr:Port registered as Name
+-spec start_link(atom(), atom(), [any()]) -> ok | ignore | {error, any()}.
start_link(Name, CallbackModule, InitParams) ->
gen_server:start_link(Name, ?MODULE, [CallbackModule, InitParams], [{fullsweep_after, 0}]).
-%% @spec get_cb_state(#state{}) -> any()
%% @doc Extracts the callback module's state from the server's overall state
%% NOTE: Should only be called by the submodule
+-spec get_cb_state(#state{}) -> any().
get_cb_state(#state{server_state=SState}) ->
SState.
-%% @spec store_cb_state(any(), #state{}) -> #state{}
%% @doc Stores the callback module's state into the server's state
%% NOTE: Should only be called by the submodule
+-spec store_cb_state(any(), #state{}) -> #state{}.
store_cb_state(CBState, State) when is_record(State, state) ->
State#state{server_state=CBState}.
-%% @spec add_listen_socket({string(), integer()}, #state{}) -> {ok, #state{}} | {error, any()}
%% @doc Adds a new listener socket to be managed by gen_nb_server
%% NOTE: Should only be called by the submodule
+-spec add_listen_socket({string(), integer()}, #state{}) -> {ok, #state{}} | {error, any()}.
add_listen_socket({IpAddr, Port}, #state{cb=Callback, addrs=Addrs, socks=Socks}=State) ->
Key = {IpAddr, Port},
case dict:find(Key, Socks) of
@@ -109,9 +103,10 @@ add_listen_socket({IpAddr, Port}, #state{cb=Callback, addrs=Addrs, socks=Socks}=
Error
end
end.
-%% @spec remove_listen_socket({string(), integer()}, #state{}) -> {ok, #state{}} | {error, any()}
+
%% @doc Removes a new listener socket to be managed by gen_nb_server
%% NOTE: Should only be called by the submodule
+-spec remove_listen_socket({string(), integer()}, #state{}) -> {error, not_listening} | {ok, #state{}}.
remove_listen_socket({IpAddr, Port}, #state{socks=Socks, addrs=Addrs}=State) ->
Key = {IpAddr, Port},
case dict:find(Key, Socks) of
@@ -123,9 +118,8 @@ remove_listen_socket({IpAddr, Port}, #state{socks=Socks, addrs=Addrs}=State) ->
addrs=dict:erase(Sock, Addrs)}}
end.
-%% @spec init(#state{}) -> Result
-%% Result = any()
%% @doc Returns the callback module's state
+-spec init([atom()|any()]) -> {ok, #state{}} | {error, bad_init_state} | {error, any()}.
init([CallbackModule, InitParams]) ->
process_flag(trap_exit, true),
State = #state{cb=CallbackModule},

0 comments on commit ce8c342

Please sign in to comment.