[Freeswitch-users] Spidermokey_curl problem? Sanity check please

Michael Jerris mike at jerris.com
Tue Jul 15 18:31:06 PDT 2008


The analysis looks good, but how in the API do we know when the  
response is complete?  Can you please open a bug on  
jira.freeswitch.org for this so we can track it.

Thanks
Mike

On Jul 15, 2008, at 8:12 PM, "Simon Tang" <simon at airg.com> wrote:

> Hello,
>
>
>
> I’ve been making Javascript curl requests and have found that larger 
>  requests sometimes come back incomplete.  This is what I am doing i 
> n javascript:
>
> ------------
>
> function callback(string, arg)
>
> {
>
>     console_log("info", "returned body:" + string + "\n");
>
>     return true;
>
> }
>
>
>
> var curl = new CURL();
>
> var blah = curl.run("GET", url, args, callback, arg, "");
>
> --------------
>
>
>
> comparing ‘string’ with tcpdump, I found that ‘string’ is  
> definitely incomplete vs. tcpdump.
>
>
>
> I’ve looked into spidermokey_curl.c and found this code (excerpts):
>
>
>
> static size_t file_callback(void *ptr, size_t size, size_t nmemb,  
> void *data)
>
> {…}
>
>
>
> curl_easy_setopt(co->curl_handle, CURLOPT_WRITEFUNCTION,  
> file_callback);
>
> curl_easy_setopt(co->curl_handle, CURLOPT_WRITEDATA, (void *) co);
>
>
>
> I had the suspicion that the callback is getting a partial response  
> and passing it into the JS object as a completed response:
>
>
>
> -          From http://curl.netmirror.org/libcurl/c/curl_easy_setopt.html 
> : “The callback function will be passed as much data as possible in  
> all invokes, but you cannot possibly make any assumptions. It may be 
>  one byte, it may be thousands. The maximum amount of data that can  
> be passed to the write callback is defined in the curl.h header file 
> : CURL_MAX_WRITE_SIZE.”  >From this, I think that it is the callback 
> ’s responsibility to ensure that the complete response was received  
> and to save the data somewhere.
>
>
>
> To confirm my suspicion, I replaced the callback function in  
> spidermonkey_curl.c with vanilla logging and took out the JSAPI  
> references:
>
>
>
> static size_t file_callback(void *ptr, size_t size, size_t nmemb,  
> void *data)
>
> {
>
>     register unsigned int realsize = (unsigned int) (size * nmemb);
>
> switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"BODY  
> STUFF::::::%s\n", (char*) ptr);
>
> return realsize;
>
> }
>
>
>
> I recompiled and reproduced the offending http request.  I found  
> that the log is called twice, with each log comprising both pieces  
> of the complete response.  When I reverted back to the original  
> file_callback function and added a log in there, the log only  
> recorded the first part of the response (incomplete).
>
>
>
> I’m not sure if I’m using this correctly or if my analysis is  
> correct, so if someone can provide me some feedback, that’d be great 
> .  If it’s a legit bug, I can file it.
>
>
>
> Simon Tang
>
> _______________________________________________
> Freeswitch-users mailing list
> Freeswitch-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20080715/0719a3c7/attachment-0002.html 


More information about the FreeSWITCH-users mailing list