Skip to content

Commit d76a7fc

Browse files
committed
Use new Erlang :erpc instead of :rpc
1 parent 420b9bc commit d76a7fc

File tree

6 files changed

+46
-29
lines changed

6 files changed

+46
-29
lines changed

lib/elixir/lib/kernel/cli.ex

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,23 +400,22 @@ defmodule Kernel.CLI do
400400
# Explicitly connect the node in case the rpc node was started with --sname/--name undefined.
401401
_ = :net_kernel.connect_node(node)
402402

403-
case :rpc.call(node, __MODULE__, :rpc_eval, [expr]) do
404-
:ok ->
405-
:ok
406-
407-
{:badrpc, {:EXIT, exit}} ->
408-
Process.exit(self(), exit)
409-
410-
{:badrpc, reason} ->
411-
if reason == :nodedown and :net_kernel.nodename() == :ignored do
403+
try do
404+
:erpc.call(node, __MODULE__, :rpc_eval, [expr])
405+
catch
406+
:error, {:erpc, reason} ->
407+
if reason == :noconnection and :net_kernel.nodename() == :ignored do
412408
{:error,
413409
"--rpc-eval : Cannot run --rpc-eval if the node is not alive (set --name or --sname)"}
414410
else
415411
{:error, "--rpc-eval : RPC failed with reason #{inspect(reason)}"}
416412
end
417413

418-
{kind, error, stack} ->
419-
:erlang.raise(kind, error, stack)
414+
:exit, {kind, exit} when kind in [:exception, :signal] ->
415+
Process.exit(self(), exit)
416+
else
417+
:ok -> :ok
418+
{kind, reason, stack} -> :erlang.raise(kind, reason, stack)
420419
end
421420
end
422421

lib/iex/lib/iex/autocomplete.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ defmodule IEx.Autocomplete do
2727
"""
2828
def remsh(node) do
2929
fn e ->
30-
case :rpc.call(node, IEx.Autocomplete, :expand, [e, IEx.Broker.shell()]) do
31-
{:badrpc, _} -> {:no, ~c"", []}
32-
r -> r
30+
try do
31+
:erpc.call(node, IEx.Autocomplete, :expand, [e, IEx.Broker.shell()])
32+
catch
33+
_, _ -> {:no, ~c"", []}
3334
end
3435
end
3536
end

lib/iex/lib/iex/broker.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,11 @@ defmodule IEx.Broker do
180180

181181
defp local_or_remote_shell() do
182182
Enum.find_value([node() | Node.list()], fn node ->
183-
server = :rpc.call(node, IEx.Broker, :shell, [])
184-
if is_pid(server), do: server
183+
try do
184+
:erpc.call(node, IEx.Broker, :shell, [])
185+
catch
186+
_, _ -> nil
187+
end
185188
end)
186189
end
187190
end

lib/iex/lib/iex/helpers.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,15 +1458,14 @@ defmodule IEx.Helpers do
14581458
def nl(nodes \\ Node.list(), module) when is_list(nodes) and is_atom(module) do
14591459
case get_beam_and_path(module) do
14601460
{bin, beam_path} ->
1461+
call = :erpc.multicall(nodes, :code, :load_binary, [module, beam_path, bin])
1462+
14611463
results =
1462-
for node <- nodes do
1463-
case :rpc.call(node, :code, :load_binary, [module, beam_path, bin]) do
1464-
{:module, _} -> {node, :loaded, module}
1465-
{:badrpc, message} -> {node, :badrpc, message}
1466-
{:error, message} -> {node, :error, message}
1467-
unexpected -> {node, :error, unexpected}
1468-
end
1469-
end
1464+
Enum.zip_with(nodes, call, fn
1465+
node, {:ok, {:module, _}} -> {node, :loaded, module}
1466+
node, {:ok, {:error, reason}} -> {node, :error, reason}
1467+
node, {:error, {:erpc, reason}} -> {node, :badrpc, reason}
1468+
end)
14701469

14711470
{:ok, results}
14721471

lib/iex/lib/iex/info.ex

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,11 @@ defimpl IEx.Info, for: PID do
346346

347347
def info(pid) do
348348
extra_info =
349-
case :rpc.pinfo(pid, @keys) do
349+
try do
350+
:erpc.call(node(pid), :erlang, :process_info, [pid, @keys])
351+
catch
352+
_, _ -> [{"Alive", false}]
353+
else
350354
[_ | _] = info ->
351355
[
352356
{"Alive", true},
@@ -382,11 +386,19 @@ end
382386

383387
defimpl IEx.Info, for: Port do
384388
def info(port) do
385-
connected = :rpc.call(node(port), :erlang, :port_info, [port, :connected])
389+
open? =
390+
try do
391+
:erpc.call(node(port), :erlang, :port_info, [port, :connected])
392+
catch
393+
_, _ -> false
394+
else
395+
{:connected, _} -> true
396+
_ -> false
397+
end
386398

387399
[
388400
{"Data type", "Port"},
389-
{"Open", match?({:connected, _}, connected)},
401+
{"Open", open?},
390402
{"Reference modules", "Port"}
391403
]
392404
end

lib/iex/test/iex/helpers_test.exs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,9 +1294,12 @@ defmodule IEx.HelpersTest do
12941294
@tag :capture_log
12951295
test "loads a given module on the given nodes" do
12961296
assert nl([node()], :lists) == {:ok, [{:nonode@nohost, :error, :sticky_directory}]}
1297-
assert nl(:nonexistent_module) == {:error, :nofile}
1298-
assert nl([:nosuchnode@badhost], Enum) == {:ok, [{:nosuchnode@badhost, :badrpc, :nodedown}]}
12991297
assert nl([node()], Enum) == {:ok, [{:nonode@nohost, :loaded, Enum}]}
1298+
1299+
assert nl(:nonexistent_module) == {:error, :nofile}
1300+
1301+
assert nl([:nosuchnode@badhost], Enum) ==
1302+
{:ok, [{:nosuchnode@badhost, :badrpc, :noconnection}]}
13001303
end
13011304
end
13021305

0 commit comments

Comments
 (0)