<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks Tony for the tip. I was hoping there is some other way to call the emulator's internals without resorting to having to implement both a driver and a NIF library for this purpose. It seems like it's somewhat an oversight in the NIF API design that needs to be addressed - there should be a NIF capable of associating an FD with a callback or else, as you mentioned, the implementation of this becomes more complicated than necessary when integrating with external C libraries. </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 29, 2015 at 9:44 AM, Tony Rogvall <span dir="ltr"><<a href="mailto:tony@rogvall.se" target="_blank">tony@rogvall.se</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Why not write a small driver that can watch a number of file descriptors,<div>Get fd from a nif pass it to the driver_select_driver may be overkill but fun.</div><div><br></div><div>Could be a useful thing.</div><div><br></div><div>I am working on something that may someday be capable of doing this,</div><div>( <a href="https://github.com/tonyrog/niffed" target="_blank">https://github.com/tonyrog/niffed</a> )</div><div>It is a a C library that allow you to call (linked) nif library from driver code,</div><div>The marshalling code is actually building VM heap compatible data that </div><div>can be processed by the nif code, only by offsetting some pointers :-)</div><div>It is even possible to use the same shared object as both nif and driver!</div><div><br></div><div>/Tony</div><div><br></div><div><div><blockquote type="cite"><div>On 29 jan 2015, at 15:20, Serge Aleynikov <<a href="mailto:serge@aleynikov.org" target="_blank">serge@aleynikov.org</a>> wrote:</div><br><div><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Is there a way to hook a file descriptor from within a NIF function to the select/epoll/poll loop managed by the emulator with a callback invoked in the "NIF-land" on activity detected on the file descriptor?</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I am looking for similar functionality available to NIF functions that is available when writing drivers using driver_select() call (*). More specifically, I have an eventfd file descriptor that I'd like to be notified about without allocating a separate OS thread to poll on that FD and return results by sending a message to a given Erlang Pid.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Serge</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">(*) <a href="http://www.erlang.org/doc/man/erl_driver.html#driver_select" target="_blank">http://www.erlang.org/doc/man/erl_driver.html#driver_select</a></div></div>
_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" target="_blank">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></div></blockquote></div><br></div></div></blockquote></div><br></div>