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
 
@@ -73,13 +73,12 @@ for(counter=0; counter<argc; counter++){
 
			fprintf(stderr,"Please try again! :D\n");
 
			return 0;
 
		}
 
	}
 
/* End arg parser */
 

	
 

	
 
/* Option getter: Creates vars to grab stuff from conf, uses the options include to grab this data */
 
char *username;
 
char *datadir;
 
cfg_t * my_cfg;
 
cfg_opt_t myopts[] = {
 
		CFG_SIMPLE_STR("username", &username),
 
@@ -190,13 +189,13 @@ if(gotframe ==1)
 
    else{
 
      fprintf(stderr,"I think the XML craziness may have failed, so I'll terminate just for fun.\n");
 
      return 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
 

	
 

	
 
     exec_blender(&myjob, pathtoJobfile, pathtoOutput, framenum); // @TODO: This warning should be fixed :D
 

	
 
    // Consider placing the following in the exec_blender() function
src/server/slavefuncs.c
Show inline comments
 
@@ -75,28 +75,41 @@ void tell_the_server(char *stuff){
 
/** Function referenced by curlget() to write data to disk. */
 
size_t curl_writetodisk(void *ptr, size_t size, size_t nmemb, FILE *stream)
 
 {
 
    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;
 

	
 
  curl = curl_easy_init();
 
  if(curl) {
 
	outfile = fopen(out, "w"); // Open where we're writing to
 

	
 
  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
 
}
 

	
 
/** Posts a file to a url with cUrl */
 
int curlpost(char *filename, char *url){
 
  char *targetname = "uploadedfile"; // Name of the target in the php file on the server (Don't change me unless you have different PHP code)
0 comments (0 inline, 0 general)