.TH rpc 3erl "kernel 6.2" "Ericsson AB" "Erlang Module Definition" .SH NAME rpc \- Remote Procedure Call services. .SH DESCRIPTION .LP This module contains services similar to Remote Procedure Calls\&. It also contains broadcast facilities and parallel evaluators\&. A remote procedure call is a method to call a function on a remote node and collect the answer\&. It is used for collecting information on a remote node, or for running a function with some specific side effects on the remote node\&. .SH DATA TYPES .nf \fBkey()\fR\& .br .fi .RS .LP As returned by \fB\fIasync_call/4\fR\&\fR\&\&. .RE .SH EXPORTS .LP .nf .B abcast(Name, Msg) -> abcast .br .fi .br .RS .LP Types: .RS 3 Name = atom() .br Msg = term() .br .RE .RE .RS .LP Equivalent to \fIabcast([node()|nodes()], Name, Msg)\fR\&\&. .RE .LP .nf .B abcast(Nodes, Name, Msg) -> abcast .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Name = atom() .br Msg = term() .br .RE .RE .RS .LP Broadcasts the message \fIMsg\fR\& asynchronously to the registered process \fIName\fR\& on the specified nodes\&. .RE .LP .nf .B async_call(Node, Module, Function, Args) -> Key .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Key = \fBkey()\fR\& .br .RE .RE .RS .LP Implements \fIcall streams with promises\fR\&, a type of RPC that does not suspend the caller until the result is finished\&. Instead, a key is returned, which can be used later to collect the value\&. The key can be viewed as a promise to deliver the answer\&. .LP In this case, the key \fIKey\fR\& is returned, which can be used in a subsequent call to \fB\fIyield/1\fR\&\fR\& or \fB\fInb_yield/1,2\fR\&\fR\& to retrieve the value of evaluating \fIapply(Module, Function, Args)\fR\& on node \fINode\fR\&\&. .LP .RS -4 .B Note: .RE \fB\fIyield/1\fR\&\fR\& and \fB\fInb_yield/1,2\fR\&\fR\& must be called by the same process from which this function was made otherwise they will never yield correctly\&. .RE .LP .nf .B block_call(Node, Module, Function, Args) -> Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Res = Reason = term() .br .RE .RE .RS .LP Same as \fB\fIcall/4\fR\&\fR\&, but the RPC server at \fINode\fR\& does not create a separate process to handle the call\&. Thus, this function can be used if the intention of the call is to block the RPC server from any other incoming requests until the request has been handled\&. The function can also be used for efficiency reasons when very small fast functions are evaluated, for example, BIFs that are guaranteed not to suspend\&. .RE .LP .nf .B block_call(Node, Module, Function, Args, Timeout) -> .B Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Res = Reason = term() .br Timeout = timeout() .br .RE .RE .RS .LP Same as \fB\fIblock_call/4\fR\&\fR\&, but with a time-out value in the same manner as \fB\fIcall/5\fR\&\fR\&\&. .RE .LP .nf .B call(Node, Module, Function, Args) -> Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Res = Reason = term() .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, Args)\fR\& on node \fINode\fR\& and returns the corresponding value \fIRes\fR\&, or \fI{badrpc, Reason}\fR\& if the call fails\&. .RE .LP .nf .B call(Node, Module, Function, Args, Timeout) -> .B Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Res = Reason = term() .br Timeout = timeout() .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, Args)\fR\& on node \fINode\fR\& and returns the corresponding value \fIRes\fR\&, or \fI{badrpc, Reason}\fR\& if the call fails\&. \fITimeout\fR\& is a time-out value in milliseconds\&. If the call times out, \fIReason\fR\& is \fItimeout\fR\&\&. .LP If the reply arrives after the call times out, no message contaminates the caller\&'s message queue, as this function spawns off a middleman process to act as (a void) destination for such an orphan reply\&. This feature also makes this function more expensive than \fIcall/4\fR\& at the caller\&'s end\&. .RE .LP .nf .B cast(Node, Module, Function, Args) -> true .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, Args)\fR\& on node \fINode\fR\&\&. No response is delivered and the calling process is not suspended until the evaluation is complete, as is the case with \fB\fIcall/4,5\fR\&\fR\&\&. .RE .LP .nf .B eval_everywhere(Module, Function, Args) -> abcast .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Equivalent to \fIeval_everywhere([node()|nodes()], Module, Function, Args)\fR\&\&. .RE .LP .nf .B eval_everywhere(Nodes, Module, Function, Args) -> abcast .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, Args)\fR\& on the specified nodes\&. No answers are collected\&. .RE .LP .nf .B multi_server_call(Name, Msg) -> {Replies, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Name = atom() .br Msg = term() .br Replies = [Reply :: term()] .br BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fImulti_server_call([node()|nodes()], Name, Msg)\fR\&\&. .RE .LP .nf .B multi_server_call(Nodes, Name, Msg) -> {Replies, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Name = atom() .br Msg = term() .br Replies = [Reply :: term()] .br BadNodes = [node()] .br .RE .RE .RS .LP Can be used when interacting with servers called \fIName\fR\& on the specified nodes\&. It is assumed that the servers receive messages in the format \fI{From, Msg}\fR\& and reply using \fIFrom ! {Name, Node, Reply}\fR\&, where \fINode\fR\& is the name of the node where the server is located\&. The function returns \fI{Replies, BadNodes}\fR\&, where \fIReplies\fR\& is a list of all \fIReply\fR\& values, and \fIBadNodes\fR\& is one of the following: .RS 2 .TP 2 * A list of the nodes that do not exist .LP .TP 2 * A list of the nodes where the server does not exist .LP .TP 2 * A list of the nodes where the server terminated before sending any reply\&. .LP .RE .RE .LP .nf .B multicall(Module, Function, Args) -> {ResL, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br ResL = [Res :: term() | {badrpc, Reason :: term()}] .br BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fImulticall([node()|nodes()], Module, Function, Args, infinity)\fR\&\&. .RE .LP .nf .B multicall(Nodes, Module, Function, Args) -> {ResL, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Module = module() .br Function = atom() .br Args = [term()] .br ResL = [Res :: term() | {badrpc, Reason :: term()}] .br BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fImulticall(Nodes, Module, Function, Args, infinity)\fR\&\&. .RE .LP .nf .B multicall(Module, Function, Args, Timeout) -> {ResL, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br Timeout = timeout() .br ResL = [Res :: term() | {badrpc, Reason :: term()}] .br BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fImulticall([node()|nodes()], Module, Function, Args, Timeout)\fR\&\&. .RE .LP .nf .B multicall(Nodes, Module, Function, Args, Timeout) -> .B {ResL, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Module = module() .br Function = atom() .br Args = [term()] .br Timeout = timeout() .br ResL = [Res :: term() | {badrpc, Reason :: term()}] .br BadNodes = [node()] .br .RE .RE .RS .LP In contrast to an RPC, a multicall is an RPC that is sent concurrently from one client to multiple servers\&. This is useful for collecting information from a set of nodes, or for calling a function on a set of nodes to achieve some side effects\&. It is semantically the same as iteratively making a series of RPCs on all the nodes, but the multicall is faster, as all the requests are sent at the same time and are collected one by one as they come back\&. .LP The function evaluates \fIapply(Module, Function, Args)\fR\& on the specified nodes and collects the answers\&. It returns \fI{ResL, BadNodes}\fR\&, where \fIBadNodes\fR\& is a list of the nodes that do not exist, and \fIResL\fR\& is a list of the return values, or \fI{badrpc, Reason}\fR\& for failing calls\&. \fITimeout\fR\& is a time (integer) in milliseconds, or \fIinfinity\fR\&\&. .LP The following example is useful when new object code is to be loaded on all nodes in the network, and indicates some side effects that RPCs can produce: .LP .nf %% Find object code for module Mod {Mod, Bin, File} = code:get_object_code(Mod), %% and load it on all nodes including this one {ResL, _} = rpc:multicall(code, load_binary, [Mod, File, Bin]), %% and then maybe check the ResL list. .fi .RE .LP .nf .B nb_yield(Key) -> {value, Val} | timeout .br .fi .br .RS .LP Types: .RS 3 Key = \fBkey()\fR\& .br Val = (Res :: term()) | {badrpc, Reason :: term()} .br .RE .RE .RS .LP Equivalent to \fInb_yield(Key, 0)\fR\&\&. .RE .LP .nf .B nb_yield(Key, Timeout) -> {value, Val} | timeout .br .fi .br .RS .LP Types: .RS 3 Key = \fBkey()\fR\& .br Timeout = timeout() .br Val = (Res :: term()) | {badrpc, Reason :: term()} .br .RE .RE .RS .LP Non-blocking version of \fB\fIyield/1\fR\&\fR\&\&. It returns the tuple \fI{value, Val}\fR\& when the computation is finished, or \fItimeout\fR\& when \fITimeout\fR\& milliseconds has elapsed\&. .LP .RS -4 .B Note: .RE This function must be called by the same process from which \fB\fIasync_call/4\fR\&\fR\& was made otherwise it will only return \fItimeout\fR\&\&. .RE .LP .nf .B parallel_eval(FuncCalls) -> ResL .br .fi .br .RS .LP Types: .RS 3 FuncCalls = [{Module, Function, Args}] .br Module = module() .br Function = atom() .br Args = ResL = [term()] .br .RE .RE .RS .LP Evaluates, for every tuple in \fIFuncCalls\fR\&, \fIapply(Module, Function, Args)\fR\& on some node in the network\&. Returns the list of return values, in the same order as in \fIFuncCalls\fR\&\&. .RE .LP .nf .B pinfo(Pid) -> [{Item, Info}] | undefined .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br Item = atom() .br Info = term() .br .RE .RE .RS .LP Location transparent version of the BIF \fB\fIerlang:process_info/1\fR\&\fR\& in ERTS\&. .RE .LP .nf .B pinfo(Pid, Item) -> {Item, Info} | undefined | [] .br .fi .br .nf .B pinfo(Pid, ItemList) -> [{Item, Info}] | undefined | [] .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br Item = atom() .br ItemList = [Item] .br Info = term() .br .RE .RE .RS .LP Location transparent version of the BIF \fB\fIerlang:process_info/2\fR\&\fR\& in ERTS\&. .RE .LP .nf .B pmap(FuncSpec, ExtraArgs, List1) -> List2 .br .fi .br .RS .LP Types: .RS 3 FuncSpec = {Module, Function} .br Module = module() .br Function = atom() .br ExtraArgs = [term()] .br List1 = [Elem :: term()] .br List2 = [term()] .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, [Elem|ExtraArgs])\fR\& for every element \fIElem\fR\& in \fIList1\fR\&, in parallel\&. Returns the list of return values, in the same order as in \fIList1\fR\&\&. .RE .LP .nf .B sbcast(Name, Msg) -> {GoodNodes, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Name = atom() .br Msg = term() .br GoodNodes = BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fIsbcast([node()|nodes()], Name, Msg)\fR\&\&. .RE .LP .nf .B sbcast(Nodes, Name, Msg) -> {GoodNodes, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Name = atom() .br Msg = term() .br Nodes = GoodNodes = BadNodes = [node()] .br .RE .RE .RS .LP Broadcasts the message \fIMsg\fR\& synchronously to the registered process \fIName\fR\& on the specified nodes\&. .LP Returns \fI{GoodNodes, BadNodes}\fR\&, where \fIGoodNodes\fR\& is the list of nodes that have \fIName\fR\& as a registered process\&. .LP The function is synchronous in the sense that it is known that all servers have received the message when the call returns\&. It is not possible to know that the servers have processed the message\&. .LP Any further messages sent to the servers, after this function has returned, are received by all servers after this message\&. .RE .LP .nf .B server_call(Node, Name, ReplyWrapper, Msg) -> .B Reply | {error, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Name = atom() .br ReplyWrapper = Msg = Reply = term() .br Reason = nodedown .br .RE .RE .RS .LP Can be used when interacting with a server called \fIName\fR\& on node \fINode\fR\&\&. It is assumed that the server receives messages in the format \fI{From, Msg}\fR\& and replies using \fIFrom ! {ReplyWrapper, Node, Reply}\fR\&\&. This function makes such a server call and ensures that the entire call is packed into an atomic transaction, which either succeeds or fails\&. It never hangs, unless the server itself hangs\&. .LP The function returns the answer \fIReply\fR\& as produced by the server \fIName\fR\&, or \fI{error, Reason}\fR\&\&. .RE .LP .nf .B yield(Key) -> Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Key = \fBkey()\fR\& .br Res = Reason = term() .br .RE .RE .RS .LP Returns the promised answer from a previous \fB\fIasync_call/4\fR\&\fR\&\&. If the answer is available, it is returned immediately\&. Otherwise, the calling process is suspended until the answer arrives from \fINode\fR\&\&. .LP .RS -4 .B Note: .RE This function must be called by the same process from which \fB\fIasync_call/4\fR\&\fR\& was made otherwise it will never return\&. .RE