curl-library
Re: libcurl.dll memory restriction??
Date: Sat, 22 Jan 2011 12:48:45 -0600
On Sat, Jan 22, 2011 at 7:11 AM, RaptorX wrote:
> My write function is writing the bytes correctly but the problem is that if
> i have a file that is 1MB in size i will still only get 1KB.
> any idea why is that happening?
> here is how the script lookslike:
>
>> #include ..\cURL.ahk
>>
>> ; --
>> if curl_global_init() ; Initialize cURL
>> {
>> msgbox % "Global Initialization Error"
>> ExitApp
>> }
>>
>> curl:=curl_easy_init() ; Create Session.
>> if (curl){
>> curl_easy_setopt(curl, "CURLOPT_WRITEFUNCTION",
>> RegisterCallBack("WriteFile")) ; Callback function.
>> curl_easy_setopt(curl, "CURLOPT_WRITEDATA",
>> hFile:=curl_CreateFile(a_desktop "\smartgui.zip"))
>>
>> curl_easy_setopt(curl, "CURLOPT_URL",
>> "http://www.autohotkey.com/download/smartgui.zip")
>> if res:=curl_easy_perform(curl)
>> msgbox % curl_easy_strerror(res) ; If res is not CURLE_OK (zero)
>> show a meaningful string for our error.
>>
>> cURL_Easy_GetInfo(curl, "CURLINFO_SPEED_DOWNLOAD", Var)
>> msgbox % var
>> }
>> curl_easy_cleanup(curl) ; End Session.
>> curl_global_cleanup() ; mandatory clean up for global
>> exitapp
>>
>>
>>
>> ; Callback function.
>> ; This can be personalized to suit your needs as defined here:
>> ; http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTWRITEFUNCTION
>> WriteFile(ptr, size, nmemb, userdata){
>> static
>> msgbox % size*nmemb ; it shows 1109
>> curl_WriteFile(userdata, ptr, size*nmemb, wsize)
>> msgbox % wsize ; it shows 1109 that means that all bytes were
>> written correctly.
>> curl_CloseHandle(hFile)
>> return
>> }
The curl library will use a properly implemented callback function
repeatedly until all data is received. So I can see at least two
problems with your callback - first, it closes the file handle, so
the next call will always fail. Also, I am not familiar with
autohotkey, but it looks like the callback doesn't return a value?
Check the documentation for CURLOPT_WRITEFUNCTION:
"Return the number of bytes actually taken care of. If that amount
differs from the amount passed to your function, it'll signal an
error to the library."
- Jeff
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-01-22