Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/nksip_call_srv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
-behaviour(gen_server).

-export([start/2, stop/1, sync_work/5, async_work/2]).
-export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,
-export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,
code_change/3]).
-export([get_data/1, find_call/2, get_all/0]).

Expand Down Expand Up @@ -82,12 +82,7 @@ get_data(Pid) ->
pid() | undefined.

find_call(SrvId, CallId) ->
case nklib_proc:values({?MODULE, SrvId, CallId}) of
[{_, Pid}] when is_pid(Pid) ->
Pid;
_ ->
undefined
end.
validate_process(nklib_proc:values({?MODULE, SrvId, CallId})).


%% @private Get all started calls (dangerous in production with many calls)
Expand All @@ -104,15 +99,27 @@ get_all() ->
nklib_proc:fold_names(Fun, []).


%% @private Validate if given Pid is alive process
-spec validate_process(list()) ->
pid() | undefined.

validate_process([{_, Pid}]) when is_pid(Pid) ->
case is_process_alive(Pid) of
true ->
Pid;
false ->
undefined
end;
validate_process(_) ->
undefined.


%% ===================================================================
%% gen_server
%% ===================================================================


%% @private
%% @private
-spec init(term()) ->
{ok, call()}.

Expand All @@ -125,7 +132,7 @@ init([SrvId, CallId]) ->
Call = #call{
srv_id = SrvId,
srv_ref = monitor(process, whereis(SrvId)),
call_id = CallId,
call_id = CallId,
next = Id+1,
hibernate = false,
trans = [],
Expand All @@ -150,7 +157,7 @@ init([SrvId, CallId]) ->
handle_call(get_data, _From, Call) ->
#call{trans=Trans, forks=Forks, dialogs=Dialogs} = Call,
{reply, {Trans, Forks, Dialogs}, Call};

handle_call(Msg, _From, Call) ->
lager:error("Module ~p received unexpected sync event: ~p", [?MODULE, Msg]),
{noreply, Call}.
Expand Down Expand Up @@ -201,7 +208,7 @@ handle_info(Info, Call) ->
-spec code_change(term(), call(), term()) ->
{ok, call()}.

code_change(_OldVsn, Call, _Extra) ->
code_change(_OldVsn, Call, _Extra) ->
{ok, Call}.


Expand All @@ -223,26 +230,19 @@ terminate(_Reason, #call{srv_id=_SrvId, call_id =_CallId}=Call) ->
-spec next(call()) ->
{noreply, call()} | {stop, normal, call()}.

next(#call{trans=[], forks=[], dialogs=[], events=[]}=Call) ->
next(#call{trans=[], forks=[], dialogs=[], events=[]}=Call) ->
case erlang:process_info(self(), message_queue_len) of
{_, 0} ->
{_, 0} ->
{stop, normal, Call};
_ ->
_ ->
{noreply, Call}
end;

next(#call{hibernate=Hibernate}=Call) ->
next(#call{hibernate=Hibernate}=Call) ->
case Hibernate of
false ->
{noreply, Call};
_ ->
?CALL_DEBUG("hibernating: ~p", [Hibernate], Call),
{noreply, Call#call{hibernate=false}, hibernate}
end.







16 changes: 9 additions & 7 deletions src/nksip_uac.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
%%
%% In case of using a SIP URI as destination, is is possible to include
%% custom headers: `"<sip:host;method=REGISTER?contact=*&expires=10>"'
%%
%%
-module(nksip_uac).
-author('Carlos Gonzalez <carlosj.gf@gmail.com>').

Expand All @@ -44,9 +44,9 @@
%% ===================================================================


-type uac_result() ::
-type uac_result() ::
{ok, nksip:sip_code(), nksip:resp_options()} | {async, nksip:handle()} | {error, term()}.

-type uac_ack_result() ::
ok | async | {error, term()}.

Expand All @@ -66,6 +66,7 @@
allow |
accept |
allow_event |
contact |

% Special parameters
to_as_from |
Expand Down Expand Up @@ -93,6 +94,7 @@
% Publish
{sip_if_match, binary()} |

async |
no_dialog |
stateless_via |

Expand Down Expand Up @@ -403,9 +405,9 @@ refresh(Handle, Opts) ->

%% @doc Sends a <i>STUN</i> binding request.
%%
%% Use this function to send a STUN binding request to a remote STUN or
%% Use this function to send a STUN binding request to a remote STUN or
%% STUN-enabled SIP server, in order to get our external ip and port.
%% If the remote server is a standard STUN server, use port 3478
%% If the remote server is a standard STUN server, use port 3478
%% (i.e. `sip:stunserver.org:3478'). If it is a STUN server embedded into a SIP UDP
%% server, use a standard SIP uri.
%%
Expand Down Expand Up @@ -485,7 +487,7 @@ send(SrvId, Method, Uri, Opts) ->
send_dialog(Method, Handle, Opts) ->
case nksip_dialog:get_handle(Handle) of
{ok, DlgHandle} ->
Opts1 = case Handle of
Opts1 = case Handle of
<<$U, $_, _/binary>>=SubsHandle ->
[{subscription, SubsHandle}|Opts];
_ ->
Expand All @@ -505,7 +507,7 @@ send_dialog(Method, Handle, Opts) ->
%% @private
-spec send_cancel(nksip:handle(), [req_option()]) ->
uac_ack_result().

send_cancel(Handle, Opts) ->
case nksip_sipmsg:parse_handle(Handle) of
{req, SrvId, ReqId, CallId} ->
Expand Down