curl-library
Re: Use memory to ftp upload large image and got a bad performance
Date: Tue, 28 Apr 2009 19:40:40 +0800
>
> That's not what I said and it's not right either. Read the docs please.
> libcurl tells how much data it wants in each callback invoke.
>
Sorry, I didn't understand what your mean due to my poor english.
I try to understand the callback option CURLOPT_READFUNCTION in the
document.
And rewrite my callback function. If something wrong please correct me.
Many thanks
static size_t ReadMemoryCallback(void *ptr, size_t size, size_t nmemb, void
*pMem)
{
struct MemoryStruct *pRead = (struct MemoryStruct *)pMem;
size_t ReadLength = size * nmemb;
if (pRead->size >= ReadLength)
{
memcpy((char *)ptr, &pRead->memory[0], ReadLength);
pRead->memory += ReadLength;
pRead->size -= ReadLength;
return ReadLength;
}
else if ((pRead->size < ReadLength) && (pRead->size > 0))
{
size_t ReturnSize = pRead->size;
memcpy((char *)ptr, &pRead->memory[0], pRead->size);
pRead->memory += pRead->size;
pRead->size = 0;
return(ReturnSize);
}
else
return 0;
}
Received on 2009-04-28