1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2012, 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 "testtrace.h" 25#include "testutil.h" 26#include "warnless.h" 27#include "memdebug.h" 28 29#define TEST_HANG_TIMEOUT 60 * 1000 30 31/* 32 * Get a single URL without select(). 33 */ 34 35int test(char *URL) 36{ 37 CURL *c = NULL; 38 CURLM *m = NULL; 39 int res = 0; 40 int running = 1; 41 double connect_time = 0.0; 42 double dbl_epsilon; 43 44 dbl_epsilon = 1.0; 45 do { 46 dbl_epsilon /= 2.0; 47 } while ((double)(1.0 + (dbl_epsilon/2.0)) > (double)1.0); 48 49 start_test_timing(); 50 51 global_init(CURL_GLOBAL_ALL); 52 53 easy_init(c); 54 55 easy_setopt(c, CURLOPT_HEADER, 1L); 56 easy_setopt(c, CURLOPT_URL, URL); 57 58 libtest_debug_config.nohex = 1; 59 libtest_debug_config.tracetime = 1; 60 easy_setopt(c, CURLOPT_DEBUGDATA, &libtest_debug_config); 61 easy_setopt(c, CURLOPT_DEBUGFUNCTION, libtest_debug_cb); 62 easy_setopt(c, CURLOPT_VERBOSE, 1L); 63 64 multi_init(m); 65 66 multi_add_handle(m, c); 67 68 while (running) { 69 struct timeval timeout; 70 fd_set fdread, fdwrite, fdexcep; 71 int maxfd = -99; 72 73 timeout.tv_sec = 0; 74 timeout.tv_usec = 100000L; /* 100 ms */ 75 76 multi_perform(m, &running); 77 78 abort_on_test_timeout(); 79 80 if(!running) 81 break; /* done */ 82 83 FD_ZERO(&fdread); 84 FD_ZERO(&fdwrite); 85 FD_ZERO(&fdexcep); 86 87 multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd); 88 89 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 90 91 select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); 92 93 abort_on_test_timeout(); 94 } 95 96 curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time); 97 if (connect_time < dbl_epsilon) { 98 fprintf(stderr, "connect time is < epsilon\n"); 99 res = TEST_ERR_MAJOR_BAD; 100 } 101 102test_cleanup: 103 104 /* proper cleanup sequence - type PA */ 105 106 curl_multi_remove_handle(m, c); 107 curl_multi_cleanup(m); 108 curl_easy_cleanup(c); 109 curl_global_cleanup(); 110 111 return res; 112} 113 114