Loading docs/examples/fopen.c +54 −41 Original line number Diff line number Diff line Loading @@ -22,10 +22,13 @@ #include <stdio.h> #include <string.h> #include <sys/time.h> #include <stdlib.h> #include <curl/curl.h> #include <curl/types.h> #include <curl/easy.h> #if (LIBCURL_VERSION_NUM < 0x070907) #error "too old libcurl version, get the latest!" #endif struct data { int type; Loading @@ -34,8 +37,8 @@ struct data { FILE *file; } handle; /* TODO: We should perhaps document the biggest possible buffer chunk we can get from libcurl in one single callback... */ /* This is the documented biggest possible buffer chunk we can get from libcurl in one single callback! */ char buffer[CURL_MAX_WRITE_SIZE]; char *readptr; /* read from here */ Loading @@ -62,6 +65,8 @@ size_t write_callback(char *buffer, url->readptr += size; url->bytes += size; fprintf(stderr, "callback %d size bytes\n", size); return size; } Loading @@ -72,6 +77,7 @@ URL_FILE *url_fopen(char *url, char *operation) URL_FILE *file; int still_running; (void)operation; file = (URL_FILE *)malloc(sizeof(URL_FILE)); if(!file) Loading Loading @@ -134,11 +140,13 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) } } if(!still_running) { printf("NO MORE RUNNING AROUND!\n"); printf("DONE RUNNING AROUND!\n"); return 0; } } do { FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); Loading @@ -160,6 +168,7 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) break; default: /* timeout or readable/writable sockets */ printf("select() returned %d!\n", rc); do { file->m = curl_multi_perform(multi_handle, &still_running); Loading @@ -171,10 +180,11 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) if(!still_running) printf("NO MORE RUNNING AROUND!\n"); printf("DONE RUNNING AROUND!\n"); break; } } while(still_running && (file->bytes <= 0)); } else printf("(fread) Skip network read\n"); Loading Loading @@ -204,7 +214,10 @@ int main(int argc, char *argv[]) int nread; char buffer[256]; handle = url_fopen("http://www.haxx.se", "r"); (void)argc; (void)argv; handle = url_fopen("http://curl.haxx.se/", "r"); if(!handle) { printf("couldn't url_fopen()\n"); Loading Loading
docs/examples/fopen.c +54 −41 Original line number Diff line number Diff line Loading @@ -22,10 +22,13 @@ #include <stdio.h> #include <string.h> #include <sys/time.h> #include <stdlib.h> #include <curl/curl.h> #include <curl/types.h> #include <curl/easy.h> #if (LIBCURL_VERSION_NUM < 0x070907) #error "too old libcurl version, get the latest!" #endif struct data { int type; Loading @@ -34,8 +37,8 @@ struct data { FILE *file; } handle; /* TODO: We should perhaps document the biggest possible buffer chunk we can get from libcurl in one single callback... */ /* This is the documented biggest possible buffer chunk we can get from libcurl in one single callback! */ char buffer[CURL_MAX_WRITE_SIZE]; char *readptr; /* read from here */ Loading @@ -62,6 +65,8 @@ size_t write_callback(char *buffer, url->readptr += size; url->bytes += size; fprintf(stderr, "callback %d size bytes\n", size); return size; } Loading @@ -72,6 +77,7 @@ URL_FILE *url_fopen(char *url, char *operation) URL_FILE *file; int still_running; (void)operation; file = (URL_FILE *)malloc(sizeof(URL_FILE)); if(!file) Loading Loading @@ -134,11 +140,13 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) } } if(!still_running) { printf("NO MORE RUNNING AROUND!\n"); printf("DONE RUNNING AROUND!\n"); return 0; } } do { FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); Loading @@ -160,6 +168,7 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) break; default: /* timeout or readable/writable sockets */ printf("select() returned %d!\n", rc); do { file->m = curl_multi_perform(multi_handle, &still_running); Loading @@ -171,10 +180,11 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) if(!still_running) printf("NO MORE RUNNING AROUND!\n"); printf("DONE RUNNING AROUND!\n"); break; } } while(still_running && (file->bytes <= 0)); } else printf("(fread) Skip network read\n"); Loading Loading @@ -204,7 +214,10 @@ int main(int argc, char *argv[]) int nread; char buffer[256]; handle = url_fopen("http://www.haxx.se", "r"); (void)argc; (void)argv; handle = url_fopen("http://curl.haxx.se/", "r"); if(!handle) { printf("couldn't url_fopen()\n"); Loading