curl-library
progress hook question
Date: Mon, 3 May 2004 14:38:32 -0400
I am having a terrible time trapping valid progress information for sending or 
recieving a file. Here is what I have tried so far, any help, especially  
working minimal app code would be greatly appreciated.
1) tried the cutrlgtk sample app. Could not fully compile. used this command:
`curl-config --cc` `gtk-config --cflags` -o curlgtk curlgtk.c `curl-config 
--cflags --libs` `gtk-config --libs gthread gtk`
and I get this error:
: undefined reference to `g_thread_create'
collect2: ld returned 1 exit status
2)Tried making my own, command-line version based on the gtk sample, and it 
compiles fine, and uploads the file fine, but the callback function is always 
called with zeros. Note that the file uploads fine, regardless of the 
protocol used, ftp or http POST, but the output is always all zeros. here is 
the code I used:
----start code
#include <stdio.h> 
#include <curl/curl.h> 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
 
 int my_progress_func(void *nothing, double dltotal, double dlnow, double 
ultotal, double ulnow){ 
   printf("dltotal: %d, dlnow: %d, ultotal: %d, ulnow: %d \n", dltotal, dlnow, 
ultotal, ulnow); 
   return 0; 
 } 
 
int main(int argc, char *argv[]){ 
  CURL *curl; 
  CURLcode res; 
  FILE * hd_src ; 
  int hd ; 
  struct stat file_info; 
 
 
    /* get the file size of the local file */ 
      hd = open("test.dat", O_RDONLY) ; 
      fstat(hd, &file_info); 
      close(hd) ; 
 
    /* get a FILE * of the same file, could also be made with 
       fdopen() from the previous descriptor, but hey this is just  
       an example! */ 
    hd_src = fopen("test.dat", "rb"); 
 
 
 
  struct curl_httppost *formpost=NULL; 
  struct curl_httppost *lastptr=NULL; 
  struct curl_slist *headerlist=NULL; 
  char buf[] = "Expect:"; 
 
  //initialize 
  curl_global_init(CURL_GLOBAL_ALL); 
 
  //form data 
  curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "project", 
CURLFORM_FILE, "test.dat", CURLFORM_END); 
 
  //submit button 
  curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", 
CURLFORM_COPYCONTENTS, "send", CURLFORM_END); 
 
  //initialize 
  curl = curl_easy_init(); 
 
  //header list 
  headerlist = curl_slist_append(headerlist, buf); 
 
  if(curl) { 
 
   /* now specify which file to upload */ 
    curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); 
 
   /* and give the size of the upload (optional) */ 
   curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size); 
 
   // Tell libcurl that we want to upload: 
   curl_easy_setopt(easyhandle, CURLOPT_UPLOAD, TRUE); 
 
     curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); 
     curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func); 
     curl_easy_setopt(curl, CURLOPT_URL, "http://www.somewhere.com/test.cgi"); 
     curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); 
     curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); 
 
    //do it 
    res = curl_easy_perform(curl); 
 
    //cleanup 
    curl_easy_cleanup(curl); 
    curl_formfree(formpost); 
    curl_slist_free_all (headerlist); 
  } 
 
  fclose(hd_src); /* close the local file */ 
 
  return 0; 
} 
----end code
Note that I have sucessfully compiled and runn the curl application itself, 
with command line options to duplicate what I am trying to do,  and it shows 
progress correctly, so I do not think it is a platform or compiler issue.
Can anyone help with this?
Received on 2004-05-03