Erlang Port Drivers and Erl functions

Casper casper2000a@REDACTED
Wed Dec 22 07:13:47 CET 2004


Hi All,

 

I'm developing a Erlang <-> C port using Port Drivers. As per the
communication message, I try to use Erl_Interface functions for easy message
encoding/decoding. But the program generates a segmentation fault.

 

Below are the details I do.

 

Start Port Driver:

            Port = open_port({spawn, './lib.so'}, []),                %%
inside a spawned process

 

Send a message to the C Port:

            Port ! {self(), {command, term_to_binary(Msg)}},  %% binary
encode the message

 

Receive the message in the C Port:

            static void nmslib_drv_output(ErlDrvData handle, char *buff, int
bufflen) {

                        ETERM *tuple;

                        tuple = erl_decode(buff);

 

As soon as I do the erl_decode, the program gets segmentation fault. As I
suspect, the buff doesn't have the correct message format that erl_decode
expect. Could anybody kindly advice me what's that difference.

 

If I don't use erl_decode, inside the C Port, the Port Driver works without
any problems.

 

Thanks in advance!

Eranga

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20041222/736d4aea/attachment.htm>


More information about the erlang-questions mailing list