1 /*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel (at) 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 <fcntl.h> 25 26 #include "testutil.h" 27 #include "warnless.h" 28 #include "memdebug.h" 29 30 #define TEST_HANG_TIMEOUT 60 * 1000 31 32 static int perform(CURLM *multi) 33 { 34 int handles; 35 fd_set fdread, fdwrite, fdexcep; 36 int res = 0; 37 38 for(;;) { 39 struct timeval interval; 40 int maxfd = -99; 41 42 interval.tv_sec = 0; 43 interval.tv_usec = 100000L; /* 100 ms */ 44 45 res_multi_perform(multi, &handles); 46 if(res) 47 return res; 48 49 res_test_timedout(); 50 if(res) 51 return res; 52 53 if(!handles) 54 break; /* done */ 55 56 FD_ZERO(&fdread); 57 FD_ZERO(&fdwrite); 58 FD_ZERO(&fdexcep); 59 60 res_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); 61 if(res) 62 return res; 63 64 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 65 66 res_select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval); 67 if(res) 68 return res; 69 70 res_test_timedout(); 71 if(res) 72 return res; 73 } 74 75 return 0; /* success */ 76 } 77 78 int test(char *URL) 79 { 80 CURLM *multi = NULL; 81 CURL *easy = NULL; 82 int res = 0; 83 84 start_test_timing(); 85 86 global_init(CURL_GLOBAL_ALL); 87 88 multi_init(multi); 89 90 easy_init(easy); 91 92 multi_setopt(multi, CURLMOPT_PIPELINING, 1L); 93 94 easy_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite); 95 easy_setopt(easy, CURLOPT_FAILONERROR, 1L); 96 easy_setopt(easy, CURLOPT_URL, URL); 97 98 res_multi_add_handle(multi, easy); 99 if(res) { 100 printf("curl_multi_add_handle() 1 failed\n"); 101 goto test_cleanup; 102 } 103 104 res = perform(multi); 105 if(res) { 106 printf("retrieve 1 failed\n"); 107 goto test_cleanup; 108 } 109 110 curl_multi_remove_handle(multi, easy); 111 112 curl_easy_reset(easy); 113 114 easy_setopt(easy, CURLOPT_FAILONERROR, 1L); 115 easy_setopt(easy, CURLOPT_URL, libtest_arg2); 116 117 res_multi_add_handle(multi, easy); 118 if(res) { 119 printf("curl_multi_add_handle() 2 failed\n"); 120 goto test_cleanup; 121 } 122 123 res = perform(multi); 124 if(res) { 125 printf("retrieve 2 failed\n"); 126 goto test_cleanup; 127 } 128 129 curl_multi_remove_handle(multi, easy); 130 131 test_cleanup: 132 133 /* undocumented cleanup sequence - type UB */ 134 135 curl_easy_cleanup(easy); 136 curl_multi_cleanup(multi); 137 curl_global_cleanup(); 138 139 printf("Finished!\n"); 140 141 return res; 142 } 143