Skip to content

Commit

Permalink
Update examples to use the new microsecond timer API
Browse files Browse the repository at this point in the history
  • Loading branch information
pprindeville committed Apr 19, 2018
1 parent fd0dbd6 commit ada1661
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
25 changes: 14 additions & 11 deletions docs/examples/chkspeed.c
Expand Up @@ -165,33 +165,36 @@ int main(int argc, char *argv[])
res = curl_easy_perform(curl_handle);

if(CURLE_OK == res) {
double val;
curl_off_t val;

/* check for bytes downloaded */
res = curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &val);
res = curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD_T, &val);
if((CURLE_OK == res) && (val>0))
printf("Data downloaded: %0.0f bytes.\n", val);
printf("Data downloaded: %" CURL_FORMAT_CURL_OFF_T " bytes.\n", val);

/* check for total download time */
res = curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME, &val);
res = curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME_T, &val);
if((CURLE_OK == res) && (val>0))
printf("Total download time: %0.3f sec.\n", val);
printf("Total download time: %" CURL_FORMAT_TIME_TUPLE " sec.\n",
CURL_OFF_T_TO_TIMEVAL(val));

/* check for average download speed */
res = curl_easy_getinfo(curl_handle, CURLINFO_SPEED_DOWNLOAD, &val);
res = curl_easy_getinfo(curl_handle, CURLINFO_SPEED_DOWNLOAD_T, &val);
if((CURLE_OK == res) && (val>0))
printf("Average download speed: %0.3f kbyte/sec.\n", val / 1024);
printf("Average download speed: %" CURL_FORMAT_CURL_OFF_T " kbyte/sec.\n", val / 1024);

if(prtall) {
/* check for name resolution time */
res = curl_easy_getinfo(curl_handle, CURLINFO_NAMELOOKUP_TIME, &val);
res = curl_easy_getinfo(curl_handle, CURLINFO_NAMELOOKUP_TIME_T, &val);
if((CURLE_OK == res) && (val>0))
printf("Name lookup time: %0.3f sec.\n", val);
printf("Name lookup time: %" CURL_FORMAT_TIME_TUPLE " sec.\n",
CURL_OFF_T_TO_TIMEVAL(val));

/* check for connect time */
res = curl_easy_getinfo(curl_handle, CURLINFO_CONNECT_TIME, &val);
res = curl_easy_getinfo(curl_handle, CURLINFO_CONNECT_TIME_T, &val);
if((CURLE_OK == res) && (val>0))
printf("Connect time: %0.3f sec.\n", val);
printf("Connect time: %" CURL_FORMAT_TIME_TUPLE " sec.\n",
CURL_OFF_T_TO_TIMEVAL(val));
}
}
else {
Expand Down
10 changes: 5 additions & 5 deletions docs/examples/fileupload.c
Expand Up @@ -33,7 +33,7 @@ int main(void)
CURL *curl;
CURLcode res;
struct stat file_info;
double speed_upload, total_time;
curl_off_t speed_upload, total_time;
FILE *fd;

fd = fopen("debugit", "rb"); /* open file to upload */
Expand Down Expand Up @@ -72,11 +72,11 @@ int main(void)
}
else {
/* now extract transfer info */
curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD_T, &speed_upload);
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &total_time);

fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n",
speed_upload, total_time);
fprintf(stderr, "Speed: %" CURL_FORMAT_CURL_OFF_T " bytes/sec during %" CURL_FORMAT_TIME_TUPLE " seconds\n",
speed_upload, CURL_OFF_T_TO_TIMEVAL(total_time));

}
/* always cleanup */
Expand Down
10 changes: 5 additions & 5 deletions docs/examples/progressfunc.c
Expand Up @@ -28,10 +28,10 @@
#include <curl/curl.h>

#define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES 6000
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3000000

struct myprogress {
double lastruntime;
curl_off_t lastruntime;
CURL *curl;
};

Expand All @@ -42,16 +42,16 @@ static int xferinfo(void *p,
{
struct myprogress *myp = (struct myprogress *)p;
CURL *curl = myp->curl;
double curtime = 0;
curl_off_t curtime = 0;

curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime);
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &curtime);

/* under certain circumstances it may be desirable for certain functionality
to only run every N seconds, in order to do this the transaction time can
be used */
if((curtime - myp->lastruntime) >= MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL) {
myp->lastruntime = curtime;
fprintf(stderr, "TOTAL TIME: %f \r\n", curtime);
fprintf(stderr, "TOTAL TIME: %" CURL_FORMAT_TIME_TUPLE "\r\n", CURL_OFF_T_TO_TIMEVAL(curtime));
}

fprintf(stderr, "UP: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T
Expand Down

0 comments on commit ada1661

Please sign in to comment.