[erlang-questions] C Ports - how to deal wth C function pointers ?
Oscar Hellström
oscar@REDACTED
Mon Apr 23 10:48:27 CEST 2007
Roberto Saccon wrote:
> I am experimenting with port drivers (building a port driver for cairo
> graphics library). Everything goes well as long as I pass simple
> arguments to call my c library.
>
> But I need to pass a function pointer to the library. And here comes my
> problem. The c library now calls that function. How can I pass its
> result back to Erlang ? Is there a way the c-side can initiate the
> communication ?
You can send messages back to the process owning the port, using
driver_output, driver_output_term and a few more
(http://www.erlang.org/doc/doc-5.5.3/erts-5.5.3/doc/html/erl_driver.html).
Be aware though that this must be done from the main thread (the same as
the emulator runs in) and not by any threads started by using either
driver_async or pthreads etc. This makes it a bit troublesome working
with C-code that can do blocking calls. If you need to store pointers,
which the Erlang side should not see, you can you create space for this
in your driver data structure.
There has also been some discussion earlier on this subject of using
C-nodes,
(http://www.erlang.org/pipermail/erlang-questions/2007-April/025877.html),
more can be found by a quick search through the archives.
> regards
> --
> Roberto Saccon
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
Best Regards
--
Oscar Hellström, oscar@REDACTED
Erlang Training and Consulting
http://www.erlang-consulting.com/
More information about the erlang-questions
mailing list