[erlang-questions] What is the best way to parse complex erlang terms in port drivers?

Björn-Egil Dahlberg wallentin.dahlberg@REDACTED
Fri Jun 8 22:09:38 CEST 2012


First, I would like to say.:Yes, the erl_interface documentation is lacking
in details and examples.

Secondly, I would like to reframe your question. Should I use erl_interface
to communicate with my port driver in the first place? Many examples point
to that fact but I would disagree.

erl_interface, (ei), should be used for c-nodes where we want to talk to
our c-program over erlang distribution. When I want my c-program to
simulate an erlang node. This is, I think, a rare case though.

In most situations I would construct a packet protocol instead and handle
this protocol on the erlang side with bitsyntax. Handling "c-data" in
erlang is much easier than using erlang terms in c. Look at efile_drv and
inet_drv, none of those use erl_interface. The protocol becomes far simpler
and probably faster.

We have only one other case where it makes sense to encode and decode terms
in c and that is when our data are in the erlang process heap, i.e. when we
use NIFs. But, in this case we have an entirely different API so we
wouldn't use ei here either.

So, while I agree that ei could be better documented, I question if you
really need it. I think it complicates more things than it solves.

// Björn-Egil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120608/7b8a8c16/attachment.htm>


More information about the erlang-questions mailing list