Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Support both PID_EXT and NEW_PID_EXT simultaneously #317

Merged
merged 1 commit into from Apr 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 10 additions & 18 deletions src/rabbit_misc.erl
Expand Up @@ -706,31 +706,23 @@ pid_change_node(Pid, NewNode) ->
node_to_fake_pid(Node) ->
compose_pid(Node, 0, 0, 0).

-define(HAS_NEW_PID_EXT, false).
-ifdef(OTP_RELEASE).
-if(?OTP_RELEASE >= 22).
-undef(HAS_NEW_PID_EXT).
-define(HAS_NEW_PID_EXT, true).
-endif.
-endif.

decompose_pid(Pid) when is_pid(Pid) ->
%% see http://erlang.org/doc/apps/erts/erl_ext_dist.html (8.10 and
%% 8.7)
Node = node(Pid),
BinPid = term_to_binary(Pid),
ByteSize = byte_size(BinPid),
case ?HAS_NEW_PID_EXT of
true ->
NodeByteSize = (ByteSize - 14),
<<131, 88, _NodePrefix:NodeByteSize/binary, Id:32, Ser:32, Cre:32>> = BinPid,
BinPid0 = term_to_binary(Pid),
case BinPid0 of
%% NEW_PID_EXT
<<131, 88, BinPid/bits>> ->
NodeByteSize = byte_size(BinPid0) - 14,
<<_NodePrefix:NodeByteSize/binary, Id:32, Ser:32, Cre:32>> = BinPid,
{Node, Cre, Id, Ser};
false ->
NodeByteSize = (ByteSize - 11),
<<131, 103, _NodePrefix:NodeByteSize/binary, Id:32, Ser:32, Cre:8>> = BinPid,
%% PID_EXT
<<131, 103, BinPid/bits>> ->
NodeByteSize = byte_size(BinPid0) - 11,
<<_NodePrefix:NodeByteSize/binary, Id:32, Ser:32, Cre:8>> = BinPid,
{Node, Cre, Id, Ser}
end.
-dialyzer({no_match, decompose_pid/1}).

compose_pid(Node, Cre, Id, Ser) ->
<<131,NodeEnc/binary>> = term_to_binary(Node),
Expand Down