@@ -63,38 +63,32 @@ behaviour_info(callbacks) ->
63
63
behaviour_info (_ ) ->
64
64
undefined .
65
65
66
- % % @spec start_link(CallbackModule, InitParams) -> Result
67
- % % CallbackModule = atom()
68
- % % InitParams = [any()]
69
- % % Result = {ok, pid()} | {error, any()}
70
66
% % @doc Start server listening on IpAddr:Port
67
+ -spec start_link (atom (), [any ()]) -> ok | ignore | {error , any ()}.
71
68
start_link (CallbackModule , InitParams ) ->
72
69
gen_server :start_link (? MODULE , [CallbackModule , InitParams ], [{fullsweep_after , 0 }]).
73
70
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
+
79
72
% % @doc Start server listening on IpAddr:Port registered as Name
73
+ -spec start_link (atom (), atom (), [any ()]) -> ok | ignore | {error , any ()}.
80
74
start_link (Name , CallbackModule , InitParams ) ->
81
75
gen_server :start_link (Name , ? MODULE , [CallbackModule , InitParams ], [{fullsweep_after , 0 }]).
82
76
83
- % % @spec get_cb_state(#state{}) -> any()
84
77
% % @doc Extracts the callback module's state from the server's overall state
85
78
% % NOTE: Should only be called by the submodule
79
+ -spec get_cb_state (# state {}) -> any ().
86
80
get_cb_state (# state {server_state = SState }) ->
87
81
SState .
88
82
89
- % % @spec store_cb_state(any(), #state{}) -> #state{}
90
83
% % @doc Stores the callback module's state into the server's state
91
84
% % NOTE: Should only be called by the submodule
85
+ -spec store_cb_state (any (), # state {}) -> # state {}.
92
86
store_cb_state (CBState , State ) when is_record (State , state ) ->
93
87
State # state {server_state = CBState }.
94
88
95
- % % @spec add_listen_socket({string(), integer()}, #state{}) -> {ok, #state{}} | {error, any()}
96
89
% % @doc Adds a new listener socket to be managed by gen_nb_server
97
90
% % NOTE: Should only be called by the submodule
91
+ -spec add_listen_socket ({string (), integer ()}, # state {}) -> {ok , # state {}} | {error , any ()}.
98
92
add_listen_socket ({IpAddr , Port }, # state {cb = Callback , addrs = Addrs , socks = Socks }= State ) ->
99
93
Key = {IpAddr , Port },
100
94
case dict :find (Key , Socks ) of
@@ -109,9 +103,10 @@ add_listen_socket({IpAddr, Port}, #state{cb=Callback, addrs=Addrs, socks=Socks}=
109
103
Error
110
104
end
111
105
end .
112
- % % @spec remove_listen_socket({string(), integer()}, #state{}) -> {ok, #state{}} | {error, any()}
106
+
113
107
% % @doc Removes a new listener socket to be managed by gen_nb_server
114
108
% % NOTE: Should only be called by the submodule
109
+ -spec remove_listen_socket ({string (), integer ()}, # state {}) -> {error , not_listening } | {ok , # state {}}.
115
110
remove_listen_socket ({IpAddr , Port }, # state {socks = Socks , addrs = Addrs }= State ) ->
116
111
Key = {IpAddr , Port },
117
112
case dict :find (Key , Socks ) of
@@ -123,9 +118,8 @@ remove_listen_socket({IpAddr, Port}, #state{socks=Socks, addrs=Addrs}=State) ->
123
118
addrs = dict :erase (Sock , Addrs )}}
124
119
end .
125
120
126
- % % @spec init(#state{}) -> Result
127
- % % Result = any()
128
121
% % @doc Returns the callback module's state
122
+ -spec init ([atom ()|any ()]) -> {ok , # state {}} | {error , bad_init_state } | {error , any ()}.
129
123
init ([CallbackModule , InitParams ]) ->
130
124
process_flag (trap_exit , true ),
131
125
State = # state {cb = CallbackModule },
0 commit comments