curl-library
Re: Issue With curl_easy_perform
Date: Fri, 31 Mar 2006 19:29:24 -0800 (PST)
Hello Saikat,
Not quite. You need to return the product of size and
nmemb, like this:
extern "C" size_t write_data(
void *source,
size_t size,
size_t nmemb,
void *userData)
{
return size * nmemb;
}
Take care,
Jeff
--- Saikat Kanjilal <sxk1969_at_hotmail.com> wrote:
> Hi Jeff:
> Thanks for responding,let me make sure I understand,
> are you saying do the
> following:
>
> /* libcurl callback function */
> extern "C" size_t * write_data(void *source
> ,size_t,size ,size_t nmemb ,void
> *userData);
>
>
> extern "C" size_t * write_data(void *source ,size_t
> size ,size_t nmemb ,void
> *userData)
> {
> size_t * retval;
> return retval;
> }
>
>
>
> Just out of curiosity is this because I am passing
> in the address of the
> function write_data in the CURLOPT_WRITEFUNCTION
>
>
> Thanks again for your help
> SK
>
>
> >From: Jeff Phillips <jeff_at_seasideresearch.com>
> >Reply-To: jeff_at_seasideresearch.com, libcurl
> development
> ><curl-library_at_cool.haxx.se>
> >To: libcurl development <curl-library_at_cool.haxx.se>
> >Subject: Re: Issue With curl_easy_perform
> >Date: Fri, 31 Mar 2006 17:14:07 -0800 (PST)
> >
> >Hello Saikat,
> >
> >Your implementation of write_data should return
> size *
> >nmemb, so that libcurl knows that your application
> has
> >processed the data.
> >
> >Take care,
> >Jeff Phillips
> >
> >--- Saikat Kanjilal <sxk1969_at_hotmail.com> wrote:
> >
> > > Hello All:
> > > I am trying to use libcurl to do a simple
> http_post,
> > > I have the code below,
> > > everything works like a charm except that
> > > curl_easy_perform keeps popping up
> > > this window, I have a callback function that I
> have
> > > written using
> > > CURLOPT_WRITEFUNCTION but that still does not
> make
> > > the dos window completely
> > > go away, any help on this would be much
> appreciated.
> > > I have been struggling
> > > with this for a day or so, any ideas??
> > >
> > >
> > >
> > > /* libcurl callback function */
> > > extern "C" size_t write_data(void *source
> ,size_t
> > > size ,size_t nmemb ,void
> > > *userData);
> > >
> > > extern "C" size_t write_data(void *source
> ,size_t
> > > size ,size_t nmemb ,void
> > > *userData)
> > > {
> > > size_t retval=0;
> > > std::cout<<"Inside write_data\n";
> > > return retval;
> > > }
> > >
> > >
> > > int MyClass::uploadFile(std::string
> URL,std::string
> > > path)
> > > {
> > > CURL *curl;
> > > CURLcode res;
> > >
> > > struct curl_httppost *formpost=NULL;
> > > struct curl_httppost *lastptr=NULL;
> > > struct curl_slist *headerlist=NULL;
> > > char buf[] = "Expect:";
> > > bool delFile = false;
> > >
> > > curl_global_init(CURL_GLOBAL_ALL);
> > >
> > > /* Fill in the file upload field */
> > > curl_formadd(&formpost,
> > > &lastptr,
> > > CURLFORM_COPYNAME, "sendfile",
> > > CURLFORM_FILE, path.c_str(),
> > > CURLFORM_END);
> > >
> > > /* Fill in the filename field */
> > > curl_formadd(&formpost,
> > > &lastptr,
> > > CURLFORM_COPYNAME, "filename",
> > > CURLFORM_COPYCONTENTS, path.c_str(),
> > > CURLFORM_END);
> > >
> > >
> > > /* Fill in the submit field too, even if
> this is
> > > rarely needed */
> > > curl_formadd(&formpost,
> > > &lastptr,
> > > CURLFORM_COPYNAME, "submit",
> > > CURLFORM_COPYCONTENTS, "send",
> > > CURLFORM_END);
> > >
> > > curl = curl_easy_init();
> > >
> > > /* initalize custom header list (stating that
> > > Expect: 100-continue is not
> > > wanted */
> > > headerlist = curl_slist_append(headerlist,
> buf);
> > >
> > > /* if we have a handle proceed with the
> transaction
> > > */
> > > if(curl)
> > > {
> > > curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
> > > &write_data);
> > >
> > > /* what URL that receives this POST */
> > > curl_easy_setopt(curl, CURLOPT_URL,
> URL.c_str());
> > > curl_easy_setopt(curl, CURLOPT_HTTPPOST,
> > > formpost);
> > > res = curl_easy_perform(curl);
> > >
> > > /* if the file was transported successfully we
> > > need to delete
> > > the file else wait a while and try to
> upload
> > > */
> > > if (res==CURLE_OK)
> > > delFile=true;
> > > else
> > > {
> > > /* if we are here we wait
> > > and try the upload again till we are
> > > successful
> > > for now we set this to 2 minutes
> > > later it will be configurable
> > > */
> > > Sleep(120000);
> > > uploadFile(URL,path);
> > > }
> > >
> > >
> > > /* cleanup */
> > > curl_easy_cleanup(curl);
> > >
> > > /* then cleanup the formpost chain */
> > > curl_formfree(formpost);
> > >
> > > /* free slist */
> > > curl_slist_free_all (headerlist);
> > > }
> > >
> > > if (delFile)
> > > DeleteLog(path);
> > > return res;
> > > }
> > >
> > > Thanks Again
> > >
> > >
> > >
> >
>
>
>
Received on 2006-04-01