Hi All<br>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<br>
to fail. If I remove this function erl_ddll:load_driver works fine. I<br>
have isolated the issue to the following 2 lines in the function<br>
ei_x_new_with_version(&x_buff);<br><div class="Ih2E3d">
ret = ei_x_encode_string(&x_buff,arg1);<br>
<br>
Commenting these 2 lines,results in erl_ddll:load_driver working<br>
find.I need some help to understand if I am doing something wrong. Any help<br>
would be appreciated.<br>
<br>
The code for the control function is<br>
<br>
static int example_drv_control(ErlDrvData example_data,unsigned int<br>
command,char *buf,int len, char **rbuf, int rlen){<br>
int ret = -1;<br>
char *arg1;<br>
ei_x_buff x_buff;<br>
arg1 = (char *)malloc(sizeof(char) * (len+1));<br>
logmessage("In control");<br>
strncpy(arg1,buf,len);<br>
strcat(arg1,"\0");<br>
logmessage(arg1);<br>
ei_x_new_with_version(&x_buff);<br>
<br>
strcat(arg1,"ASDF");<br>
ret = ei_x_encode_string(&x_buff,arg1);<br>
*rbuf = (char*)ei_x_to_new_binary(&x_buff);<br>
return ret;<br>
}</div>