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 "warnless.h" 26#include "memdebug.h" 27 28#define TEST_HANG_TIMEOUT 60 * 1000 29 30#define NUM_HANDLES 4 31 32int test(char *URL) 33{ 34 int res = 0; 35 CURL *curl[NUM_HANDLES]; 36 int running; 37 CURLM *m = NULL; 38 int i; 39 char target_url[256]; 40 41 for(i=0; i < NUM_HANDLES; i++) 42 curl[i] = NULL; 43 44 start_test_timing(); 45 46 global_init(CURL_GLOBAL_ALL); 47 48 multi_init(m); 49 50 /* get NUM_HANDLES easy handles */ 51 for(i=0; i < NUM_HANDLES; i++) { 52 /* get an easy handle */ 53 easy_init(curl[i]); 54 /* specify target */ 55 sprintf(target_url, "%s%04i", URL, i + 1); 56 target_url[sizeof(target_url) - 1] = '\0'; 57 easy_setopt(curl[i], CURLOPT_URL, target_url); 58 /* go verbose */ 59 easy_setopt(curl[i], CURLOPT_VERBOSE, 1L); 60 /* include headers */ 61 easy_setopt(curl[i], CURLOPT_HEADER, 1L); 62 /* add handle to multi */ 63 multi_add_handle(m, curl[i]); 64 } 65 66 multi_setopt(m, CURLMOPT_PIPELINING, 1L); 67 68 fprintf(stderr, "Start at URL 0\n"); 69 70 for(;;) { 71 struct timeval interval; 72 fd_set rd, wr, exc; 73 int maxfd = -99; 74 75 interval.tv_sec = 1; 76 interval.tv_usec = 0; 77 78 multi_perform(m, &running); 79 80 abort_on_test_timeout(); 81 82 if(!running) 83 break; /* done */ 84 85 FD_ZERO(&rd); 86 FD_ZERO(&wr); 87 FD_ZERO(&exc); 88 89 multi_fdset(m, &rd, &wr, &exc, &maxfd); 90 91 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 92 93 select_test(maxfd+1, &rd, &wr, &exc, &interval); 94 95 abort_on_test_timeout(); 96 } 97 98test_cleanup: 99 100 /* proper cleanup sequence - type PB */ 101 102 for(i=0; i < NUM_HANDLES; i++) { 103 curl_multi_remove_handle(m, curl[i]); 104 curl_easy_cleanup(curl[i]); 105 } 106 107 curl_multi_cleanup(m); 108 curl_global_cleanup(); 109 110 return res; 111} 112