1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. 9 * 10 * This software is licensed as described in the file COPYING, which 11 * you should have received as part of this distribution. The terms 12 * are also available at http://curl.haxx.se/docs/copyright.html. 13 * 14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 * copies of the Software, and permit persons to whom the Software is 16 * furnished to do so, under the terms of the COPYING file. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 ***************************************************************************/ 22#include "test.h" 23 24#include "testutil.h" 25#include "memdebug.h" 26 27#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000 28#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000 29 30/* 31 * Get a single URL without select(). 32 */ 33 34int test(char *URL) 35{ 36 CURL *c; 37 CURLM *m = NULL; 38 int res = 0; 39 int running=1; 40 struct timeval mp_start; 41 char mp_timedout = FALSE; 42 43 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { 44 fprintf(stderr, "curl_global_init() failed\n"); 45 return TEST_ERR_MAJOR_BAD; 46 } 47 48 if ((c = curl_easy_init()) == NULL) { 49 fprintf(stderr, "curl_easy_init() failed\n"); 50 curl_global_cleanup(); 51 return TEST_ERR_MAJOR_BAD; 52 } 53 54 test_setopt(c, CURLOPT_URL, URL); 55 56 if ((m = curl_multi_init()) == NULL) { 57 fprintf(stderr, "curl_multi_init() failed\n"); 58 curl_easy_cleanup(c); 59 curl_global_cleanup(); 60 return TEST_ERR_MAJOR_BAD; 61 } 62 63 if ((res = (int)curl_multi_add_handle(m, c)) != CURLM_OK) { 64 fprintf(stderr, "curl_multi_add_handle() failed, " 65 "with code %d\n", res); 66 curl_multi_cleanup(m); 67 curl_easy_cleanup(c); 68 curl_global_cleanup(); 69 return TEST_ERR_MAJOR_BAD; 70 } 71 72 mp_timedout = FALSE; 73 mp_start = tutil_tvnow(); 74 75 while (running) { 76 res = (int)curl_multi_perform(m, &running); 77 if (tutil_tvdiff(tutil_tvnow(), mp_start) > 78 MULTI_PERFORM_HANG_TIMEOUT) { 79 mp_timedout = TRUE; 80 break; 81 } 82 if (running <= 0) { 83 fprintf(stderr, "nothing left running.\n"); 84 break; 85 } 86 } 87 88 if (mp_timedout) { 89 if (mp_timedout) fprintf(stderr, "mp_timedout\n"); 90 fprintf(stderr, "ABORTING TEST, since it seems " 91 "that it would have run forever.\n"); 92 res = TEST_ERR_RUNS_FOREVER; 93 } 94 95test_cleanup: 96 97 if(m) { 98 curl_multi_remove_handle(m, c); 99 curl_multi_cleanup(m); 100 } 101 curl_easy_cleanup(c); 102 curl_global_cleanup(); 103 104 return res; 105} 106 107