2011-03-10 05:48:02 -05:00
|
|
|
/***************************************************************************
|
2006-10-09 17:29:53 -04:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2011-03-10 05:48:02 -05:00
|
|
|
* Copyright (C) 1998 - 2011, 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 http://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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2006-10-09 17:29:53 -04:00
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2007-02-08 20:11:14 -05:00
|
|
|
#include "testutil.h"
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "warnless.h"
|
|
|
|
#include "memdebug.h"
|
2006-10-20 11:39:54 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
#define TEST_HANG_TIMEOUT 60 * 1000
|
2006-10-20 11:39:54 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
static int perform(CURLM *multi)
|
2006-10-09 17:29:53 -04:00
|
|
|
{
|
2010-04-24 06:14:21 -04:00
|
|
|
int handles;
|
2006-10-19 18:49:33 -04:00
|
|
|
fd_set fdread, fdwrite, fdexcep;
|
2011-10-21 10:26:18 -04:00
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
struct timeval interval;
|
|
|
|
int maxfd = -99;
|
|
|
|
|
|
|
|
interval.tv_sec = 0;
|
|
|
|
interval.tv_usec = 100000L; /* 100 ms */
|
|
|
|
|
|
|
|
res_multi_perform(multi, &handles);
|
|
|
|
if(res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res_test_timedout();
|
|
|
|
if(res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
if(!handles)
|
|
|
|
break; /* done */
|
2006-10-19 18:49:33 -04:00
|
|
|
|
|
|
|
FD_ZERO(&fdread);
|
|
|
|
FD_ZERO(&fdwrite);
|
|
|
|
FD_ZERO(&fdexcep);
|
2010-04-24 06:14:21 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
res_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
|
|
|
|
if(res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
|
2010-04-24 06:14:21 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
res_select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval);
|
|
|
|
if(res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res_test_timedout();
|
|
|
|
if(res)
|
|
|
|
return res;
|
2006-10-19 18:49:33 -04:00
|
|
|
}
|
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
return 0; /* success */
|
2006-10-09 17:29:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int test(char *URL)
|
|
|
|
{
|
2011-10-21 10:26:18 -04:00
|
|
|
CURLM *multi = NULL;
|
|
|
|
CURL *easy = NULL;
|
2007-05-02 02:02:13 -04:00
|
|
|
int res = 0;
|
2006-10-25 01:59:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
start_test_timing();
|
2006-10-25 01:59:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
global_init(CURL_GLOBAL_ALL);
|
2006-10-25 01:59:46 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
multi_init(multi);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
easy_init(easy);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
multi_setopt(multi, CURLMOPT_PIPELINING, 1L);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
easy_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
|
|
|
|
easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
|
|
|
|
easy_setopt(easy, CURLOPT_URL, URL);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
res_multi_add_handle(multi, easy);
|
|
|
|
if(res) {
|
|
|
|
printf("curl_multi_add_handle() 1 failed\n");
|
|
|
|
goto test_cleanup;
|
2007-05-02 02:02:13 -04:00
|
|
|
}
|
2011-10-21 10:26:18 -04:00
|
|
|
|
|
|
|
res = perform(multi);
|
|
|
|
if(res) {
|
|
|
|
printf("retrieve 1 failed\n");
|
|
|
|
goto test_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_multi_remove_handle(multi, easy);
|
|
|
|
|
2006-10-19 18:49:33 -04:00
|
|
|
curl_easy_reset(easy);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
|
|
|
|
easy_setopt(easy, CURLOPT_URL, libtest_arg2);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
res_multi_add_handle(multi, easy);
|
|
|
|
if(res) {
|
2007-05-02 02:02:13 -04:00
|
|
|
printf("curl_multi_add_handle() 2 failed\n");
|
2011-10-21 10:26:18 -04:00
|
|
|
goto test_cleanup;
|
|
|
|
}
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
res = perform(multi);
|
|
|
|
if(res) {
|
|
|
|
printf("retrieve 2 failed\n");
|
|
|
|
goto test_cleanup;
|
2007-05-02 02:02:13 -04:00
|
|
|
}
|
2010-02-05 13:07:19 -05:00
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
curl_multi_remove_handle(multi, easy);
|
|
|
|
|
2010-02-05 13:07:19 -05:00
|
|
|
test_cleanup:
|
|
|
|
|
2011-10-21 10:26:18 -04:00
|
|
|
/* undocumented cleanup sequence - type UB */
|
|
|
|
|
2006-10-19 18:49:33 -04:00
|
|
|
curl_easy_cleanup(easy);
|
|
|
|
curl_multi_cleanup(multi);
|
2006-10-25 01:59:46 -04:00
|
|
|
curl_global_cleanup();
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2006-10-19 18:49:33 -04:00
|
|
|
printf("Finished!\n");
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2007-05-02 02:02:13 -04:00
|
|
|
return res;
|
2006-10-09 17:29:53 -04:00
|
|
|
}
|