2011-03-10 05:48:02 -05:00
|
|
|
/***************************************************************************
|
2010-05-12 09:33:22 -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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2010-05-12 09:33:22 -04:00
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "testutil.h"
|
2011-05-26 06:40:04 -04:00
|
|
|
#include "warnless.h"
|
2010-05-12 09:33:22 -04:00
|
|
|
#include "memdebug.h"
|
|
|
|
|
|
|
|
/* 3x download!
|
|
|
|
* 1. normal
|
|
|
|
* 2. dup handle
|
|
|
|
* 3. with multi interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
int test(char *URL)
|
|
|
|
{
|
|
|
|
CURLMcode m;
|
|
|
|
CURL *handle = NULL, *duphandle;
|
|
|
|
CURLM *mhandle = NULL;
|
|
|
|
int res = 0;
|
|
|
|
int still_running = 0;
|
|
|
|
|
|
|
|
if(curl_global_init(CURL_GLOBAL_ALL)) {
|
|
|
|
fprintf(stderr, "curl_global_init() failed\n");
|
|
|
|
goto test_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
handle = curl_easy_init();
|
|
|
|
if(!handle) {
|
|
|
|
res = CURLE_OUT_OF_MEMORY;
|
|
|
|
goto test_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_setopt(handle, CURLOPT_URL, URL);
|
|
|
|
test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
|
|
|
|
test_setopt(handle, CURLOPT_VERBOSE, 1L);
|
|
|
|
|
|
|
|
res = curl_easy_perform(handle);
|
|
|
|
if(res)
|
|
|
|
goto test_cleanup;
|
|
|
|
|
|
|
|
res = curl_easy_perform(handle);
|
|
|
|
if(res)
|
|
|
|
goto test_cleanup;
|
|
|
|
|
|
|
|
duphandle = curl_easy_duphandle(handle);
|
|
|
|
if(!duphandle)
|
|
|
|
goto test_cleanup;
|
|
|
|
curl_easy_cleanup(handle);
|
|
|
|
handle = duphandle;
|
|
|
|
|
|
|
|
mhandle = curl_multi_init();
|
|
|
|
if(!mhandle) {
|
|
|
|
fprintf(stderr, "curl_multi_init() failed\n");
|
|
|
|
goto test_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_multi_add_handle(mhandle, handle);
|
|
|
|
|
2011-06-26 17:12:08 -04:00
|
|
|
curl_multi_perform(mhandle, &still_running);
|
2010-05-12 09:33:22 -04:00
|
|
|
|
|
|
|
while(still_running) {
|
2010-06-17 11:07:15 -04:00
|
|
|
static struct timeval timeout = /* 100 ms */ { 0, 100000L };
|
2010-05-12 09:33:22 -04:00
|
|
|
int rc;
|
|
|
|
fd_set fdread;
|
|
|
|
fd_set fdwrite;
|
|
|
|
fd_set fdexcep;
|
|
|
|
int max_fdset = -1;
|
|
|
|
FD_ZERO(&fdread);
|
|
|
|
FD_ZERO(&fdwrite);
|
|
|
|
FD_ZERO(&fdexcep);
|
|
|
|
|
|
|
|
m = curl_multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &max_fdset);
|
2010-05-31 10:51:36 -04:00
|
|
|
if(m != CURLM_OK) {
|
|
|
|
fprintf(stderr, "curl_multi_fdset() error\n");
|
|
|
|
goto test_cleanup;
|
|
|
|
}
|
2010-06-17 11:07:15 -04:00
|
|
|
/* We call select(max_fdset + 1, ...), specially in case of (maxfd == -1),
|
|
|
|
* we call select(0, ...), which is basically equal to sleep. */
|
2010-05-12 09:33:22 -04:00
|
|
|
rc = select(max_fdset + 1, &fdread, &fdwrite, &fdexcep, &timeout);
|
|
|
|
if(rc == -1) {
|
|
|
|
fprintf(stderr, "select() error\n");
|
|
|
|
goto test_cleanup;
|
|
|
|
}
|
|
|
|
else {
|
2011-06-26 17:12:08 -04:00
|
|
|
curl_multi_perform(mhandle, &still_running);
|
2010-05-12 09:33:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test_cleanup:
|
|
|
|
if(mhandle)
|
|
|
|
curl_multi_cleanup(mhandle);
|
|
|
|
if(handle)
|
|
|
|
curl_easy_cleanup(handle);
|
|
|
|
curl_global_cleanup();
|
|
|
|
return res;
|
|
|
|
}
|