Erlang C node related question

The tutorial shows: http://www.erlang.org/doc/tutorial/cnode.html

The following is an example:


/* cnode_s.c */
#include 
#include 
#include 
#include 
#include "erl_interface.h"
#include "ei.h"
#define BUFSIZE 1000
int main(int argc, char **argv) {
  int port;                                /* Listen port number */
  int listen;                              /* Listen socket */
  int fd;                                  /* fd to Erlang node */
  ErlConnect conn;                         /* Connection data */
  int loop = 1;                            /* Loop flag */
  int got;                                 /* Result of receive */
  unsigned char buf[BUFSIZE];              /* Buffer for incoming message */
  ErlMessage emsg;                         /* Incoming message */
  ETERM *fromp, *tuplep, *fnp, *argp, *resp;
  int res;
  port = atoi(argv[1]);
  erl_init(NULL, 0);
  if (erl_connect_init(1, "secretcookie", 0) == -1)
    erl_err_quit("erl_connect_init");
  /* Make a listen socket */
  if ((listen = my_listen(port)) 

I suspect that erl_receive_msg is a blocking call, and I don't know how to overcome this. In C network programming there is the "select" statement but in the Erlang EI API I don't know whether there is such a statement.

Basically I want to build a C node, that continuously sends messages to Erlang nodes. For simplicity suppose there is only one Erlang node.

The Erlang node has to process the messages it receives from the C node. The Erlang node is not supposed to ensure that it has received the message, not does it have to reply with the result of processing. Therefore once the message is sent I don't care about it faith.

One might think that one could modify the code as:

...
if (emsg.type == ERL_REG_SEND) {
    ...
    while(1) { 
        //generate tuple
        erl_send(fd, fromp, tuple);
        //free alloc resources
    }
    ...
}

, () . : , C node Erlang node ( Erlang node C node ), Erlang node , C node .

, ( ), :

( , ) C Erlang, ?

+5
3

Port Drivers , ( C, ).

Port Driver Erlang: EPAPI. , : Erland DBus.

+2

ei_receive_msg_tmo? , , Erlang, , - 0, .

, erl_interface , ei. , ...

+1

you need to study the link to the tutorial that you published more closely. (search "And finally, we have the code for the C node client".) You will see that the author has provided an implementation of client cnode. It looks rational.

+1
source

All Articles