| Author |
Message |
|
| gandalf at control.att.co |
Posted: Wed Jun 02, 1999 7:09 pm |
|
|
|
Guest
|
Folks,
I'd have another dumb question about "registered" process.
Here is a erlang code:
%%-------------------------------------------------
start() ->
Rec = spawn(dumb_eh, receiver, []),
register(eh, Rec).
%%--------------------------------------------------
receiver() ->
receive
Message ->
io:format("Recv: ~w~n", Message),
receiver()
end.
%%---------------------------------------------------
This dumb handler working just fine:
(server_at_rohan)16> eh!{boo, baa, foo, bar,42}.
{boo,baa,foo,bar,42}
(server_at_rohan)17>
-----------------------------------------------------
And regs(). returns exactly what I'm expected:
global_name_server <0.11.0> {global,init,1} 52 0
eh <0.62.0> {dumb_eh,receiver,0} 106 0
------------------------------------------------------
I did tried to send erl_reg_send, it seems like eh do not received any
messages. I did create small tool:
**************************************************************
#include "erl_interface.h"
#include "ei.h"
int main(int argc, char **argv) {
int sockfd;
char **names;
int count;
erl_init(NULL, 0);
erl_connect_init(42, "thecookie", 0);
sockfd = erl_connect("server_at_rohan");
names = erl_global_names(sockfd, &count);
printf("%d,%d
", sockfd, count);
erl_close_connection(sockfd);
}
****************************************************************
And count returns 0. May be you'll tell to me, what I did wrong.
=======================================================
Vladimir I. Ulogov (gandalf_at_control.att.com)
tel: 973-236-6464 or 6463
fax: 973-236-2090
"Where lands meets water. Where earth meets air. Where body meets
mind. Where space meets time. We like to be on one side, and look
at the other." D.Adams "Mostly harmless"
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| luke at javagroup.org |
Posted: Wed Jun 02, 1999 7:47 pm |
|
|
|
Guest
|
Vladimir Ulogov <gandalf_at_control.att.com> writes:
> Folks,
> I'd have another dumb question about "registered" process.
> Here is a erlang code:
> %%-------------------------------------------------
> start() ->
> Rec = spawn(dumb_eh, receiver, []),
> register(eh, Rec).
> %%--------------------------------------------------
> receiver() ->
> receive
> Message ->
> io:format("Recv: ~w~n", Message),
^^^ This looks suspicious -- I believe you want:
io:format("Recv: ~w~n", [Message]),
i.e., Message inside a list. Instead of raising an error on that sort
of problem, format just returns {error,format}, so it's easy to miss.
Cheers,
Luke
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| gandalf at control.att.co |
Posted: Wed Jun 02, 1999 8:34 pm |
|
|
|
Guest
|
On 3 Jun 1999, Luke Gorrie wrote:
> > io:format("Recv: ~w~n", Message),
> ^^^ This looks suspicious -- I believe you want:
> io:format("Recv: ~w~n", [Message]),
Yes, Luke, was my mistake, of course [Message], but why erl_global_names
returns 0 ?
> Luke
=======================================================
Vladimir I. Ulogov (gandalf_at_control.att.com)
tel: 973-236-6464 or 6463
fax: 973-236-2090
"Where lands meets water. Where earth meets air. Where body meets
mind. Where space meets time. We like to be on one side, and look
at the other." D.Adams "Mostly harmless"
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| klacke at bluetail.com |
Posted: Wed Jun 02, 1999 8:43 pm |
|
|
|
Guest
|
>
> Folks,
> I'd have another dumb question about "registered" process.
> receiver() ->
> receive
> Message ->
> io:format("Recv: ~w~n", Message),
> receiver()
> end.
Should be
io:format("Recv: ~w~n", [Message]),
This is really irritating that io:format/2 doesn't
fail when presented with unformatable data.
It simply fails to write anything and returns
an error code.
A very good practice is to start to write
ok = io:format(.....
everywhere in the code, the match then works as an
assertion and the process will crash when io:format/2
returns an error code.
> (server_at_rohan)16> eh!{boo, baa, foo, bar,42}.
> {boo,baa,foo,bar,42}
Ahhh, but this is not the printout, this is the
return value from the sendstatement that is printed in
the shell, where is the "Recv .... " ??
/klacke
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| tobbe at serc.rmit.edu.au |
Posted: Wed Jun 02, 1999 8:47 pm |
|
|
|
Guest
|
Did you use the same cookie on the erlang side ?
Did you start erlang as a distributed node ?
Example: erl -name hello -setcookie thecookie
/Tobbe
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| tobbe at serc.rmit.edu.au |
Posted: Wed Jun 02, 1999 8:51 pm |
|
|
|
Guest
|
> Example: erl -name hello -setcookie thecookie
Sorry, should in your example be:
erl -sname server -setcookie thecookie
/Tobbe
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| gandalf at control.att.co |
Posted: Wed Jun 02, 1999 9:07 pm |
|
|
|
Guest
|
On Thu, 3 Jun 1999, Torbjorn Tornkvist wrote:
> Did you use the same cookie on the erlang side ?
In get_names.c:
erl_connect_init(42, "thecookie", 0);
> Did you start erlang as a distributed node ?
yes, sure:
rohan:/local/andorra _ /local/erlang/bin/erl -name server -setcookie
thecookie
Erlang (JAM) emulator version 47.4.1
Eshell V47.4.1 (abort with ^G)
(server_at_rohan.control.att.com)1>
-----------------------
sockfd = erl_connect("server_at_rohan.control.att.com");
names = erl_global_names(sockfd, &count);
printf("%d,%d
", sockfd, count);
-----------------------
Output:
3,0
=======================================================
Vladimir I. Ulogov (gandalf_at_control.att.com)
tel: 973-236-6464 or 6463
fax: 973-236-2090
"Where lands meets water. Where earth meets air. Where body meets
mind. Where space meets time. We like to be on one side, and look
at the other." D.Adams "Mostly harmless"
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| tobbe at serc.rmit.edu.au |
Posted: Wed Jun 02, 1999 9:17 pm |
|
|
|
Guest
|
> sockfd = erl_connect("server_at_rohan.control.att.com");
> names = erl_global_names(sockfd, &count);
> printf("%d,%d
", sockfd, count);
> -----------------------
> Output:
> 3,0
Looks ok to me. '3' is the socket-descriptor and '0'
is the number of globally registered processes.
NB: Initially, when you start your Erlang node you don't
have any globally registered processes. Example:
unix> erl -sname hello
Erlang (BEAM) emulator version 47.4.1
Eshell V47.4.1 (abort with ^G)
(hello_at_campari)1> length(global:registered_names()).
0
(hello_at_campari)2>
/Tobbe
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| gandalf at control.att.co |
Posted: Wed Jun 02, 1999 9:31 pm |
|
|
|
Guest
|
On Thu, 3 Jun 1999, Torbjorn Tornkvist wrote:
> Looks ok to me. '3' is the socket-descriptor and '0'
Well, I'm have "registered" process on erlang node.
-------------------------------------
Rec = spawn(dumb_eh, receiver, []),
register(eh, Rec).
-------------------------------------
How I can makes this process avialable for the C application which use
erl_interface acessible by name (erl_reg_send) ?
=======================================================
Vladimir I. Ulogov (gandalf_at_control.att.com)
tel: 973-236-6464 or 6463
fax: 973-236-2090
"Where lands meets water. Where earth meets air. Where body meets
mind. Where space meets time. We like to be on one side, and look
at the other." D.Adams "Mostly harmless"
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| gandalf at control.att.co |
Posted: Wed Jun 02, 1999 9:37 pm |
|
|
|
Guest
|
On Thu, 3 Jun 1999, Torbjorn Tornkvist wrote:
> (hello_at_campari)1> length(global:registered_names()).
(server_at_rohan.control.att.com)9> global:register_name("eh", P).
(server_at_rohan.control.att.com)11> global:registered_names().
["eh"]
------------------------
Output still to be:
3,0
=======================================================
Vladimir I. Ulogov (gandalf_at_control.att.com)
tel: 973-236-6464 or 6463
fax: 973-236-2090
"Where lands meets water. Where earth meets air. Where body meets
mind. Where space meets time. We like to be on one side, and look
at the other." D.Adams "Mostly harmless"
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| jon at serc.rmit.edu.au |
Posted: Thu Jun 03, 1999 1:07 am |
|
|
|
Guest
|
Hi Vladimir,
I tried your program and it works fine for me. In your last email you
correctly used global:register_name(eh,P) instead of the register(eh,P)
in the original program. I have attached my erl file, the C program and
the makefile below. I get the following result:
universe_104% erl -sname test -setcookie bla
Erlang (BEAM) emulator version 47.4.1
Eshell V47.4.1 (abort with ^G)
(test_at_universe)1> test:start().
Starting the receiver.
yes
(test_at_universe)2> global:registered_names().
[eh]
And when I run the C program:
universe_33% ./erl_reg_send
4,1
Cheers,
Jon Larsson
--
Erl file:
%%-------------------------------------------------
-module(test).
-export([start/0,receiver/0]).
%%-------------------------------------------------
start() ->
P = spawn(test, receiver, []),
io:fwrite("Starting the receiver.~n"),
global:register_name(eh, P).
%%--------------------------------------------------
receiver() ->
receive
stop ->
io:format("Stop.~n");
Message ->
io:format("Recv: ~w~n", [Message]),
receiver()
end.
%%---------------------------------------------------
C file:
*****************************************************
#include "erl_interface.h"
#include "ei.h"
int main(int argc, char **argv) {
int sockfd;
char **names;
int count;
erl_init(NULL, 0);
erl_connect_init(42, "bla", 0);
sockfd = erl_connect("test_at_universe");
names = erl_global_names(sockfd, &count);
printf("%d,%d
", sockfd, count);
erl_close_connection(sockfd);
}
*****************************************************
Makefile:
FILES = erl_reg_send.o
INCFLAGS = -I/opt/erlang-47.4.1/lib/erlang/usr/include
LIBFLAGS = -L/opt/erlang-47.4.1/lib/erlang/usr/lib
CFLAGS = $(INCFLAGS) $(LIBFLAGS)
all: $(FILES)
$(LINK.c) -o erl_reg_send $< -lerl_interface -lei -lnsl -lsocket -lresolv
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| peter.olin at ericsson.co |
Posted: Thu Jun 03, 1999 8:38 am |
|
|
|
Guest
|
Claes Wikstrom wrote:
> This is really irritating that io:format/2 doesn't
> fail when presented with unformatable data.
> It simply fails to write anything and returns
> an error code.
True! Really irritating. And of course the source of many obscure run-time errors that are not spotted right away as
they happen.
> A very good practice is to start to write
> ok = io:format(.....
> everywhere in the code, the match then works as an
> assertion and the process will crash when io:format/2
> returns an error code.
A "very good practice" is perhaps exaggerating the positive side of it a bit. I would say it is a necessary,kludgy
workaround enforced by poor design in the library modules. And we have lived with it too long already.
There are many places in OTP where errors are "signalled" this way.
The practice of *returning* {error,}-tuples and {ok,}-tuples instead of simply returning the relevant values, or EXITing
also makes it impossible to have nested function calls.
For instance: (code not compiled or executed)
copy1(File1, File2) ->
file:write_file("dot_login", file:read_file(".login")).
is impossible. Instead one has to write:
copy2(File1, File2) ->
{ok, B} = file:read_file(".login"),
ok = file:write_file("dot_login", B).
Not only is this awkward, but also, instead of simply handling the values we're interested in we need to match
structures and explicitly force our code to crash where it would be natural to have that behaviour implicitly.
"Backwards compatibility" has been the often mentioned reason for keeping a lot of the inconsistencies in the OTP
libraries, but I really don't think that's an argument.
What's the "public opinion" on revising and rewriting interfaces so that functions have some consistent use of "types",
return values, EXIT reasons, etc.? There are many ways of keeping the system backwards compatible, without actively
preventing improvements where there is a need for them. (New names for revised modules, forwarding of calls, compiler
warnings, etc)
--
/Peter Olin (mailto:peter.olin_at_ericsson.com)
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| crd at inversenet.com |
Posted: Thu Jun 03, 1999 6:01 pm |
|
|
|
Guest
|
Peter Olin wrote:
> The practice of *returning* {error,}-tuples and {ok,}-tuples instead of
> simply returning the relevant values, or EXITing also makes it impossible
> to have nested function calls.
>
> For instance: (code not compiled or executed)
> copy1(File1, File2) ->
> file:write_file("dot_login", file:read_file(".login")).
>
> is impossible. Instead one has to write:
>
> copy2(File1, File2) ->
> {ok, B} = file:read_file(".login"),
> ok = file:write_file("dot_login", B).
>
> Not only is this awkward, but also, instead of simply handling the values
> we're interested in we need to match structures and explicitly force our
> code to crash where it would be natural to have that behaviour implicitly.
True. It isn't quite true, though, that nested function calls are
impossible.
There is another way to write it than your copy2:
copy3(File1, File2) ->
file:write_file("dot_login",
begin {ok, B} = file:read_file(".login"), B end).
Whether this is better or worse than copy2 is probably a question of taste.
> "Backwards compatibility" has been the often mentioned reason for keeping
a
> lot of the inconsistencies in the OTP libraries, but I really don't think
> that's an argument.
>
> What's the "public opinion" on revising and rewriting interfaces so that
> functions have some consistent use of "types", return values, EXIT
reasons,
> etc.? There are many ways of keeping the system backwards compatible,
without
> actively preventing improvements where there is a need for them. (New
names
> for revised modules, forwarding of calls, compiler warnings, etc)
Sounds good to me. I don't even much care if backward compatibility is
retained,
though it's probably a good idea.
Craig
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| luke at javagroup.org |
Posted: Thu Jun 03, 1999 6:53 pm |
|
|
|
Guest
|
"Craig Dickson" <crd_at_inversenet.com> writes:
> Peter Olin wrote:
[...]
> copy3(File1, File2) ->
> file:write_file("dot_login",
> begin {ok, B} = file:read_file(".login"), B end).
Interesting, I've never come across "begin" before. Could you please
give me a pointer to where it's documented? Perhaps I just missed it
in the general documentation, or are there some nice features tucked
away in the specification/reference manual only?
--
"The Commando Pattern is used to get in and out quick, and get the job
done. This pattern can break any encapsulation to accomplish its
mission. It takes no prisoners." - Michael Duell ("Resign Patterns")
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
| crd at inversenet.com |
Posted: Thu Jun 03, 1999 8:43 pm |
|
|
|
Guest
|
Luke Gorrie <luke_at_javagroup.org> wrote:
> "Craig Dickson" <crd_at_inversenet.com> writes:
>
> > copy3(File1, File2) ->
> > file:write_file("dot_login",
> > begin {ok, B} = file:read_file(".login"), B end).
>
> Interesting, I've never come across "begin" before. Could you please
> give me a pointer to where it's documented? Perhaps I just missed it
> in the general documentation, or are there some nice features tucked
> away in the specification/reference manual only?
Erlang 4.7.3 Reference Manual, section 6.20.6, "Block Expressions".
Craig
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
|
|
All times are GMT
Page 1 of 2
Goto page 1, 2 Next
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|