diff --git a/src/hanoi_level.erl b/src/hanoi_level.erl index 415f7d5..38500a9 100644 --- a/src/hanoi_level.erl +++ b/src/hanoi_level.erl @@ -105,7 +105,7 @@ unmerged_count(Ref) -> plain_rpc:call(Ref, unmerged_count). set_max_level(Ref, LevelNo) -> - plain_rpc:send_cast(Ref, {set_max_level, LevelNo}). + plain_rpc:cast(Ref, {set_max_level, LevelNo}). close(Ref) -> try diff --git a/src/plain_rpc.erl b/src/plain_rpc.erl index e50d7a5..4a083a0 100644 --- a/src/plain_rpc.erl +++ b/src/plain_rpc.erl @@ -22,7 +22,7 @@ -module(plain_rpc). -author('Kresten Krab Thorup '). --export([send_call/2, receive_reply/1, send_reply/2, call/2, send_cast/2]). +-export([send_call/2, receive_reply/1, send_reply/2, call/2, call/3, cast/2]). -include("include/plain_rpc.hrl"). @@ -32,7 +32,7 @@ send_call(PID, Request) -> PID ! ?CALL({self(), Ref}, Request), Ref. -send_cast(PID, Msg) -> +cast(PID, Msg) -> PID ! ?CAST(self(), Msg). receive_reply(MRef) -> @@ -40,8 +40,8 @@ receive_reply(MRef) -> ?REPLY(MRef, Reply) -> erlang:demonitor(MRef, [flush]), Reply; - {'DOWN', MRef, _, _, Reason} -> - exit(Reason) + {'DOWN', MRef, _, _, Reason} -> + exit(Reason) end. send_reply({PID,Ref}, Reply) -> @@ -49,6 +49,9 @@ send_reply({PID,Ref}, Reply) -> ok. call(PID,Request) -> + call(PID, Request, infinity). + +call(PID,Request,Timeout) -> MRef = erlang:monitor(process, PID), PID ! ?CALL({self(), MRef}, Request), receive @@ -57,9 +60,9 @@ call(PID,Request) -> Reply; {'DOWN', MRef, _, _, Reason} -> exit(Reason) -% after 3000 -> -% erlang:demonitor(MRef, [flush]), -% exit({rpc_timeout, Request}) + after Timeout -> + erlang:demonitor(MRef, [flush]), + exit({rpc_timeout, Request}) end.