mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
made it work
made it cause less compiler warnings made it require 7.9.7 to build
This commit is contained in:
parent
2b054e5309
commit
173b35eaf8
@ -22,10 +22,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <curl/curl.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 {
|
struct data {
|
||||||
int type;
|
int type;
|
||||||
@ -34,8 +37,8 @@ struct data {
|
|||||||
FILE *file;
|
FILE *file;
|
||||||
} handle;
|
} handle;
|
||||||
|
|
||||||
/* TODO: We should perhaps document the biggest possible buffer chunk we can
|
/* This is the documented biggest possible buffer chunk we can get from
|
||||||
get from libcurl in one single callback... */
|
libcurl in one single callback! */
|
||||||
char buffer[CURL_MAX_WRITE_SIZE];
|
char buffer[CURL_MAX_WRITE_SIZE];
|
||||||
|
|
||||||
char *readptr; /* read from here */
|
char *readptr; /* read from here */
|
||||||
@ -62,6 +65,8 @@ size_t write_callback(char *buffer,
|
|||||||
url->readptr += size;
|
url->readptr += size;
|
||||||
url->bytes += size;
|
url->bytes += size;
|
||||||
|
|
||||||
|
fprintf(stderr, "callback %d size bytes\n", size);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,6 +77,7 @@ URL_FILE *url_fopen(char *url, char *operation)
|
|||||||
|
|
||||||
URL_FILE *file;
|
URL_FILE *file;
|
||||||
int still_running;
|
int still_running;
|
||||||
|
(void)operation;
|
||||||
|
|
||||||
file = (URL_FILE *)malloc(sizeof(URL_FILE));
|
file = (URL_FILE *)malloc(sizeof(URL_FILE));
|
||||||
if(!file)
|
if(!file)
|
||||||
@ -134,47 +140,51 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!still_running) {
|
if(!still_running) {
|
||||||
printf("NO MORE RUNNING AROUND!\n");
|
printf("DONE RUNNING AROUND!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FD_ZERO(&fdread);
|
do {
|
||||||
FD_ZERO(&fdwrite);
|
|
||||||
FD_ZERO(&fdexcep);
|
|
||||||
|
|
||||||
/* set a suitable timeout to fail on */
|
FD_ZERO(&fdread);
|
||||||
timeout.tv_sec = 500; /* 5 minutes */
|
FD_ZERO(&fdwrite);
|
||||||
timeout.tv_usec = 0;
|
FD_ZERO(&fdexcep);
|
||||||
|
|
||||||
/* get file descriptors from the transfers */
|
/* set a suitable timeout to fail on */
|
||||||
curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
|
timeout.tv_sec = 500; /* 5 minutes */
|
||||||
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
|
/* get file descriptors from the transfers */
|
||||||
|
curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
|
||||||
|
|
||||||
switch(rc) {
|
rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
|
||||||
case -1:
|
|
||||||
/* select error */
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* timeout or readable/writable sockets */
|
|
||||||
do {
|
|
||||||
file->m = curl_multi_perform(multi_handle, &still_running);
|
|
||||||
|
|
||||||
if(file->bytes)
|
switch(rc) {
|
||||||
/* we have received data, return that now */
|
case -1:
|
||||||
break;
|
/* select error */
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* timeout or readable/writable sockets */
|
||||||
|
printf("select() returned %d!\n", rc);
|
||||||
|
do {
|
||||||
|
file->m = curl_multi_perform(multi_handle, &still_running);
|
||||||
|
|
||||||
} while(CURLM_CALL_MULTI_PERFORM == file->m);
|
if(file->bytes)
|
||||||
|
/* we have received data, return that now */
|
||||||
|
break;
|
||||||
|
|
||||||
|
} while(CURLM_CALL_MULTI_PERFORM == file->m);
|
||||||
|
|
||||||
|
|
||||||
if(!still_running)
|
if(!still_running)
|
||||||
printf("NO MORE RUNNING AROUND!\n");
|
printf("DONE RUNNING AROUND!\n");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} while(still_running && (file->bytes <= 0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf("(fread) Skip network read\n");
|
printf("(fread) Skip network read\n");
|
||||||
@ -204,7 +214,10 @@ int main(int argc, char *argv[])
|
|||||||
int nread;
|
int nread;
|
||||||
char buffer[256];
|
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) {
|
if(!handle) {
|
||||||
printf("couldn't url_fopen()\n");
|
printf("couldn't url_fopen()\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user