9 #include "zypp/base/Exception.h"
10 #include "zypp/base/Logger.h"
11 #include "zypp/Pathname.h"
12 #include "zypp/ExternalProgram.cc"
18 size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
20 MIL << "got data : " << size*nmemb << " bytes" << endl;
24 int socket_callback(CURL *easy, curl_socket_t s, int what, void *userp, void *socketp)
26 MIL << "socket : " << s << " : " << what << endl;
32 Range( off_t f, off_t t)
42 FILE *f = fopen("piece", "w" );
43 curl_global_init(CURL_GLOBAL_ALL);
45 curlm = curl_multi_init();
46 //curl_multi_setopt( curlm, CURLMOPT_PIPELINING, 1);
47 curl_multi_setopt( curlm, CURLMOPT_SOCKETFUNCTION, socket_callback);
57 for ( ; i < 10; i++ ) {
59 curl = curl_easy_init();
61 // http://download.opensuse.org/distribution/10.2/repo/oss/suse/setup/descr/packages
62 if ( (success = curl_easy_setopt(curl, CURLOPT_URL, "http://ftp5.gwdg.de/pub/opensuse/distribution/10.2/repo/oss/suse/setup/descr/packages")) != CURLE_OK)
63 ZYPP_THROW(Exception("url"));
65 if ( (success = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data)) != CURLE_OK)
66 ZYPP_THROW(Exception("write data"));
67 //curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);
71 rs << ( k!=1 ? "," : "") << (i*k)*1000 << "-" << ((i*k)*1000 + 1000);
73 MIL << "range: " << rs.str() << endl;
74 if ( (success = curl_easy_setopt(curl, CURLOPT_RANGE, rs.str().c_str())) != CURLE_OK)
75 ZYPP_THROW(Exception("write data"));
78 if ( (code = curl_multi_add_handle( curlm, curl)) != CURLM_OK)
79 ZYPP_THROW(Exception("write data"));
82 int still_running = 0;
83 /* we start some action by calling perform right away */
84 while(CURLM_CALL_MULTI_PERFORM ==
85 curl_multi_perform(curlm, &still_running));
87 while(still_running) {
88 struct timeval timeout;
89 int rc; /* select() return code */
100 /* set a suitable timeout to play around with */
104 /* get file descriptors from the transfers */
105 curl_multi_fdset(curlm, &fdread, &fdwrite, &fdexcep, &maxfd);
107 /* In a real-world program you OF COURSE check the return code of the
108 function calls, *and* you make sure that maxfd is bigger than -1 so
109 that the call to select() below makes sense! */
111 rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
117 ERR << "select() returns error, this is badness" << endl;
121 /* timeout or readable/writable sockets */
122 while(CURLM_CALL_MULTI_PERFORM ==
123 curl_multi_perform(curlm, &still_running));
130 while ( m = curl_multi_info_read( curlm, &c) )
132 MIL<< m->msg << " : " << curl_easy_strerror(m->data.result) << endl;
134 Pathname root("/home/duncan/suse/metadata-diff");
137 curl_multi_cleanup(curlm);
138 //curl_easy_cleanup(http_handle);