Skip to content

Instantly share code, notes, and snippets.

@bagder bagder/issue-3629.c
Created Feb 28, 2019

Embed
What would you like to do?
source example trying to reproduce curl issue #3629
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include <stdio.h>
#include <string.h>
/* somewhat unix-specific */
#include <sys/time.h>
#include <unistd.h>
/* curl stuff */
#include <curl/curl.h>
/*
* Simply download three HTTP files!
*/
int main(void)
{
CURL *http_handle1;
CURL *http_handle2;
CURL *http_handle3;
CURLM *multi_handle;
char error1[CURL_ERROR_SIZE];
char error2[CURL_ERROR_SIZE];
char error3[CURL_ERROR_SIZE];
int still_running = 3; /* keep number of running handles */
http_handle1 = curl_easy_init();
http_handle2 = curl_easy_init();
http_handle3 = curl_easy_init();
/* set options */
curl_easy_setopt(http_handle1, CURLOPT_URL, "https://www.example.com/");
curl_easy_setopt(http_handle2, CURLOPT_URL, "https://www.example.com/");
curl_easy_setopt(http_handle3, CURLOPT_URL, "https://www.example.com/");
curl_easy_setopt(http_handle1, CURLOPT_ERRORBUFFER, error1);
curl_easy_setopt(http_handle2, CURLOPT_ERRORBUFFER, error2);
curl_easy_setopt(http_handle3, CURLOPT_ERRORBUFFER, error3);
/* init a multi stack */
multi_handle = curl_multi_init();
/* add the individual transfers */
curl_multi_add_handle(multi_handle, http_handle1);
curl_multi_add_handle(multi_handle, http_handle2);
curl_multi_add_handle(multi_handle, http_handle3);
while(still_running) {
(void) curl_multi_wait(multi_handle, NULL, 0, 1000, NULL);
(void) curl_multi_perform(multi_handle, &still_running);
}
curl_multi_cleanup(multi_handle);
curl_easy_cleanup(http_handle1);
curl_easy_cleanup(http_handle2);
curl_easy_cleanup(http_handle3);
fprintf(stderr, "error1: '%s'\n", error1);
fprintf(stderr, "error2: '%s'\n", error2);
fprintf(stderr, "error3: '%s'\n", error3);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.