diff --git a/src/gen_ipc.erl b/src/gen_ipc.erl index 8d66413..609a0b0 100644 --- a/src/gen_ipc.erl +++ b/src/gen_ipc.erl @@ -10,7 +10,7 @@ start/3, start/4, start_link/3, start_link/4 , start_monitor/3, start_monitor/4 , stop/1, stop/3 - , cast/2 + , cast/2, send/2 , abcast/2, abcast/3 , call/2, call/3 , send_request/2, wait_response/1, wait_response/2, check_response/2 @@ -640,6 +640,28 @@ cast(Dest, Msg) -> catch _:_ -> ok end. +-spec send(ServerRef :: serverRef(), Msg :: term()) -> ok. +send({global, Name}, Msg) -> + try global:send(Name, Msg), + ok + catch _:_ -> ok + end; +send({via, RegMod, Name}, Msg) -> + try RegMod:send(Name, Msg), + ok + catch _:_ -> ok + end; +send({Name, Node} = Dest, Msg) when is_atom(Name), is_atom(Node) -> + try erlang:send(Dest, Msg), + ok + catch _:_ -> ok + end; +send(Dest, Msg) -> + try erlang:send(Dest, Msg), + ok + catch _:_ -> ok + end. + %% 异步广播,不返回任何内容,只是发送“ n”祈祷 abcast(Name, Msg) when is_atom(Name) -> doAbcast([node() | nodes()], Name, Msg). diff --git a/src/gen_srv.erl b/src/gen_srv.erl index 503a04c..a74c7b8 100644 --- a/src/gen_srv.erl +++ b/src/gen_srv.erl @@ -12,7 +12,7 @@ , stop/1, stop/3 , call/2, call/3 , send_request/2, wait_response/2, check_response/2 - , cast/2, reply/1, reply/2 + , cast/2, send/2, reply/1, reply/2 , abcast/2, abcast/3 , multi_call/2, multi_call/3, multi_call/4 , enter_loop/3, enter_loop/4, enter_loop/5 @@ -466,6 +466,29 @@ cast(Dest, Msg) -> catch _:_ -> ok end. +-spec send(ServerRef :: serverRef(), Msg :: term()) -> ok. +send({global, Name}, Msg) -> + try global:send(Name, Msg), + ok + catch _:_ -> ok + end; +send({via, RegMod, Name}, Msg) -> + try RegMod:send(Name, Msg), + ok + catch _:_ -> ok + end; +send({Name, Node} = Dest, Msg) when is_atom(Name), is_atom(Node) -> + try erlang:send(Dest, Msg), + ok + catch _:_ -> ok + end; +send(Dest, Msg) -> + try erlang:send(Dest, Msg), + ok + catch _:_ -> ok + end. + + %% 异步广播,不返回任何内容,只是发送“ n”祈祷 abcast(Name, Msg) when is_atom(Name) -> doAbcast([node() | nodes()], Name, Msg).