Re: libcurl - help needed

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Greg,

I ported your code to Eu 3

include machine.e  
  
sequence ram_space 
integer ram_free_list, free_rid 
 
ram_space = {} 
ram_free_list = 0 
 
function malloc(object mem_struct_p) 
  integer temp_ 
 
  if atom(mem_struct_p) then 
    mem_struct_p = repeat(0, mem_struct_p) 
  end if 
  if ram_free_list = 0 then 
    ram_space = append(ram_space, mem_struct_p) 
    return length(ram_space) 
  end if 
   
  temp_ = ram_free_list 
  ram_free_list = ram_space[temp_] 
  ram_space[temp_] = mem_struct_p 
 
  return temp_ 
end function 
 
procedure free(atom mem_p) 
  if mem_p < 1 then return end if 
  if mem_p > length(ram_space) then return end if 
 
  ram_space[mem_p] = ram_free_list 
  ram_free_list = floor(mem_p) 
end procedure 
free_rid = routine_id("free") 
 
function curl_write_callback( atom ptr, atom size, atom nmemb, atom userdata )  
  atom realsize 
  sequence data 
 
  realsize = size * nmemb  
  data = peek({ ptr, realsize })  
 
  ram_space[userdata] = append( ram_space[userdata], data )  
 
  return realsize  
end function  
  
global function curl_easy_perform_ex( atom handle )  
  atom write_cb, userdata, result 
  sequence content 
   
  write_cb = call_back( routine_id("curl_write_callback") )  
  void = curl_easy_setopt( handle, CURLOPT_WRITEFUNCTION, write_cb )  
  
  userdata = malloc( "" )  
  void = curl_easy_setopt( handle, CURLOPT_WRITEDATA, userdata )  
  
  result = curl_easy_perform( handle )  
  content = ram_space[userdata]  
  
  free( userdata )  
  
  return {result,content}  
end function  

I got the same crash. Then I tried to replace

write_cb = call_back( routine_id("curl_write_callback") )

by

write_cb = call_back( { '+', routine_id("curl_write_callback")} )

and it doesn't crash anymore!

Thanks

Jean-Marc

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu