<br><br><div class="gmail_quote">2011/8/20 Alexander Kuleshov <span dir="ltr"><<a href="mailto:kuleshovmail@gmail.com">kuleshovmail@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>Hello,</div><div><br></div><div>I try to send message from C code to erlang. I use EI Library.</div><div><br></div><div>My C code:</div><div><br></div><div> int main (int argc, char** argv)</div><div> {</div><div>
erl_init (NULL, 0);</div><div> </div><div> extern const char *erl_thisnodename(void);</div><div> extern short erl_thiscreation(void);</div><div> </div><div> #define SELF(fd) erl_mk_pid(erl_thisnodename(), fd, 0, erl_thiscreation())</div>
<div> </div><div> ETERM *arr[2], *emsg;</div><div> </div><div> int sockfd, creation=1;</div><div> </div><div> arr[0] = SELF(sockfd);</div><div> arr[1] = erl_mk_atom("ok");</div><div>
emsg = erl_mk_tuple(arr, 2);</div><div> </div><div> erl_reg_send(sockfd, "my_server", emsg);</div><div> erl_free_term(emsg);</div><div> </div><div> return (EXIT_SUCCESS);</div><div>
}</div>
<div><br></div><div>And my erlang code:</div><div><br></div><div> start() -></div><div> <span style="white-space:pre-wrap"> </span>Pid = spawn(?MODULE, loop, []),</div><div> <span style="white-space:pre-wrap"> </span>register(my_server, Pid).</div>
<div> </div><div> loop() -></div><div> <span style="white-space:pre-wrap"> </span>receive</div><div> <span style="white-space:pre-wrap"> </span>{ok} -></div><div> <span style="white-space:pre-wrap"> </span>io:format("Ok received \n"),</div>
<div> <span style="white-space:pre-wrap"> </span>loop();</div><div> <span style="white-space:pre-wrap"> </span>stop -></div><div> <span style="white-space:pre-wrap"> </span>stop;</div>
<div> <span style="white-space:pre-wrap"> </span>_ -></div><div> <span style="white-space:pre-wrap"> </span>io:format("Somethig else \n")</div><div> end.<span style="white-space:pre-wrap"> </span></div>
<div> </div><div> stop() -></div><div> <span style="white-space:pre-wrap"> </span>my_server ! stop.</div><div><br></div><div>But when i run my C application, erlang application nothing received. What's wrong?</div>
<div><br></div><div>Thank you.</div><div><br></div></blockquote><div>And i get error:</div><div><br></div><div>[Thread debugging using libthread_db enabled]</div><div><br></div><div>Program received signal SIGSEGV, Segmentation fault.</div>
<div>0x08055fac in ei_mutex_lock ()</div><div> </div></div><br>