Skip to content

Instantly share code, notes, and snippets.

@kanazux
Created February 17, 2014 19:35
Show Gist options
  • Save kanazux/9057368 to your computer and use it in GitHub Desktop.
Save kanazux/9057368 to your computer and use it in GitHub Desktop.
newconsumer.c
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#define MAX_STRING_LEN 6000002
size_t read_data (char *bufptr, size_t size, size_t nitems, void *userp)
{
size_t read;
read = fread(bufptr, size, nitems, userp);
return read;
}
int main(void)
{
CURL *curl;
CURLcode res;
struct stat file_info;
char test[MAX_STRING_LEN];
long chSize;
double speed_upload, total_time;
char *ch = "0123456789ABCDEFGHIJKLMNOPQRSTUVXWYZ";
int size = strlen(ch) - 1;
for (int x = 0; x < 5150000;){
for (int i = 0; i <= size; ++i){
strcpy(&test[x],&ch[i]);
++x;
}
}
char word[] = "content=";
strcat(word,test);
FILE *fd = fopen("tteste","a");
fputs(word,fd);
fclose(fd);
exit(0);
FILE *nfd = fopen("tteste","r");
// http://speedtest.ntelecom.com.br/speedtest/random2000x2000.jpg
curl = curl_easy_init();
if(curl){
curl_easy_setopt(curl, CURLOPT_URL, "http://speedtest.ntelecom.com.br/speedtest/upload.php");
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READDATA, nfd);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
else {
curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
float upload = speed_upload / 1024 / 1024;
fprintf(stderr, "Upload Speed: %.2f MB/s\n", upload);
}
curl_easy_cleanup(curl);
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment