Changeset - f597c84c5247
[Not reviewed]
default
0 2 0
ethanzonca - 16 years ago 2009-09-03 23:06:01

Added percentage feedback to cURL downloading
2 files changed with 14 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/server/slave.c
Show inline comments
 
@@ -76,7 +76,6 @@ for(counter=0; counter<argc; counter++){
 
	}
 
/* End arg parser */
 

	
 

	
 
/* Option getter: Creates vars to grab stuff from conf, uses the options include to grab this data */
 
char *username;
 
char *datadir;
 
@@ -193,7 +192,7 @@ if(gotframe ==1)
 
    }
 

	
 
    /* Variable-fillers which require XML */
 
    outputExt = myjob.outputFormat; /* @TODO: FIXME! */
 
    // outputExt = myjob.outputFormat; /* @TODO: FIXME! */
 
    _distren_asprintf(&pathtoOutput, "%s/job%d/output/frame%d.%s", datadir, jobnum, framenum, outputExt ); // Prepares the path to the jobfile
 

	
 

	
src/server/slavefuncs.c
Show inline comments
 
@@ -78,8 +78,17 @@ size_t curl_writetodisk(void *ptr, size_
 
    return fwrite(ptr, size, nmemb, stream);
 
  }
 

	
 
/** Helper function for cURL's progressbar */
 
int curl_progress( char *Bar,double t,double d,double ultotal,double ulnow)
 
{
 
fprintf(stderr,"Downloading... %f%% complete\r",d/t*100);
 
return 0;
 
}
 

	
 
/** Retrieves a URL with cURL and saves it to disk */
 
int curlget(char *url, char *out){
 

	
 
  double *Bar; // Stores cURL progressbar info
 
  CURL *curl;
 
  CURLcode res;
 
  FILE *outfile;
 
@@ -91,9 +100,13 @@ int curlget(char *url, char *out){
 
  curl_easy_setopt(curl, CURLOPT_URL, url);
 
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
 
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writetodisk); // this MUST be set for win32 compat.
 
  curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
 
  curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress);
 
  curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar);
 
  res = curl_easy_perform(curl);
 
  curl_easy_cleanup(curl);
 
  }
 
  fprintf(stderr,"\n"); // Clears out he progressbar's carriage return
 
  return res; // 0 means OK, nonzero means AAAH badness
 
}
 

	
0 comments (0 inline, 0 general)