[erlang-questions] newbie question about port driver.

Salonee Sinha Roy ssroy1979@REDACTED
Tue Feb 3 01:01:27 CET 2009


Hi All
I am trying to port some perl code to erlang and for that I need to write a
port driver (linked-in driver) . I decided to go with this because I want to
execute the C code within the erlang process space. I am having issue with
the control function in the driver.   Adding the control function  to my C
code, causes erl_ddll:load_driver
to fail. If I remove this function erl_ddll:load_driver works fine. I
have isolated the issue to the following 2 lines in the function
 ei_x_new_with_version(&x_buff);
 ret = ei_x_encode_string(&x_buff,arg1);

Commenting these 2 lines,results in erl_ddll:load_driver working
find.I need some help to understand if I am doing something wrong. Any help
would be appreciated.

The code for the control function is

static int example_drv_control(ErlDrvData example_data,unsigned int
command,char *buf,int len, char **rbuf, int rlen){
 int ret = -1;
 char *arg1;
 ei_x_buff  x_buff;
 arg1 = (char *)malloc(sizeof(char) * (len+1));
 logmessage("In control");
 strncpy(arg1,buf,len);
 strcat(arg1,"\0");
 logmessage(arg1);
 ei_x_new_with_version(&x_buff);

 strcat(arg1,"ASDF");
 ret = ei_x_encode_string(&x_buff,arg1);
 *rbuf = (char*)ei_x_to_new_binary(&x_buff);
 return ret;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090202/8c9c2e83/attachment.htm>


More information about the erlang-questions mailing list