[erlang-questions] NIFs and hooking file descriptors to Erlang-manged poll

Michael Santos michael.santos@REDACTED
Thu Jan 29 20:16:58 CET 2015


On Thu, Jan 29, 2015 at 09:20:25AM -0500, Serge Aleynikov wrote:
> 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?
> 
> 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.
> 
> Thanks,
> 
> Serge
> 
> (*) http://www.erlang.org/doc/man/erl_driver.html#driver_select

The simplest way is by passing the fd directly into a port:

erlang:open_port({fd,Fd,Fd}, [binary,stream]).



More information about the erlang-questions mailing list