Take a look at BERT (
<a href="http://bert-rpc.org/">http://bert-rpc.org/</a> ). BERT does almost the same thing as binary_to_term() and term_to_binary(), and there is a C++ implementation that might fit in your NIF.<div><br></div><div>Dan.<br>
<br><div class="gmail_quote">On Mon, Feb 13, 2012 at 10:56 AM, Matthew Evans <span dir="ltr"><<a href="mailto:mattevans123@hotmail.com">mattevans123@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div dir="ltr">
Hi<div><br></div><div>I've written a NIF that takes data from an external device driver, converts it to a term (a tuple) and uses enif_send (from a thread created by the nif) to a specific Erlang process.</div><div><br>
</div><div>Unfortunately on some deployments we have been forced to disable SMP in the Linux kernel and BEAM due to a third-party driver issue. In these cases what I have done is used enif_system_info in the NIF, and if SMP is disabled I will send the message via a unix domain socket (I have a driver for that) instead of enif_send.</div>
<div><br></div><div>On the Erlang side the UDS is opened, and I use erlang:open_port to pass the unix domain socket to the event loop. What is nice here is that I can use the same Erlang and C code for both SMP enabled and disabled systems. So the Erlang process would get an Erlang message like:</div>
<div><br></div><div>{driver_result,Integer,Integer} - If SMP is enabled</div><div><br></div><div>Or: </div><div><br></div><div><div>{#Port<0.647>,{data,SomeBinary}} - If SMP is disabled</div></div><div><br></div><div>
What I would like to do is see if I can send the message as an Erlang term to the unix domain socket using something like term_to_binary in the NIF (I would prefer that instead of sending raw binary to Erlang with enif_send).</div>
<div><br></div><div>Is that possible?</div><div><br></div><div>Thanks</div><div><br></div><div>Matt</div> </div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>