Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdio.h>
00028 #include <string.h>
00029
00030
00031 #include <sys/time.h>
00032 #include <unistd.h>
00033
00034
00035 #include <curl/curl.h>
00036
00037 #ifdef _WIN32
00038 #define WAITMS(x) Sleep(x)
00039 #else
00040
00041 #define WAITMS(x) \
00042 struct timeval wait = { 0, (x) * 1000 }; \
00043 (void)select(0, NULL, NULL, NULL, &wait);
00044 #endif
00045
00046
00047
00048
00049 int main(void)
00050 {
00051 CURL *http_handle;
00052 CURLM *multi_handle;
00053
00054 int still_running;
00055 int repeats = 0;
00056
00057 curl_global_init(CURL_GLOBAL_DEFAULT);
00058
00059 http_handle = curl_easy_init();
00060
00061
00062 curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/");
00063
00064
00065 multi_handle = curl_multi_init();
00066
00067
00068 curl_multi_add_handle(multi_handle, http_handle);
00069
00070
00071 curl_multi_perform(multi_handle, &still_running);
00072
00073 do {
00074 CURLMcode mc;
00075 int numfds;
00076
00077
00078 mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
00079
00080 if(mc != CURLM_OK) {
00081 fprintf(stderr, "curl_multi_wait() failed, code %d.\n", mc);
00082 break;
00083 }
00084
00085
00086
00087
00088
00089
00090 if(!numfds) {
00091 repeats++;
00092 if(repeats > 1) {
00093 WAITMS(100);
00094 }
00095 }
00096 else
00097 repeats = 0;
00098
00099 curl_multi_perform(multi_handle, &still_running);
00100 } while(still_running);
00101
00102 curl_multi_remove_handle(multi_handle, http_handle);
00103
00104 curl_easy_cleanup(http_handle);
00105
00106 curl_multi_cleanup(multi_handle);
00107
00108 curl_global_cleanup();
00109
00110 return 0;
00111 }