cURL / Mailing Lists / curl-library / Single Mail

curl-library

Issues on callback write_data

From: Gustavo Elias Siqueira <gumail_at_gmail.com>
Date: Fri, 23 Mar 2007 18:07:04 -0300

Hi Fellows,
I'm a beginner curl user, asking for a hand to solve a problem.
When I call curl to perform, the libcurl at the
first callback write_data, returns a buffer with 1100 and show a parcial
data.For the second time, the buffer returns me 1768, but theres no data
avaiable.

// Crawler.cpp : main project file.

#include <stdafx.h>
#include <iostream>
#include <curl/curl.h>
#include <Threads.h>

using namespace System;

struct MemoryStruct {
 char *memory;
 size_t size;
};

size_t write_data(void *ptr, size_t size, size_t nmemb, void *data) {
 register int realsize = size * nmemb;
 struct MemoryStruct *mem = (struct MemoryStruct *)data;
 mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
 if (mem->memory) {
  memcpy(&(mem->memory[mem->size]), ptr, realsize);
  mem->size += realsize;
  mem->memory[mem->size] = 0;
 }
 return realsize;
}

int main(array<System::String ^> ^args)
{

 CURL *curl;
 CURLcode res;

 curl_global_init(CURL_GLOBAL_ALL);
 curl = curl_easy_init();

 if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com.br");
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);

  res = curl_easy_perform(curl);
  curl_easy_cleanup(curl);
 }
 return 1;
}

Here's my enviroment:
Visual C++, CLR Console Application, getting libcurl by dll
Any idea would be great!
Thanks,
Gu
Received on 2007-03-23