+ mret = curl_multi_add_handle(multi_handle, curl_handle);
+ if (mret != CURLM_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_add_handle", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return -1;
+ }
+
+ while(CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi_handle, &still_running));
+
+ while(still_running)
+ {
+ struct timeval timeout;
+ int rc; /* select() return code */
+
+ fd_set fdread;
+ fd_set fdwrite;
+ fd_set fdexcep;
+ int maxfd = -1;
+
+ FD_ZERO(&fdread);
+ FD_ZERO(&fdwrite);
+ FD_ZERO(&fdexcep);
+
+ /* set a suitable timeout to play around with */
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ /* get file descriptors from the transfers */
+ mret = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
+ if (mret != CURLM_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_fdset", __FILE__, __LINE__,
+ curl_multi_strerror (mret));
+ return -1;
+ }
+
+ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ switch(rc)
+ {
+ case -1:
+ /* select error */
+ break;
+ case 0:
+ /* timeout, do something else */
+ break;
+ default:
+ /* one or more of curl's file descriptors say there's data to read
+ or write */
+ while(CURLM_CALL_MULTI_PERFORM ==
+ curl_multi_perform(multi_handle, &still_running));
+ break;
+ }
+ }
+
+ /* See how the transfers went */
+ while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
+ if (msg->msg == CURLMSG_DONE) {
+ int idx, found = 0;
+
+ /* Find out which handle this message is about */
+ for (idx=0; idx<1; idx++) {
+ found = (msg->easy_handle == curl_handle);
+ if(found)
+ break;
+ }
+
+ switch (idx) {
+ case 0:
+ printf("HTTP transfer completed with status %d\n", msg->data.result);
+ break;
+ }
+ }
+ }
+
+