| Author |
Message |
|
| gandalf at control.att.co |
Posted: Tue May 25, 1999 8:57 pm |
|
|
|
Guest
|
Hello,
I'm having questions related with some ERTS issues:
1) Where I can find a sample, how to handle ErlMessage and receive
information from them. As sample, if I'm expecting to receive something
like {pid, atom, number, sting}, how to extract pid, atom, number and
string from the ErlMessage.
2) At the time, as I wants to create pid using SELF(sockfd) macros (from
the 1.2 Erl_Interface library). What is sockfd? Which socket file
descriptor I should use if I wants to send messages like {sender pid,
atom, number, string} from C program.
3) How to return messages to C program, which invokes erl_receive_msg.
Which operations I should perform before erl_receive_msg ?
Thank you for assistance .
=======================================================
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 May 26, 1999 3:01 am |
|
|
|
Guest
|
Hi !
I assume you have read the erl_interface User's Manual (and the
Reference Manuals) ? If not, here are some examples:
> 1) Where I can find a sample, how to handle ErlMessage and receive
> information from them. As sample, if I'm expecting to receive something
> like {pid, atom, number, sting}, how to extract pid, atom, number and
> string from the ErlMessage.
ETERM *arr[2], *msg;
int sockfd,rc;
char buf[BUFSIZE];
ErlMessage emsg;
....stuff here....
if ((rc = erl_receive_msg(sockfd , buf, BUFSIZE, &emsg)) == ERL_MSG) {
ETERM *pid,*atom,*number,*string;
msg = erl_decode_buf(bufp);
if (ERL_IS_TUPLE(msg) & (ERL_TUPLE_SIZE(msg) == 4)) {
/* NOTE!!! This is 0-based!! (first item is number 0)
* Note too that element/2 (in Erlang) and
* erl_element() are both 1-based.
*/
pid = ERL_TUPLE_ELEMENT(msg, 0);
atom = ERL_TUPLE_ELEMENT(msg, 1);
number = ERL_TUPLE_ELEMENT(msg, 2);
string = ERL_TUPLE_ELEMENT(msg, 3);
....etc.....
}
....etc....
}
(NB: ERL_TUPLE_ELEMENT(x, i) doesn't seem to be documented.
You'll find it in the erl_eterm.h header file though...)
> 2) At the time, as I wants to create pid using SELF(sockfd) macros (from
> the 1.2 Erl_Interface library). What is sockfd? Which socket file
> descriptor I should use if I wants to send messages like {sender pid,
> atom, number, string} from C program.
'sockfd' is the filedescriptor you get from erl_connect()
Example:
int sockfd;
char *nodename="xyz_at_my.domain.org"; /* An example */
if ((sockfd = erl_connect(nodename)) < 0)
erl_err_quit("ERROR: erl_connect failed");
> 3) How to return messages to C program, which invokes erl_receive_msg.
You mean from Erlang ?
In your C program you create your own Pid using the SELF() macro.
This Pid, has to be included in the message you send to Erlang.
The Erlang side can then use it to return a message.
It may be easier to use erl_rpc() instead. See for example,
how erl_rpc() is used in erl_call.c .
> Which operations I should perform before erl_receive_msg ?
See the User's Manual. Basically you need to call erl_init()
and erl_connect() before you can receive anything, but again
to receive something asynchronous on your C-side, Erlang needs
to know the Pid (NB: C-nodes doesn't show up in the result from
the nodes/0 BIF), so you probably need to send (at least) your Pid
to Erlang (using erl_send() ) before you can expect to receive
anything on the C-side.
Good luck !
/Tobbe
Post generated using Mail2Forum (http://m2f.sourceforge.net) |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
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
|
|
|