cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re:Re: Failed writing body (-1 != 16384)

From: 兰天 <lantian0811_at_163.com>
Date: Thu, 12 Mar 2015 14:38:58 +0800 (CST)

在 2015-03-12 13:44:27,"Ray Satiro via curl-library" <curl-library_at_cool.haxx.se> 写道:
On 3/11/2015 12:35 PM, 兰天 wrote:

My write callback function is follow:int Writer(char *data, size_t size, size_t nmemb, void *stream){ CURL_DATA_INFO *out = (CURL_DATA_INFO *) stream; unsigned int uiSizes = size * nmemb;unsigned int uiLoadContentLen = 0; if (NULL == out || 0 == size || 0 == nmemb){LOG_ERR("NULL == out || 0 == size || 0 == nmemb");//return -1; }
if ( uiSizes <= out->uiBufLen - out->uiWriteBufLen){//LOG_DBG("uiSizes:%u,buffer length:%u,writen lengh:%u",uiSizes,out->uiBufLen, out->uiWriteBufLen); memcpy(out->pszDownBuf + out->uiWriteBufLen, data, uiSizes);out->uiWriteBufLen += uiSizes;if(out->uiWriteBufLen > out->uiBufLen){LOG_ERR("invalid write buf len:%u", out->uiWriteBufLen);}uiLoadContentLen = uiSizes;return uiLoadContentLen;}else{LOG_ERR("too large file, size=%u, writen=%u", uiSizes, out->uiWriteBufLen);//return -2;}//return 0;}after I running the program for 2 hours ,the programe stop with the follow infomations:* Failed writing body (1 != 16384)* Closing connection #21* Failed writing body (1 != 16384)* Closing connection #7* Operation timed out after 40000 milliseconds with 186810 out of 269621 bytes received* Closing connection #58

Thank you for not top posting however your mail client is now garbling the quoting. The e-mail you sent makes your reply look like it's a reply I made. You may be able to fix that by hitting enter twice below whatever you've quoted.

As I said you need to review CURLOPT_WRITEFUNCTION [1]. Your function prototype should be:

size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);

Your callback must always return a value and it's not doing that. Also you need to properly handle 0 bytes, for example if(!uiSizes) return 0.

I'm still curious what version of libcurl is actually loaded here. If you could dump the version as I showed in my previous e-mail that would help.

thank you for answering , my libcurl version is 7.36 ,this version is ok? and I am testing.....best regards.....

[1]: http://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-03-12