tres/switch_registry: Fix to add handler for switch pid is not exist
This commit is contained in:
parent
697b7181a9
commit
acdb7ab4bb
2 changed files with 17 additions and 7 deletions
BIN
bin/enum_gen
BIN
bin/enum_gen
Binary file not shown.
|
|
@ -34,11 +34,9 @@ defmodule Tres.SwitchRegistry do
|
|||
end
|
||||
|
||||
def blocking_send_message(message, {_dpid, _aux_id} = datapath_id) do
|
||||
[{pid, _} | _] = Registry.lookup(__MODULE__, datapath_id)
|
||||
:gen_statem.call(pid, {:send_message, message}, 5000)
|
||||
catch
|
||||
:exit, {:timeout, _} ->
|
||||
{:error, :timeout}
|
||||
__MODULE__
|
||||
|> Registry.lookup(datapath_id)
|
||||
|> call({:send_message, message}, 5_000)
|
||||
end
|
||||
|
||||
def blocking_send_message(message, dpid) when is_binary(dpid) do
|
||||
|
|
@ -46,8 +44,9 @@ defmodule Tres.SwitchRegistry do
|
|||
end
|
||||
|
||||
def get_current_xid({_dpid, _aux_id} = datapath_id) do
|
||||
[{pid, _} | _] = Registry.lookup(__MODULE__, datapath_id)
|
||||
:gen_statem.call(pid, :get_xid, 1000)
|
||||
__MODULE__
|
||||
|> Registry.lookup(datapath_id)
|
||||
|> call(:get_xid, 1_000)
|
||||
end
|
||||
|
||||
def get_current_xid(datapath_id) do
|
||||
|
|
@ -62,6 +61,17 @@ defmodule Tres.SwitchRegistry do
|
|||
|
||||
# private function
|
||||
|
||||
defp call([{pid, _}|_], msg, timeout) do
|
||||
:gen_statem.call(pid, msg, timeout)
|
||||
catch
|
||||
:exit, {:timeout, _} ->
|
||||
{:error, :timeout}
|
||||
end
|
||||
|
||||
defp call(_, _, _) do
|
||||
{:error, :not_found}
|
||||
end
|
||||
|
||||
defp do_send_message(entries, message) do
|
||||
for {pid, _} <- entries, do: :gen_statem.cast(pid, {:send_message, message})
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue