Threaded Erlang C- Node (cnode) Interaction howto?

I am at the Erlang development point where I need to create a C-Node (see link for C-Node docs). The main implementation is quite simple, but there is a huge hole in the document.

The code implements one stream client and server. Ignoring the client at the moment ... The c code that the server implements is single-threaded and can only connect to one erlang client at a time.

  • Running EPMD ('epmd-daemons')
  • Launch the server application ('cserver 1234')
  • Launch the erlang client application ('erl -sname e1 -setcookie secretcookie') [in another window, from # 2]
  • execute the server command ('complex3: foo (3).') from the erlang shell in # 3

Now that the server is up and that the current erlang shell is connected to the server, try again from another window.

  • open a new window.
  • start the erlang client ('erl -sname e2 -setcookie secretcookie').
  • execute a new server command ('complex3: foo (3).').

Note that the system seems to hang ... when it was supposed to execute the command. The reason it hangs is due to the fact that another erlang node is connected and there are no other threads that listen on the connections.

NOTE. There seems to be an error processing the connection. I added a timeout in the receive block, and I caught some strange behavior, but I did not get them all. In addition, I was able to make cserver crash without warning or error if I forcefully terminated the first erlang node after following the steps.

, ... C- Node? ?

+3
1

cnode cnode tutorial node, , .

erl_accept - , .

if ((fd = erl_accept(listen, &conn)) == ERL_ERROR)
  erl_err_quit("erl_accept");
fprintf(stderr, "Connected to %s\n\r", conn.nodename);
while (loop) {
  got = erl_receive_msg(fd, buf, BUFSIZE, &emsg);

, , , cnode , /. , erlang node, cnode , erl_receive_msg , fd .

, . , , (, , ) syscall poll select, .

, , , , concurrency cnode. , erlang concurrency, cnode .

+3

Source: https://habr.com/ru/post/1738545/


All Articles