[erlang-questions] FW: Local and remote sends
Bob Cowdery
Bob.Cowdery@REDACTED
Tue Oct 31 14:32:15 CET 2006
On 2006-10-31 13:18, Bob Cowdery wrote:
> On 2006-10-30 16:54, Bob Cowdery wrote:
>> Hi
>>
>> I have a process that usually sends to a CNode, however, for
>> testing I use erlang processes running in the same session. My
>> sends are of the form: {any, From} ! {GatewayPid} When I am testing
>> this does not work and gives an argument error on running and I
>> have to change it to:
>>> From ! {GatewayPid}
>> Is there some form that will work in both situations?
>
>>> is it correct that 'any' is the registered name of a process? and
>>> that From is the node name (also atom) you want to reach? then
>>> sending to From during testing is an error and should not work.
>>> you should have a pid (or registered name), not a node name.
>>>
>>> i think i must have misunderstood something here.
>
> As far as I can tell I have two different situations. When working
> locally in one erlang session the From is a Pid (the Pid of the
> sender to which I am replying) which I need to use directly as the
> target of the send. When the From is a CNode there is no Pid, just a
>> it is somewhat confusing to have the same variable name in these cases.
>> presumably it is perfectly fine when seen in context, but there is no
>> context here. please consider adding context, or having different names.
It's just a receive loop
<snip>
server_loop(Registrations, Classes) ->
receive
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Register a new actor
%%
%% @From the erlang short-name or Pid
%% @Class the class of this client
%% @Mode one of [client, server, both]
%% @Access one of [default, polling, none]
%% @Format one of [TBD]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{new_reg, From, Class, Mode, Access, Format} ->
...
</snip>
so could get called from any type of node or process. I guess there could be a different pattern depending on the type of 'From' but all the code is common except for that one instance of replying with From or {any, From}.
> short name in my case (e.g. c1@REDACTED) and I need to use a tuple to
> address it like {any, c1@REDACTED}. The 'any' is a registered name but is
> ignored for all intent and purpose, so it's just any old atom as far
> as I am concerned. It explains this a bit in the interoperability
> tutorial on page 20.
>> when i go to the interoperability tutorial
>> http://www.erlang.org/doc/doc-5.5.1/doc/tutorial/part_frame.html
>> i have no page numbers. could you give me the chapter/paragraph instead?
7.1
> I guess I need to test the address and see what form it is. Do you
> know of any simple way to determin a Pid from a short address apart
> from looking at the makeup and deducing what it is.
>> erlang:is_pid/1 is a good way to see if you have a pid.
Thanks, that works fine.
bengt
--
EPO guidelines 1978: "If the contribution to the known art resides
solely in a computer program then the subject matter is not
patentable in whatever manner it may be presented in the claims."
More information about the erlang-questions
mailing list