<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 2015-01-29 15:20, Serge Aleynikov
      wrote:<br>
    </div>
    <blockquote
cite="mid:CANt451kfg_u-5nemeiRAroQPerYh0qeKc7go+DVX6AZQM0W8YQ@mail.gmail.com"
      type="cite">
      <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>
    </blockquote>
    <br>
    I think you have discovered why we have drivers in Erlang. This is
    exactly the use case for drivers. Normally you don't do much in a
    driver. You react to an event and transfer the binary to erlang
    space and to what should be done in Erlang. Don't try to program
    Erlang in C (like erl_interface), do it in Erlang.<br>
    <br>
    And no, we don't have native processes (in which case drivers would
    be obsolete). And no, it's not an oversight in the NIF API, not
    really. You could see native processes as an extension to NIFs but
    it is something completely different.<br>
    <br>
    In some specific cases you could transfer a fd (socket) to Erlangs
    I/O system, i.e. select/poll. See gen_tcp:connect/3,4. I know of
    projects that open fd:s in NIFs which then get transferred to
    gen_tcp in this manner.<br>
    <br>
    // Björn-Egil<br>
    <br>
    <blockquote
cite="mid:CANt451kfg_u-5nemeiRAroQPerYh0qeKc7go+DVX6AZQM0W8YQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <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
            moz-do-not-send="true"
            href="http://www.erlang.org/doc/man/erl_driver.html#driver_select">http://www.erlang.org/doc/man/erl_driver.html#driver_select</a></div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>