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

Serge Aleynikov serge@REDACTED
Thu Jan 29 20:52:52 CET 2015


Though this doesn't preclude the I/O subsystem from actually reading data
from the file descriptor. The C library I am bridging with Erlang has it's
own reactive paradigm, yet it permits to use an external select/poll event
reactor, so I only need to be notified by the emulator that there is data
to be read on a given Fd, and pass that Fd to a C function call to do the
reading/decoding (same for writing when the Fd is congested).  I realize
there are many ways to skin the cat, but it looks to me that NIF API for
hooking FDs with callbacks into the emulator's I/O loop would be the most
beneficial...

On Thu, Jan 29, 2015 at 2:16 PM, Michael Santos <michael.santos@REDACTED>
wrote:

> 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]).
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150129/d8585132/attachment.htm>


More information about the erlang-questions mailing list