Packages
otpbp
7.4.0
7.18.0
7.16.1
7.15.0
7.14.0
7.13.0
7.12.0
7.11.0
7.10.2
7.9.3
7.9.2
7.9.1
7.8.7
7.8.6
7.8.5
7.8.4
7.7.1
7.7.0
7.6.3
7.6.2
7.6.1
7.6.0
7.5.1
7.5.0
7.4.0
7.3.4
7.3.3
7.3.2
7.3.1
7.3.0
7.2.0
7.1.1
7.1.0
7.0.4
7.0.3
7.0.2
7.0.1
6.26.0
6.25.0
6.24.0
6.23.0
6.22.2
6.21.3
6.21.2
6.21.1
6.20.2
6.19.1
6.19.0
6.18.3
6.18.2
6.18.1
6.18.0
6.17.1
6.17.0
6.16.0
6.15.4
6.15.3
6.15.2
6.15.1
6.15.0
6.14.0
6.13.5
6.13.4
6.13.3
6.13.2
6.13.1
6.13.0
6.12.0
6.11.2
6.11.1
6.10.0
6.9.2
6.9.1
6.9.0
6.8.0
6.7.1
6.7.0
6.6.4
6.6.3
6.6.2
6.6.1
6.6.0
6.5.0
6.4.0
6.3.3
6.3.2
6.3.1
6.3.0
6.2.1
6.2.0
6.1.0
6.0.0
5.39.0
5.38.0
5.37.0
5.36.0
5.35.2
5.34.3
5.34.2
5.34.1
5.33.1
5.32.1
5.32.0
5.31.3
5.31.2
5.31.1
5.31.0
5.30.1
5.30.0
5.29.0
5.28.4
5.28.3
5.28.2
5.28.1
5.28.0
5.27.0
5.26.5
5.26.4
5.26.3
5.26.2
5.26.1
5.26.0
5.25.0
5.24.2
5.24.1
5.23.0
5.22.2
5.22.1
5.22.0
5.21.0
5.20.1
5.20.0
5.19.4
5.19.3
5.19.2
5.19.1
5.19.0
5.18.0
5.17.0
5.16.3
5.16.1
5.16.0
5.15.1
5.15.0
5.14.0
5.13.1
5.13.0
5.12.1
5.12.0
5.11.2
5.11.1
5.10.1
5.10.0
5.9.0
5.8.0
5.7.0
5.6.1
5.6.0
5.5.0
5.4.2
5.4.1
5.4.0
5.3.0
5.2.2
5.2.1
5.2.0
5.1.2
5.1.1
4.79.0
4.78.0
4.77.0
4.76.2
4.75.3
4.75.2
4.75.1
4.74.0
4.73.1
4.73.0
4.72.3
4.72.2
4.72.1
4.72.0
4.71.1
4.71.0
4.70.0
4.69.4
4.69.3
4.69.2
4.69.1
4.69.0
4.68.0
4.67.5
4.67.4
4.67.3
4.67.2
4.67.0
4.66.0
4.65.2
4.65.1
4.64.0
4.63.2
4.63.1
4.63.0
4.62.0
4.61.1
4.61.0
4.60.4
4.60.3
4.60.2
4.60.1
4.60.0
4.59.0
4.58.0
4.57.2
4.57.1
4.57.0
4.56.2
4.56.1
4.56.0
4.55.0
4.54.0
4.53.0
4.52.1
4.52.0
4.51.3
4.51.2
4.51.0
4.50.0
4.49.3
4.49.2
OTP backports
Current section
Files
Jump to
Current section
Files
src/otpbp_erpc.erl
-module(otpbp_erpc).
-ifdef(HAVE_erlang__spawn_request_abandon_1).
-ifndef(HAVE_erpc__check_response_3).
% OTP 25.0
-export([check_response/3]).
-endif.
-ifndef(HAVE_erpc__receive_response_3).
% OTP 25.0
-export([receive_response/3]).
-endif.
-ifndef(HAVE_erpc__reqids_add_3).
% OTP 25.0
-export([reqids_add/3]).
-endif.
-ifndef(HAVE_erpc__reqids_size_1).
% OTP 25.0
-export([reqids_size/1]).
-endif.
-ifndef(HAVE_erpc__reqids_to_list_1).
% OTP 25.0
-export([reqids_to_list/1]).
-endif.
-ifndef(HAVE_erpc__send_request_6).
% OTP 25.0
-export([send_request/6]).
-endif.
-ifndef(HAVE_erpc__wait_response_3).
% OTP 25.0
-export([wait_response/3]).
-endif.
-compile({parse_transform, otpbp_pt}).
-ifndef(HAVE_erpc__check_response_3).
check_response(_Msg, ReqIdCol, Del) when map_size(ReqIdCol) =:= 0, is_boolean(Del) -> no_request;
check_response({spawn_reply, ReqId, error, Reason}, ReqIdCol, Del)
when is_reference(ReqId), is_map_key(ReqId, ReqIdCol), is_boolean(Del) ->
collection_result(spawn_reply, ReqId, Reason, ReqIdCol, true, Del);
check_response({'DOWN', ReqId, process, _Pid, Reason}, ReqIdCol, Del)
when is_reference(ReqId), is_map_key(ReqId, ReqIdCol), is_boolean(Del) ->
collection_result(down, ReqId, Reason, ReqIdCol, true, Del);
check_response(_Msg, ReqIdCol, Del) ->
is_map(ReqIdCol) andalso is_boolean(Del) orelse error({erpc, badarg}),
no_response.
-ifndef(NEED_collection_result_6).
-define(NEED_collection_result_6, true).
-endif.
-endif.
-ifndef(HAVE_erpc__receive_response_3).
receive_response(ReqIdCol, WT, Del) when map_size(ReqIdCol) =:= 0, is_boolean(Del) ->
_ = timeout_value(WT),
no_request;
receive_response(ReqIdCol, Tmo, Del) when is_map(ReqIdCol), is_boolean(Del) ->
Timeout = timeout_value(Tmo),
receive
{spawn_reply, ReqId, error, Reason} when is_map_key(ReqId, ReqIdCol), is_reference(ReqId) ->
collection_result(spawn_reply, ReqId, Reason, ReqIdCol, false, Del);
{'DOWN', ReqId, process, _Pid, Reason} when is_map_key(ReqId, ReqIdCol), is_reference(ReqId) ->
collection_result(down, ReqId, Reason, ReqIdCol, false, Del)
after Timeout ->
try
maps:foreach(fun abandon/2, ReqIdCol)
catch
throw:badarg -> error({erpc, badarg})
end,
error({erpc, timeout})
end;
receive_response(_, _, _) -> error({erpc, badarg}).
abandon(ReqId, [Res|_Label]) when is_reference(ReqId), is_reference(Res) ->
spawn_request_abandon(ReqId) orelse demonitor(ReqId, [info]) orelse
receive
{spawn_reply, ReqId, error, _} -> ok;
{'DOWN', ReqId, process, _, _} -> ok
after 0 -> ok
end;
abandon(_, _) -> throw(badarg).
-ifndef(NEED_timeout_value_1).
-define(NEED_timeout_value_1, true).
-endif.
-ifndef(NEED_collection_result_6).
-define(NEED_collection_result_6, true).
-endif.
-endif.
-ifndef(HAVE_erpc__reqids_add_3).
reqids_add([Res|ReqId], Label, ReqIdCollection)
when is_reference(Res), is_reference(ReqId), not is_map_key(ReqId, ReqIdCollection) ->
ReqIdCollection#{ReqId => [Res|Label]};
reqids_add(_, _, _) -> error({erpc, badarg}).
-endif.
-ifndef(HAVE_erpc__reqids_size_1).
reqids_size(ReqIdCollection) ->
try
maps:size(ReqIdCollection)
catch
_:_ -> error({erpc, badarg})
end.
-endif.
-ifndef(HAVE_erpc__reqids_to_list_1).
reqids_to_list(ReqIdCollection) when is_map(ReqIdCollection) ->
try
maps:fold(fun(ReqId, [Res|Label], Acc) when is_reference(ReqId), is_reference(Res) -> [{[Res|ReqId], Label}|Acc];
(_, _, _) -> throw(badarg)
end,
[], ReqIdCollection)
catch
throw:badarg -> error({erpc, badarg})
end;
reqids_to_list(_) -> error({erpc, badarg}).
-endif.
-ifndef(HAVE_erpc__wait_response_3).
wait_response(ReqIdCol, WT, Del) when map_size(ReqIdCol) =:= 0, is_boolean(Del) ->
_ = timeout_value(WT),
no_request;
wait_response(ReqIdCol, WT, Del) when is_map(ReqIdCol), is_boolean(Del) ->
Timeout = timeout_value(WT),
receive
{spawn_reply, ReqId, error, Reason} when is_map_key(ReqId, ReqIdCol), is_reference(ReqId) ->
collection_result(spawn_reply, ReqId, Reason, ReqIdCol, true, Del);
{'DOWN', ReqId, process, _Pid, Reason} when is_map_key(ReqId, ReqIdCol), is_reference(ReqId) ->
collection_result(down, ReqId, Reason, ReqIdCol, true, Del)
after Timeout -> no_response
end;
wait_response(_, _, _) -> error({erpc, badarg}).
-ifndef(NEED_timeout_value_1).
-define(NEED_timeout_value_1, true).
-endif.
-ifndef(NEED_collection_result_6).
-define(NEED_collection_result_6, true).
-endif.
-endif.
-ifndef(HAVE_erpc__send_request_6).
send_request(N, M, F, A, L, C) when is_atom(N), is_atom(M), is_atom(F), is_list(A), is_map(C) ->
Res = make_ref(),
C#{spawn_request(N, erpc, execute_call, [Res, M, F, A], [{reply, error_only}, monitor]) => [Res|L]};
send_request(_N, _M, _F, _A, _L, _C) -> error({erpc, badarg}).
-endif.
-ifdef(NEED_collection_result_6).
collection_result(Type, ReqId, ResultReason, ReqIdCol, WrapResponse, Delete) ->
case reqid(ReqId, ReqIdCol, Delete) of
{[Res|Label], NewReqIdCol} when is_reference(Res) ->
try result(Type, ReqId, Res, ResultReason) of
Result -> {wrap(WrapResponse, Result), Label, NewReqIdCol}
catch
Class:Reason -> erlang:Class({Reason, Label, NewReqIdCol})
end;
_ -> error({erpc, badarg})
end.
-compile({inline, wrap/2}).
wrap(true, R) -> {response, R};
wrap(_false, R) -> R.
-compile({inline, reqid/3}).
reqid(ReqId, ReqIdCol, true) -> maps:take(ReqId, ReqIdCol);
reqid(ReqId, ReqIdCol, false) -> {maps:get(ReqId, ReqIdCol), ReqIdCol}.
-compile({inline, result/4}).
result(down, _ReqId, Res, {Res, return, Return}) -> Return;
result(down, _ReqId, Res, {Res, throw, Throw}) -> throw(Throw);
result(down, _ReqId, Res, {Res, exit, Exit}) -> exit({exception, Exit});
result(down, _ReqId, Res, {Res, error, Error, Stack}) -> error({exception, Error, Stack});
result(down, _ReqId, Res, {Res, error, {erpc, _} = ErpcErr}) -> error(ErpcErr);
result(down, _ReqId, _Res, noconnection) -> error({erpc, noconnection});
result(down, _ReqId, _Res, Reason) -> exit({signal, Reason});
result(spawn_reply, _ReqId, _Res, Reason) -> error({erpc, Reason}).
-endif.
-ifdef(NEED_timeout_value_1).
-define(MAX_INT_TIMEOUT, 4294967295).
timeout_value({abs, Timeout}) when is_integer(Timeout) ->
if
Timeout >= 0, Timeout =< ?MAX_INT_TIMEOUT -> Timeout;
true ->
case Timeout - erlang:monotonic_time(millisecond) of
TMO when TMO > ?MAX_INT_TIMEOUT -> error({erpc, badarg});
TMO -> max(TMO, 0)
end
end;
timeout_value(Timeout) ->
Timeout =:= infinity orelse error({erpc, badarg}),
Timeout.
-endif.
-endif.