static int do_one_request(CURLM *m, char *URL, char *resolve) { CURL *curls; struct curl_slist *resolve_list = NULL; int still_running; int res = 0; CURLMsg *msg; int msgs_left; resolve_list = curl_slist_append(resolve_list, resolve); easy_init(curls); easy_setopt(curls, CURLOPT_URL, URL); easy_setopt(curls, CURLOPT_RESOLVE, resolve_list); easy_setopt(curls, CURLOPT_DEBUGFUNCTION, debug_callback); easy_setopt(curls, CURLOPT_VERBOSE, 1); easy_setopt(curls, CURLOPT_DNS_CACHE_TIMEOUT, DNS_TIMEOUT); multi_add_handle(m, curls); multi_perform(m, &still_running); abort_on_test_timeout(); while(still_running) { struct timeval timeout; fd_set fdread, fdwrite, fdexcep; int maxfd = -99; FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); timeout.tv_sec = 1; timeout.tv_usec = 0; multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd); select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); abort_on_test_timeout(); multi_perform(m, &still_running); abort_on_test_timeout(); } do { msg = curl_multi_info_read(m, &msgs_left); if(msg && msg->msg == CURLMSG_DONE && msg->easy_handle == curls) { res = msg->data.result; break; } } while(msg); test_cleanup: curl_multi_remove_handle(m, curls); curl_easy_cleanup(curls); curl_slist_free_all(resolve_list); return res; }
int main(int argc, char **argv) { int rc = 0; if (argc <= 1) { print_usage_and_exit(argv[0], EXIT_FAILURE, false); } parse_options(argc, argv); if (!dev_name) { dev_name = TIPC_DEFAULT_DEVNAME; } if (!test_name) { fprintf(stderr, "need a Test to run\n"); print_usage_and_exit(argv[0], EXIT_FAILURE, true); } if (strcmp(test_name, "connect") == 0) { rc = connect_test(opt_repeat); } else if (strcmp(test_name, "connect_foo") == 0) { rc = connect_foo(opt_repeat); } else if (strcmp(test_name, "burst_write") == 0) { rc = burst_write_test(opt_repeat, opt_msgburst, opt_msgsize, opt_variable); } else if (strcmp(test_name, "select") == 0) { rc = select_test(opt_repeat, opt_msgburst, opt_msgsize); } else if (strcmp(test_name, "blocked_read") == 0) { rc = blocked_read_test(opt_repeat); } else if (strcmp(test_name, "closer1") == 0) { rc = closer1_test(opt_repeat); } else if (strcmp(test_name, "closer2") == 0) { rc = closer2_test(opt_repeat); } else if (strcmp(test_name, "closer3") == 0) { rc = closer3_test(opt_repeat); } else if (strcmp(test_name, "echo") == 0) { rc = echo_test(opt_repeat, opt_msgsize, opt_variable); } else if(strcmp(test_name, "ta2ta-ipc") == 0) { rc = ta2ta_ipc_test(); } else if (strcmp(test_name, "dev-uuid") == 0) { rc = dev_uuid_test(); } else if (strcmp(test_name, "ta-access") == 0) { rc = ta_access_test(); } else if (strcmp(test_name, "writev") == 0) { rc = writev_test(opt_repeat, opt_msgsize, opt_variable); } else if (strcmp(test_name, "readv") == 0) { rc = readv_test(opt_repeat, opt_msgsize, opt_variable); } else { fprintf(stderr, "Unrecognized test name '%s'\n", test_name); print_usage_and_exit(argv[0], EXIT_FAILURE, true); } return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
int test(char *URL) { int res = 0; CURL *curl = NULL; int running; CURLM *m = NULL; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(curl); easy_setopt(curl, CURLOPT_URL, URL); easy_setopt(curl, CURLOPT_VERBOSE, 1L); easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); easy_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_SOCKS4); multi_init(m); multi_add_handle(m, curl); fprintf(stderr, "Start at URL 0\n"); for(;;) { struct timeval interval; fd_set rd, wr, exc; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; multi_perform(m, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: /* undocumented cleanup sequence - type UB */ curl_easy_cleanup(curl); curl_multi_cleanup(m); curl_global_cleanup(); return res; }
int test(char *URL) { CURL *easy = NULL; CURLM *multi = NULL; int res = 0; int running; int msgs_left; CURLMsg *msg; FILE *upload = NULL; int error; start_test_timing(); upload = fopen(libtest_arg3, "rb"); if(!upload) { error = ERRNO; fprintf(stderr, "fopen() failed with error: %d (%s)\n", error, strerror(error)); fprintf(stderr, "Error opening file: (%s)\n", libtest_arg3); return TEST_ERR_FOPEN; } res_global_init(CURL_GLOBAL_ALL); if(res) { fclose(upload); return res; } easy_init(easy); /* go verbose */ easy_setopt(easy, CURLOPT_VERBOSE, 1L); /* specify target */ easy_setopt(easy, CURLOPT_URL, URL); /* enable uploading */ easy_setopt(easy, CURLOPT_UPLOAD, 1L); /* data pointer for the file read function */ easy_setopt(easy, CURLOPT_READDATA, upload); /* use active mode FTP */ easy_setopt(easy, CURLOPT_FTPPORT, "-"); /* server connection timeout */ easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS, strtol(libtest_arg2, NULL, 10)*1000); multi_init(multi); multi_add_handle(multi, easy); for(;;) { struct timeval interval; fd_set fdread; fd_set fdwrite; fd_set fdexcep; long timeout = -99; int maxfd = -99; multi_perform(multi, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ multi_timeout(multi, &timeout); /* At this point, timeout is guaranteed to be greater or equal than -1. */ if(timeout != -1L) { int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout; interval.tv_sec = itimeout/1000; interval.tv_usec = (itimeout%1000)*1000; } else { interval.tv_sec = 0; interval.tv_usec = 100000L; /* 100 ms */ } select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval); abort_on_test_timeout(); } msg = curl_multi_info_read(multi, &msgs_left); if(msg) res = msg->data.result; test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(multi); curl_easy_cleanup(easy); curl_global_cleanup(); /* close the local file */ fclose(upload); return res; }
int test(char *URL) { int res = 0; CURL *curl[NUM_HANDLES]; int running; char done=FALSE; CURLM *m = NULL; int current=0; int i, j; struct timeval ml_start; struct timeval mp_start; char ml_timedout = FALSE; char mp_timedout = FALSE; if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } /* get NUM_HANDLES easy handles */ for(i=0; i < NUM_HANDLES; i++) { curl[i] = curl_easy_init(); if(!curl[i]) { fprintf(stderr, "curl_easy_init() failed " "on handle #%d\n", i); for (j=i-1; j >= 0; j--) { curl_easy_cleanup(curl[j]); } curl_global_cleanup(); return TEST_ERR_MAJOR_BAD + i; } res = curl_easy_setopt(curl[i], CURLOPT_URL, URL); if(res) { fprintf(stderr, "curl_easy_setopt() failed " "on handle #%d\n", i); for (j=i; j >= 0; j--) { curl_easy_cleanup(curl[j]); } curl_global_cleanup(); return TEST_ERR_MAJOR_BAD + i; } /* go verbose */ res = curl_easy_setopt(curl[i], CURLOPT_VERBOSE, 1L); if(res) { fprintf(stderr, "curl_easy_setopt() failed " "on handle #%d\n", i); for (j=i; j >= 0; j--) { curl_easy_cleanup(curl[j]); } curl_global_cleanup(); return TEST_ERR_MAJOR_BAD + i; } } if ((m = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); for(i=0; i < NUM_HANDLES; i++) { curl_easy_cleanup(curl[i]); } curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } if ((res = (int)curl_multi_add_handle(m, curl[current])) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "with code %d\n", res); curl_multi_cleanup(m); for(i=0; i < NUM_HANDLES; i++) { curl_easy_cleanup(curl[i]); } curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } ml_timedout = FALSE; ml_start = tutil_tvnow(); fprintf(stderr, "Start at URL 0\n"); while (!done) { fd_set rd, wr, exc; int max_fd; struct timeval interval; interval.tv_sec = 1; interval.tv_usec = 0; if (tutil_tvdiff(tutil_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } mp_timedout = FALSE; mp_start = tutil_tvnow(); res = (int)curl_multi_perform(m, &running); if (tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } if (running <= 0) { #ifdef LIB527 /* NOTE: this code does not remove the handle from the multi handle here, which would be the nice, sane and documented way of working. This however tests that the API survives this abuse gracefully. */ curl_easy_cleanup(curl[current]); #endif if(++current < NUM_HANDLES) { fprintf(stderr, "Advancing to URL %d\n", current); #ifdef LIB532 /* first remove the only handle we use */ curl_multi_remove_handle(m, curl[0]); /* make us re-use the same handle all the time, and try resetting the handle first too */ curl_easy_reset(curl[0]); test_setopt(curl[0], CURLOPT_URL, URL); test_setopt(curl[0], CURLOPT_VERBOSE, 1L); /* re-add it */ res = (int)curl_multi_add_handle(m, curl[0]); #else res = (int)curl_multi_add_handle(m, curl[current]); #endif if(res) { fprintf(stderr, "add handle failed: %d.\n", res); res = 243; break; } } else { done = TRUE; /* bail out */ break; } } if (res != CURLM_OK) { fprintf(stderr, "not okay???\n"); break; } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); max_fd = 0; if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) { fprintf(stderr, "unexpected failured of fdset.\n"); res = 189; break; } if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) { fprintf(stderr, "bad select??\n"); res = 195; break; } } if (ml_timedout || mp_timedout) { if (ml_timedout) fprintf(stderr, "ml_timedout\n"); if (mp_timedout) fprintf(stderr, "mp_timedout\n"); fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); res = TEST_ERR_RUNS_FOREVER; } #ifdef LIB532 test_cleanup: #endif #ifndef LIB527 /* get NUM_HANDLES easy handles */ for(i=0; i < NUM_HANDLES; i++) { #ifdef LIB526 if(m) curl_multi_remove_handle(m, curl[i]); #endif curl_easy_cleanup(curl[i]); } #endif if(m) curl_multi_cleanup(m); curl_global_cleanup(); return res; }
int test_inner(void) { pj_caching_pool caching_pool; const char *filename; int line; int rc = 0; mem = &caching_pool.factory; pj_log_set_level(3); pj_log_set_decor(param_log_decor); rc = pj_init(); if (rc != 0) { app_perror("pj_init() error!!", rc); return rc; } //pj_dump_config(); pj_caching_pool_init( &caching_pool, NULL, 0 ); #if INCLUDE_ERRNO_TEST DO_TEST( errno_test() ); #endif #if INCLUDE_EXCEPTION_TEST DO_TEST( exception_test() ); #endif #if INCLUDE_OS_TEST DO_TEST( os_test() ); #endif #if INCLUDE_RAND_TEST DO_TEST( rand_test() ); #endif #if INCLUDE_LIST_TEST DO_TEST( list_test() ); #endif #if INCLUDE_POOL_TEST DO_TEST( pool_test() ); #endif #if INCLUDE_POOL_PERF_TEST DO_TEST( pool_perf_test() ); #endif #if INCLUDE_STRING_TEST DO_TEST( string_test() ); #endif #if INCLUDE_FIFOBUF_TEST DO_TEST( fifobuf_test() ); #endif #if INCLUDE_RBTREE_TEST DO_TEST( rbtree_test() ); #endif #if INCLUDE_HASH_TEST DO_TEST( hash_test() ); #endif #if INCLUDE_TIMESTAMP_TEST DO_TEST( timestamp_test() ); #endif #if INCLUDE_ATOMIC_TEST DO_TEST( atomic_test() ); #endif #if INCLUDE_MUTEX_TEST DO_TEST( mutex_test() ); #endif #if INCLUDE_TIMER_TEST DO_TEST( timer_test() ); #endif #if INCLUDE_SLEEP_TEST DO_TEST( sleep_test() ); #endif #if INCLUDE_THREAD_TEST DO_TEST( thread_test() ); #endif #if INCLUDE_SOCK_TEST DO_TEST( sock_test() ); #endif #if INCLUDE_SOCK_PERF_TEST DO_TEST( sock_perf_test() ); #endif #if INCLUDE_SELECT_TEST DO_TEST( select_test() ); #endif #if INCLUDE_UDP_IOQUEUE_TEST DO_TEST( udp_ioqueue_test() ); #endif #if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST DO_TEST( tcp_ioqueue_test() ); #endif #if INCLUDE_IOQUEUE_PERF_TEST DO_TEST( ioqueue_perf_test() ); #endif #if INCLUDE_IOQUEUE_UNREG_TEST DO_TEST( udp_ioqueue_unreg_test() ); #endif #if INCLUDE_ACTIVESOCK_TEST DO_TEST( activesock_test() ); #endif #if INCLUDE_FILE_TEST DO_TEST( file_test() ); #endif #if INCLUDE_SSLSOCK_TEST DO_TEST( ssl_sock_test() ); #endif #if INCLUDE_ECHO_SERVER //echo_server(); //echo_srv_sync(); udp_echo_srv_ioqueue(); #elif INCLUDE_ECHO_CLIENT if (param_echo_sock_type == 0) param_echo_sock_type = pj_SOCK_DGRAM(); echo_client( param_echo_sock_type, param_echo_server, param_echo_port); #endif goto on_return; on_return: pj_caching_pool_destroy( &caching_pool ); PJ_LOG(3,("test", "")); pj_thread_get_stack_info(pj_thread_this(), &filename, &line); PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u", pj_thread_get_stack_max_usage(pj_thread_this()), filename, line)); if (rc == 0) PJ_LOG(3,("test", "Looks like everything is okay!..")); else PJ_LOG(3,("test", "Test completed with error(s)")); pj_shutdown(); return 0; }
int test(char *URL) { int res = 0; CURL *curl; FILE *hd_src ; int hd ; int error; struct_stat file_info; int running; char done=FALSE; CURLM *m = NULL; struct timeval ml_start; struct timeval mp_start; char ml_timedout = FALSE; char mp_timedout = FALSE; if (!libtest_arg2) { fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n"); return -1; } hd_src = fopen(libtest_arg2, "rb"); if(NULL == hd_src) { error = ERRNO; fprintf(stderr, "fopen() failed with error: %d %s\n", error, strerror(error)); fprintf(stderr, "Error opening file: %s\n", libtest_arg2); return TEST_ERR_MAJOR_BAD; } /* get the file size of the local file */ hd = fstat(fileno(hd_src), &file_info); if(hd == -1) { /* can't open file, bail out */ error = ERRNO; fprintf(stderr, "fstat() failed with error: %d %s\n", error, strerror(error)); fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2); fclose(hd_src); return -1; } if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); fclose(hd_src); return TEST_ERR_MAJOR_BAD; } if ((curl = curl_easy_init()) == NULL) { fprintf(stderr, "curl_easy_init() failed\n"); fclose(hd_src); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* enable uploading */ test_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ test_setopt(curl,CURLOPT_URL, URL); /* go verbose */ test_setopt(curl, CURLOPT_VERBOSE, 1L); /* use active FTP */ test_setopt(curl, CURLOPT_FTPPORT, "-"); /* now specify which file to upload */ test_setopt(curl, CURLOPT_READDATA, hd_src); /* NOTE: if you want this code to work on Windows with libcurl as a DLL, you MUST also provide a read callback with CURLOPT_READFUNCTION. Failing to do so will give you a crash since a DLL may not use the variable's memory when passed in to it from an app like this. */ /* Set the size of the file to upload (optional). If you give a *_LARGE option you MUST make sure that the type of the passed-in argument is a curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must make sure that to pass in a type 'long' argument. */ test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); if ((m = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); curl_easy_cleanup(curl); curl_global_cleanup(); fclose(hd_src); return TEST_ERR_MAJOR_BAD; } if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "with code %d\n", res); curl_multi_cleanup(m); curl_easy_cleanup(curl); curl_global_cleanup(); fclose(hd_src); return TEST_ERR_MAJOR_BAD; } ml_timedout = FALSE; ml_start = tutil_tvnow(); while (!done) { fd_set rd, wr, exc; int max_fd; struct timeval interval; interval.tv_sec = 1; interval.tv_usec = 0; if (tutil_tvdiff(tutil_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } mp_timedout = FALSE; mp_start = tutil_tvnow(); res = (int)curl_multi_perform(m, &running); if (tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } if (running <= 0) { done = TRUE; break; } if (res != CURLM_OK) { fprintf(stderr, "not okay???\n"); break; } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); max_fd = 0; if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) { fprintf(stderr, "unexpected failured of fdset.\n"); res = 189; break; } if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) { fprintf(stderr, "bad select??\n"); res = 195; break; } res = CURLM_CALL_MULTI_PERFORM; } if (ml_timedout || mp_timedout) { if (ml_timedout) fprintf(stderr, "ml_timedout\n"); if (mp_timedout) fprintf(stderr, "mp_timedout\n"); fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); res = TEST_ERR_RUNS_FOREVER; } test_cleanup: #ifdef LIB529 /* test 529 */ if(m) { curl_multi_remove_handle(m, curl); curl_multi_cleanup(m); } curl_easy_cleanup(curl); #else /* test 525 */ if(m) curl_multi_remove_handle(m, curl); curl_easy_cleanup(curl); if(m) curl_multi_cleanup(m); #endif fclose(hd_src); /* close the local file */ curl_global_cleanup(); return res; }
int test(char *URL) { int res = 0; CURLM *m = NULL; CURLMsg *msg; /* for picking up messages with the transfer status */ int msgs_left; /* how many messages are left */ int running; int handlenum = 0; struct timeval last_handle_add; if(parse_url_file("log/urls.txt") <= 0) goto test_cleanup; start_test_timing(); curl_global_init(CURL_GLOBAL_ALL); multi_init(m); create_handles(); multi_setopt(m, CURLMOPT_PIPELINING, 1L); multi_setopt(m, CURLMOPT_MAX_HOST_CONNECTIONS, 2L); multi_setopt(m, CURLMOPT_MAX_PIPELINE_LENGTH, 3L); multi_setopt(m, CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, 15000L); multi_setopt(m, CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, 10000L); multi_setopt(m, CURLMOPT_PIPELINING_SITE_BL, site_blacklist); multi_setopt(m, CURLMOPT_PIPELINING_SERVER_BL, server_blacklist); last_handle_add = tutil_tvnow(); for(;;) { struct timeval interval; struct timeval now; long int msnow, mslast; fd_set rd, wr, exc; int maxfd = -99; long timeout; interval.tv_sec = 1; interval.tv_usec = 0; if(handlenum < num_handles) { now = tutil_tvnow(); msnow = now.tv_sec * 1000 + now.tv_usec / 1000; mslast = last_handle_add.tv_sec * 1000 + last_handle_add.tv_usec / 1000; if(msnow - mslast >= urltime[handlenum] && handlenum < num_handles) { fprintf(stdout, "Adding handle %d\n", handlenum); setup_handle(URL, m, handlenum); last_handle_add = now; handlenum++; } } curl_multi_perform(m, &running); abort_on_test_timeout(); /* See how the transfers went */ while ((msg = curl_multi_info_read(m, &msgs_left))) { if (msg->msg == CURLMSG_DONE) { int i, found = 0; /* Find out which handle this message is about */ for (i = 0; i < num_handles; i++) { found = (msg->easy_handle == handles[i]); if(found) break; } printf("Handle %d Completed with status %d\n", i, msg->data.result); curl_multi_remove_handle(m, handles[i]); } } if(handlenum == num_handles && !running) { break; /* done */ } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); curl_multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ curl_multi_timeout(m, &timeout); if(timeout < 0) timeout = 1; interval.tv_sec = timeout / 1000; interval.tv_usec = (timeout % 1000) * 1000; interval.tv_sec = 0; interval.tv_usec = 1000; select_test(maxfd+1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: remove_handles(); /* undocumented cleanup sequence - type UB */ curl_multi_cleanup(m); curl_global_cleanup(); free_urls(); return res; }
int test(char *URL) { int res = 0; CURL *curl[NUM_HANDLES]; int running; char done=FALSE; CURLM *m; int i, j; struct timeval ml_start; struct timeval mp_start; char ml_timedout = FALSE; char mp_timedout = FALSE; char target_url[256]; if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } if ((m = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* get NUM_HANDLES easy handles */ for(i=0; i < NUM_HANDLES; i++) { curl[i] = curl_easy_init(); if(!curl[i]) { fprintf(stderr, "curl_easy_init() failed " "on handle #%d\n", i); for (j=i-1; j >= 0; j--) { curl_multi_remove_handle(m, curl[j]); curl_easy_cleanup(curl[j]); } curl_multi_cleanup(m); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD + i; } sprintf(target_url, "%s%04i", URL, i + 1); target_url[sizeof(target_url) - 1] = '\0'; res = curl_easy_setopt(curl[i], CURLOPT_URL, target_url); if(res) { fprintf(stderr, "curl_easy_setopt() failed " "on handle #%d\n", i); for (j=i; j >= 0; j--) { curl_multi_remove_handle(m, curl[j]); curl_easy_cleanup(curl[j]); } curl_multi_cleanup(m); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD + i; } /* go verbose */ res = curl_easy_setopt(curl[i], CURLOPT_VERBOSE, 1L); if(res) { fprintf(stderr, "curl_easy_setopt() failed " "on handle #%d\n", i); for (j=i; j >= 0; j--) { curl_multi_remove_handle(m, curl[j]); curl_easy_cleanup(curl[j]); } curl_multi_cleanup(m); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD + i; } /* include headers */ res = curl_easy_setopt(curl[i], CURLOPT_HEADER, 1L); if(res) { fprintf(stderr, "curl_easy_setopt() failed " "on handle #%d\n", i); for (j=i; j >= 0; j--) { curl_multi_remove_handle(m, curl[j]); curl_easy_cleanup(curl[j]); } curl_multi_cleanup(m); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD + i; } /* add handle to multi */ if ((res = (int)curl_multi_add_handle(m, curl[i])) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "on handle #%d with code %d\n", i, res); curl_easy_cleanup(curl[i]); for (j=i-1; j >= 0; j--) { curl_multi_remove_handle(m, curl[j]); curl_easy_cleanup(curl[j]); } curl_multi_cleanup(m); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD + i; } } curl_multi_setopt(m, CURLMOPT_PIPELINING, 1L); ml_timedout = FALSE; ml_start = tutil_tvnow(); fprintf(stderr, "Start at URL 0\n"); while (!done) { fd_set rd, wr, exc; int max_fd; struct timeval interval; interval.tv_sec = 1; interval.tv_usec = 0; if (tutil_tvdiff(tutil_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } mp_timedout = FALSE; mp_start = tutil_tvnow(); res = (int)curl_multi_perform(m, &running); if (tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } if (running <= 0) { done = TRUE; /* bail out */ break; } if (res != CURLM_OK) { fprintf(stderr, "not okay???\n"); break; } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); max_fd = 0; if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) { fprintf(stderr, "unexpected failured of fdset.\n"); res = 189; break; } if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) { fprintf(stderr, "bad select??\n"); res = 195; break; } res = CURLM_CALL_MULTI_PERFORM; } if (ml_timedout || mp_timedout) { if (ml_timedout) fprintf(stderr, "ml_timedout\n"); if (mp_timedout) fprintf(stderr, "mp_timedout\n"); fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); res = TEST_ERR_RUNS_FOREVER; } /* test_cleanup: */ /* cleanup NUM_HANDLES easy handles */ for(i=0; i < NUM_HANDLES; i++) { curl_multi_remove_handle(m, curl[i]); curl_easy_cleanup(curl[i]); } curl_multi_cleanup(m); curl_global_cleanup(); return res; }
int test(char *URL) { CURL *handle = NULL; CURLM *mhandle = NULL; int res = 0; int still_running = 0; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(handle); easy_setopt(handle, CURLOPT_URL, URL); easy_setopt(handle, CURLOPT_VERBOSE, 1L); multi_init(mhandle); multi_add_handle(mhandle, handle); multi_perform(mhandle, &still_running); abort_on_test_timeout(); while(still_running) { struct timeval timeout; fd_set fdread; fd_set fdwrite; fd_set fdexcep; int maxfd = -99; struct timeval before; struct timeval after; int e; timeout.tv_sec = 0; timeout.tv_usec = 100000L; /* 100 ms */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); abort_on_test_timeout(); fprintf(stderr, "ping\n"); before = tutil_tvnow(); multi_perform(mhandle, &still_running); abort_on_test_timeout(); after = tutil_tvnow(); e = elapsed(&before, &after); fprintf(stderr, "pong = %d\n", e); if(e > MAX_BLOCKED_TIME_US) { res = 100; break; } } test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(mhandle); curl_easy_cleanup(handle); curl_global_cleanup(); return res; }
int test(char *URL) { int res = 0; CURL *curl; FILE *hd_src ; int hd ; int error; struct_stat file_info; CURLM *m = NULL; struct timeval ml_start; char ml_timedout = FALSE; struct ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}}; struct timeval timeout = {-1, 0}; int success = 0; if (!libtest_arg3) { fprintf(stderr, "Usage: lib582 [url] [filename] [username]\n"); return -1; } hd_src = fopen(libtest_arg2, "rb"); if(NULL == hd_src) { error = ERRNO; fprintf(stderr, "fopen() failed with error: %d %s\n", error, strerror(error)); fprintf(stderr, "Error opening file: %s\n", libtest_arg2); return TEST_ERR_MAJOR_BAD; } /* get the file size of the local file */ hd = fstat(fileno(hd_src), &file_info); if(hd == -1) { /* can't open file, bail out */ error = ERRNO; fprintf(stderr, "fstat() failed with error: %d %s\n", error, strerror(error)); fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2); fclose(hd_src); return -1; } fprintf(stderr, "Set to upload %d bytes\n", (int)file_info.st_size); if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); fclose(hd_src); return TEST_ERR_MAJOR_BAD; } if ((curl = curl_easy_init()) == NULL) { fprintf(stderr, "curl_easy_init() failed\n"); fclose(hd_src); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* enable uploading */ test_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ test_setopt(curl,CURLOPT_URL, URL); /* go verbose */ test_setopt(curl, CURLOPT_VERBOSE, 1L); /* now specify which file to upload */ test_setopt(curl, CURLOPT_READDATA, hd_src); test_setopt(curl, CURLOPT_USERPWD, libtest_arg3); test_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "curl_client_key.pub"); test_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "curl_client_key"); test_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); if ((m = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); curl_easy_cleanup(curl); curl_global_cleanup(); fclose(hd_src); return TEST_ERR_MAJOR_BAD; } test_multi_setopt(m, CURLMOPT_SOCKETFUNCTION, curlSocketCallback); test_multi_setopt(m, CURLMOPT_SOCKETDATA, &sockets); test_multi_setopt(m, CURLMOPT_TIMERFUNCTION, curlTimerCallback); test_multi_setopt(m, CURLMOPT_TIMERDATA, &timeout); if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "with code %d\n", res); curl_multi_cleanup(m); curl_easy_cleanup(curl); curl_global_cleanup(); fclose(hd_src); return TEST_ERR_MAJOR_BAD; } ml_timedout = FALSE; ml_start = tutil_tvnow(); while (!checkForCompletion(m, &success)) { fd_set readSet, writeSet; curl_socket_t maxFd = 0; struct timeval tv = {10, 0}; if (tutil_tvdiff(tutil_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } FD_ZERO(&readSet); FD_ZERO(&writeSet); updateFdSet(&sockets.read, &readSet, &maxFd); updateFdSet(&sockets.write, &writeSet, &maxFd); if (timeout.tv_sec != -1) { int usTimeout = getMicroSecondTimeout(&timeout); tv.tv_sec = usTimeout / 1000000; tv.tv_usec = usTimeout % 1000000; } else if (maxFd <= 0) { tv.tv_sec = 0; tv.tv_usec = 100000; } select_test(maxFd, &readSet, &writeSet, NULL, &tv); /* Check the sockets for reading / writing */ checkFdSet(m, &sockets.read, &readSet, CURL_CSELECT_IN, "read"); checkFdSet(m, &sockets.write, &writeSet, CURL_CSELECT_OUT, "write"); if (timeout.tv_sec != -1 && getMicroSecondTimeout(&timeout) == 0) { /* Curl's timer has elapsed. */ notifyCurl(m, CURL_SOCKET_TIMEOUT, 0, "timeout"); } } if (!success) { fprintf(stderr, "Error uploading file.\n"); res = TEST_ERR_MAJOR_BAD; } else if (ml_timedout) { fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); res = TEST_ERR_RUNS_FOREVER; } test_cleanup: if(m) curl_multi_remove_handle(m, curl); curl_easy_cleanup(curl); if(m) { fprintf(stderr, "Now multi-cleanup!\n"); curl_multi_cleanup(m); } fclose(hd_src); /* close the local file */ if (sockets.read.sockets) free(sockets.read.sockets); if (sockets.write.sockets) free(sockets.write.sockets); curl_global_cleanup(); return res; }
int test(char *URL) { CURL* curls = NULL; CURLM* multi = NULL; int still_running; int i = -1; int res = 0; CURLMsg *msg; start_test_timing(); global_init(CURL_GLOBAL_ALL); multi_init(multi); easy_init(curls); easy_setopt(curls, CURLOPT_URL, URL); easy_setopt(curls, CURLOPT_HEADER, 1L); multi_add_handle(multi, curls); multi_perform(multi, &still_running); abort_on_test_timeout(); while(still_running) { struct timeval timeout; fd_set fdread; fd_set fdwrite; fd_set fdexcep; int maxfd = -99; FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); timeout.tv_sec = 1; timeout.tv_usec = 0; multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); abort_on_test_timeout(); multi_perform(multi, &still_running); abort_on_test_timeout(); } msg = curl_multi_info_read(multi, &still_running); if(msg) /* this should now contain a result code from the easy handle, get it */ i = msg->data.result; test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(multi); curl_easy_cleanup(curls); curl_global_cleanup(); if(res) i = res; return i; /* return the final return code */ }
int test(char *URL) { int res = 0; CURL *curl[NUM_HANDLES]; int running; CURLM *m = NULL; int current = 0; int i; for(i=0; i < NUM_HANDLES; i++) curl[i] = NULL; start_test_timing(); global_init(CURL_GLOBAL_ALL); /* get NUM_HANDLES easy handles */ for(i=0; i < NUM_HANDLES; i++) { easy_init(curl[i]); /* specify target */ easy_setopt(curl[i], CURLOPT_URL, URL); /* go verbose */ easy_setopt(curl[i], CURLOPT_VERBOSE, 1L); } multi_init(m); multi_add_handle(m, curl[current]); fprintf(stderr, "Start at URL 0\n"); for(;;) { struct timeval interval; fd_set rd, wr, exc; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; multi_perform(m, &running); abort_on_test_timeout(); if(!running) { #ifdef LIB527 /* NOTE: this code does not remove the handle from the multi handle here, which would be the nice, sane and documented way of working. This however tests that the API survives this abuse gracefully. */ curl_easy_cleanup(curl[current]); curl[current] = NULL; #endif if(++current < NUM_HANDLES) { fprintf(stderr, "Advancing to URL %d\n", current); #ifdef LIB532 /* first remove the only handle we use */ curl_multi_remove_handle(m, curl[0]); /* make us re-use the same handle all the time, and try resetting the handle first too */ curl_easy_reset(curl[0]); easy_setopt(curl[0], CURLOPT_URL, URL); /* go verbose */ easy_setopt(curl[0], CURLOPT_VERBOSE, 1L); /* re-add it */ multi_add_handle(m, curl[0]); #else multi_add_handle(m, curl[current]); #endif } else { break; /* done */ } } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd+1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: #if defined(LIB526) /* test 526 and 528 */ /* proper cleanup sequence - type PB */ for(i=0; i < NUM_HANDLES; i++) { curl_multi_remove_handle(m, curl[i]); curl_easy_cleanup(curl[i]); } curl_multi_cleanup(m); curl_global_cleanup(); #elif defined(LIB527) /* test 527 */ /* Upon non-failure test flow the easy's have already been cleanup'ed. In case there is a failure we arrive here with easy's that have not been cleanup'ed yet, in this case we have to cleanup them or otherwise these will be leaked, let's use undocumented cleanup sequence - type UB */ if(res) for(i=0; i < NUM_HANDLES; i++) curl_easy_cleanup(curl[i]); curl_multi_cleanup(m); curl_global_cleanup(); #elif defined(LIB532) /* test 532 */ /* undocumented cleanup sequence - type UB */ for(i=0; i < NUM_HANDLES; i++) curl_easy_cleanup(curl[i]); curl_multi_cleanup(m); curl_global_cleanup(); #endif return res; }
int test(char *URL) { int res = 0; CURL *curl[NUM_HANDLES]; int running; CURLM *m = NULL; int i; char target_url[256]; char dnsentry[256]; struct curl_slist *slist = NULL; char *port = libtest_arg3; char *address = libtest_arg2; (void)URL; /* Create fake DNS entries for serverX.example.com for all handles */ for(i=0; i < NUM_HANDLES; i++) { sprintf(dnsentry, "server%d.example.com:%s:%s", i + 1, port, address); printf("%s\n", dnsentry); slist = curl_slist_append(slist, dnsentry); } for(i=0; i < NUM_HANDLES; i++) curl[i] = NULL; start_test_timing(); global_init(CURL_GLOBAL_ALL); multi_init(m); multi_setopt(m, CURLMOPT_MAXCONNECTS, 3); /* get NUM_HANDLES easy handles */ for(i=0; i < NUM_HANDLES; i++) { /* get an easy handle */ easy_init(curl[i]); /* specify target */ sprintf(target_url, "http://server%d.example.com:%s/path/1506%04i", i + 1, port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl[i], CURLOPT_URL, target_url); /* go verbose */ easy_setopt(curl[i], CURLOPT_VERBOSE, 1L); /* include headers */ easy_setopt(curl[i], CURLOPT_HEADER, 1L); easy_setopt(curl[i], CURLOPT_RESOLVE, slist); } fprintf(stderr, "Start at URL 0\n"); for(i=0; i < NUM_HANDLES; i++) { /* add handle to multi */ multi_add_handle(m, curl[i]); for(;;) { struct timeval interval; fd_set rd, wr, exc; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; multi_perform(m, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd+1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } } test_cleanup: /* proper cleanup sequence - type PB */ for(i=0; i < NUM_HANDLES; i++) { curl_multi_remove_handle(m, curl[i]); curl_easy_cleanup(curl[i]); } curl_slist_free_all(slist); curl_multi_cleanup(m); curl_global_cleanup(); return res; }
int test(char *URL) { CURL* easy = NULL; CURLM* multi = NULL; int still_running; int res = 0; char redirect[160]; /* DNS cache injection */ struct curl_slist *dns_cache_list; sprintf(redirect, "google.com:%s:%s", libtest_arg2, libtest_arg3); start_test_timing(); dns_cache_list = curl_slist_append(NULL, redirect); if(!dns_cache_list) { fprintf(stderr, "curl_slist_append() failed\n"); return TEST_ERR_MAJOR_BAD; } res_global_init(CURL_GLOBAL_ALL); if(res) { curl_slist_free_all(dns_cache_list); return res; } easy_init(easy); easy_setopt(easy, CURLOPT_URL, URL); easy_setopt(easy, CURLOPT_HEADER, 1L); easy_setopt(easy, CURLOPT_RESOLVE, dns_cache_list); multi_init(multi); multi_add_handle(multi, easy); multi_perform(multi, &still_running); abort_on_test_timeout(); while(still_running) { struct timeval timeout; fd_set fdread; fd_set fdwrite; fd_set fdexcep; int maxfd = -99; FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); timeout.tv_sec = 1; timeout.tv_usec = 0; multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); abort_on_test_timeout(); multi_perform(multi, &still_running); abort_on_test_timeout(); } test_cleanup: #ifdef LIB1502 /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(multi); curl_easy_cleanup(easy); curl_global_cleanup(); #endif #ifdef LIB1503 /* proper cleanup sequence - type PA */ curl_multi_remove_handle(multi, easy); curl_multi_cleanup(multi); curl_easy_cleanup(easy); curl_global_cleanup(); #endif #ifdef LIB1504 /* undocumented cleanup sequence - type UB */ curl_easy_cleanup(easy); curl_multi_cleanup(multi); curl_global_cleanup(); #endif #ifdef LIB1505 /* proper cleanup sequence - type PB */ curl_multi_remove_handle(multi, easy); curl_easy_cleanup(easy); curl_multi_cleanup(multi); curl_global_cleanup(); #endif curl_slist_free_all(dns_cache_list); return res; }
/* * Source code in here hugely as reported in bug report 651464 by * Christopher R. Palmer. * * Use multi interface to get document over proxy with bad port number. * This caused the interface to "hang" in libcurl 7.10.2. */ int test(char *URL) { CURL *c = NULL; int res = 0; CURLM *m = NULL; fd_set rd, wr, exc; int running; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(c); /* The point here is that there must not be anything running on the given proxy port */ if (libtest_arg2) easy_setopt(c, CURLOPT_PROXY, libtest_arg2); easy_setopt(c, CURLOPT_URL, URL); easy_setopt(c, CURLOPT_VERBOSE, 1L); multi_init(m); multi_add_handle(m, c); for(;;) { struct timeval interval; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; fprintf(stderr, "curl_multi_perform()\n"); multi_perform(m, &running); abort_on_test_timeout(); if(!running) { /* This is where this code is expected to reach */ int numleft; CURLMsg *msg = curl_multi_info_read(m, &numleft); fprintf(stderr, "Expected: not running\n"); if(msg && !numleft) res = TEST_ERR_SUCCESS; /* this is where we should be */ else res = TEST_ERR_FAILURE; /* not correct */ break; /* done */ } fprintf(stderr, "running == %d\n", running); FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); fprintf(stderr, "curl_multi_fdset()\n"); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd+1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: /* proper cleanup sequence - type PA */ curl_multi_remove_handle(m, c); curl_multi_cleanup(m); curl_easy_cleanup(c); curl_global_cleanup(); return res; }
int test(char *url) { CURLM *multi = NULL; int running; int i, j; int num_handles = 0; enum HandleState state = ReadyForNewHandle; size_t urllen = strlen(url) + 4 + 1; char* full_url = malloc(urllen); start_test_timing(); if(!full_url) { fprintf(stderr, "Not enough memory for full url\n"); return TEST_ERR_MAJOR_BAD; } for(i = 0; i < MAX_EASY_HANDLES; ++i) { easy[i] = NULL; sockets[i] = CURL_SOCKET_BAD; } res_global_init(CURL_GLOBAL_ALL); if(res) { free(full_url); return res; } multi_init(multi); #ifdef USE_PIPELINING multi_setopt(multi, CURLMOPT_PIPELINING, 1L); multi_setopt(multi, CURLMOPT_MAX_HOST_CONNECTIONS, 5L); multi_setopt(multi, CURLMOPT_MAX_TOTAL_CONNECTIONS, 10L); #endif for(;;) { struct timeval interval; fd_set fdread; fd_set fdwrite; fd_set fdexcep; long timeout = -99; int maxfd = -99; bool found_new_socket = FALSE; /* Start a new handle if we aren't at the max */ if(state == ReadyForNewHandle) { easy_init(easy[num_handles]); if(num_handles % 3 == 2) { snprintf(full_url, urllen, "%s0200", url); easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_NTLM); } else { snprintf(full_url, urllen, "%s0100", url); easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_BASIC); } easy_setopt(easy[num_handles], CURLOPT_FRESH_CONNECT, 1L); easy_setopt(easy[num_handles], CURLOPT_URL, full_url); easy_setopt(easy[num_handles], CURLOPT_VERBOSE, 1L); easy_setopt(easy[num_handles], CURLOPT_HTTPGET, 1L); easy_setopt(easy[num_handles], CURLOPT_USERPWD, "testuser:testpass"); easy_setopt(easy[num_handles], CURLOPT_WRITEFUNCTION, callback); easy_setopt(easy[num_handles], CURLOPT_WRITEDATA, easy + num_handles); easy_setopt(easy[num_handles], CURLOPT_HEADER, 1L); multi_add_handle(multi, easy[num_handles]); num_handles += 1; state = NeedSocketForNewHandle; } multi_perform(multi, &running); abort_on_test_timeout(); if(!running && state == NoMoreHandles) break; /* done */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ /* Any socket which is new in fdread is associated with the new handle */ for(i = 0; i <= maxfd; ++i) { bool socket_exists = FALSE; curl_socket_t curfd = (curl_socket_t)i; if(!FD_ISSET(curfd, &fdread)) { continue; } /* Check if this socket was already detected for an earlier handle (or for this handle, num_handles-1, in the callback */ for(j = 0; j < num_handles; ++j) { if(sockets[j] == curfd) { socket_exists = TRUE; break; } } if(socket_exists) { continue; } if(found_new_socket || state != NeedSocketForNewHandle) { fprintf(stderr, "Unexpected new socket\n"); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } /* Now we know the socket is for the most recent handle, num_handles-1 */ if(sockets[num_handles-1] != CURL_SOCKET_BAD) { /* A socket for this handle was already detected in the callback; if it matched socket_exists should be true and we would never get here */ assert(curfd != sockets[num_handles-1]); fprintf(stderr, "Handle %d wrote to socket %d then detected on %d\n", num_handles-1, (int)sockets[num_handles-1], (int)curfd); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } else { sockets[num_handles-1] = curfd; found_new_socket = TRUE; /* continue to make sure there's only one new handle */ } } if(state == NeedSocketForNewHandle) { if(maxfd != -1 && !found_new_socket) { fprintf(stderr, "Warning: socket did not open immediately for new " "handle (trying again)\n"); continue; } state = num_handles < MAX_EASY_HANDLES ? ReadyForNewHandle : NoMoreHandles; } multi_timeout(multi, &timeout); /* At this point, timeout is guaranteed to be greater or equal than -1. */ fprintf(stderr, "%s:%d num_handles %d timeout %ld\n", __FILE__, __LINE__, num_handles, timeout); if(timeout != -1L) { int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout; interval.tv_sec = itimeout/1000; interval.tv_usec = (itimeout%1000)*1000; } else { interval.tv_sec = TEST_HANG_TIMEOUT/1000+1; interval.tv_usec = 0; /* if there's no timeout and we get here on the last handle, we may already have read the last part of the stream so waiting makes no sense */ if(!running && num_handles == MAX_EASY_HANDLES) { break; } } select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval); abort_on_test_timeout(); } test_cleanup: /* proper cleanup sequence - type PB */ for(i = 0; i < MAX_EASY_HANDLES; i++) { curl_multi_remove_handle(multi, easy[i]); curl_easy_cleanup(easy[i]); } curl_multi_cleanup(multi); curl_global_cleanup(); free(full_url); return res; }
int test(char *URL) { int res = 0; CURL *curl = NULL; int running; CURLM *m = NULL; int current = 0; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(curl); easy_setopt(curl, CURLOPT_URL, URL); easy_setopt(curl, CURLOPT_VERBOSE, 1L); easy_setopt(curl, CURLOPT_FAILONERROR, 1L); multi_init(m); multi_add_handle(m, curl); fprintf(stderr, "Start at URL 0\n"); for(;;) { struct timeval interval; fd_set rd, wr, exc; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; multi_perform(m, &running); abort_on_test_timeout(); if(!running) { if(!current++) { fprintf(stderr, "Advancing to URL 1\n"); /* remove the handle we use */ curl_multi_remove_handle(m, curl); /* make us re-use the same handle all the time, and try resetting the handle first too */ curl_easy_reset(curl); easy_setopt(curl, CURLOPT_URL, libtest_arg2); easy_setopt(curl, CURLOPT_VERBOSE, 1L); easy_setopt(curl, CURLOPT_FAILONERROR, 1L); /* re-add it */ multi_add_handle(m, curl); } else break; /* done */ } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: /* undocumented cleanup sequence - type UB */ curl_easy_cleanup(curl); curl_multi_cleanup(m); curl_global_cleanup(); return res; }
int test(char *URL) { CURL *easy = NULL; CURLM *multi = NULL; int res = 0; int running; int msgs_left; int phase; CURLMsg *msg; start_test_timing(); res_global_init(CURL_GLOBAL_ALL); if(res) { return res; } easy_init(easy); multi_init(multi); for (phase = CONNECT_ONLY_PHASE; phase < LAST_PHASE; ++phase) { /* go verbose */ easy_setopt(easy, CURLOPT_VERBOSE, 1L); /* specify target */ easy_setopt(easy, CURLOPT_URL, URL); /* enable 'CONNECT_ONLY' option when in connect phase */ if (phase == CONNECT_ONLY_PHASE) easy_setopt(easy, CURLOPT_CONNECT_ONLY, 1L); /* enable 'NOBODY' option to send 'QUIT' command in quit phase */ if (phase == QUIT_PHASE) { easy_setopt(easy, CURLOPT_CONNECT_ONLY, 0L); easy_setopt(easy, CURLOPT_NOBODY, 1L); easy_setopt(easy, CURLOPT_FORBID_REUSE, 1L); } multi_add_handle(multi, easy); for(;;) { struct timeval interval; fd_set fdread; fd_set fdwrite; fd_set fdexcep; long timeout = -99; int maxfd = -99; multi_perform(multi, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ multi_timeout(multi, &timeout); /* At this point, timeout is guaranteed to be greater or equal than -1. */ if(timeout != -1L) { int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout; interval.tv_sec = itimeout/1000; interval.tv_usec = (itimeout%1000)*1000; } else { interval.tv_sec = TEST_HANG_TIMEOUT/1000+1; interval.tv_usec = 0; } select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval); abort_on_test_timeout(); } msg = curl_multi_info_read(multi, &msgs_left); if(msg) res = msg->data.result; multi_remove_handle(multi, easy); } test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(multi); curl_easy_cleanup(easy); curl_global_cleanup(); return res; }
int test(char *URL) { int res = 0; CURL *curl = NULL; FILE *hd_src = NULL; int hd; struct_stat file_info; CURLM *m = NULL; int running; start_test_timing(); if(!libtest_arg2) { #ifdef LIB529 /* test 529 */ fprintf(stderr, "Usage: lib529 [url] [uploadfile]\n"); #else /* test 525 */ fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n"); #endif return TEST_ERR_USAGE; } hd_src = fopen(libtest_arg2, "rb"); if(NULL == hd_src) { fprintf(stderr, "fopen failed with error: %d (%s)\n", errno, strerror(errno)); fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2); return TEST_ERR_FOPEN; } /* get the file size of the local file */ hd = fstat(fileno(hd_src), &file_info); if(hd == -1) { /* can't open file, bail out */ fprintf(stderr, "fstat() failed with error: %d (%s)\n", errno, strerror(errno)); fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2); fclose(hd_src); return TEST_ERR_FSTAT; } res_global_init(CURL_GLOBAL_ALL); if(res) { fclose(hd_src); return res; } easy_init(curl); /* enable uploading */ easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ easy_setopt(curl, CURLOPT_URL, URL); /* go verbose */ easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* use active FTP */ easy_setopt(curl, CURLOPT_FTPPORT, "-"); /* now specify which file to upload */ easy_setopt(curl, CURLOPT_READDATA, hd_src); /* NOTE: if you want this code to work on Windows with libcurl as a DLL, you MUST also provide a read callback with CURLOPT_READFUNCTION. Failing to do so will give you a crash since a DLL may not use the variable's memory when passed in to it from an app like this. */ /* Set the size of the file to upload (optional). If you give a *_LARGE option you MUST make sure that the type of the passed-in argument is a curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must make sure that to pass in a type 'long' argument. */ easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); multi_init(m); multi_add_handle(m, curl); for(;;) { struct timeval interval; fd_set rd, wr, exc; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; multi_perform(m, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd+1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: #ifdef LIB529 /* test 529 */ /* proper cleanup sequence - type PA */ curl_multi_remove_handle(m, curl); curl_multi_cleanup(m); curl_easy_cleanup(curl); curl_global_cleanup(); #else /* test 525 */ /* proper cleanup sequence - type PB */ curl_multi_remove_handle(m, curl); curl_easy_cleanup(curl); curl_multi_cleanup(m); curl_global_cleanup(); #endif /* close the local file */ fclose(hd_src); return res; }
int test(char *URL) { CURLM* multi; sslctxparm p; CURLMcode res; int running; char done = FALSE; int i = 0; CURLMsg *msg; struct timeval ml_start; struct timeval mp_start; char ml_timedout = FALSE; char mp_timedout = FALSE; if(libtest_arg2) { portnum = atoi(libtest_arg2); } if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } if ((p.curl = curl_easy_init()) == NULL) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } p.accessinfoURL = (unsigned char *) strdup(URL); p.accesstype = OBJ_obj2nid(OBJ_txt2obj("AD_DVCS",0)) ; curl_easy_setopt(p.curl, CURLOPT_URL, p.accessinfoURL); curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p); curl_easy_setopt(p.curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_easy_setopt(p.curl, CURLOPT_SSL_VERIFYHOST, 1); if ((multi = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); curl_easy_cleanup(p.curl); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } if ((res = curl_multi_add_handle(multi, p.curl)) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "with code %d\n", res); curl_multi_cleanup(multi); curl_easy_cleanup(p.curl); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } fprintf(stderr, "Going to perform %s\n", (char *)p.accessinfoURL); ml_timedout = FALSE; ml_start = tutil_tvnow(); while (!done) { fd_set rd, wr, exc; int max_fd; struct timeval interval; interval.tv_sec = 1; interval.tv_usec = 0; if (tutil_tvdiff(tutil_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } mp_timedout = FALSE; mp_start = tutil_tvnow(); while (res == CURLM_CALL_MULTI_PERFORM) { res = curl_multi_perform(multi, &running); if (tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } fprintf(stderr, "running=%d res=%d\n",running,res); if (running <= 0) { done = TRUE; break; } } if (mp_timedout || done) break; if (res != CURLM_OK) { fprintf(stderr, "not okay???\n"); i = 80; break; } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); max_fd = 0; if (curl_multi_fdset(multi, &rd, &wr, &exc, &max_fd) != CURLM_OK) { fprintf(stderr, "unexpected failured of fdset.\n"); i = 89; break; } if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) { fprintf(stderr, "bad select??\n"); i =95; break; } res = CURLM_CALL_MULTI_PERFORM; } if (ml_timedout || mp_timedout) { if (ml_timedout) fprintf(stderr, "ml_timedout\n"); if (mp_timedout) fprintf(stderr, "mp_timedout\n"); fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); i = TEST_ERR_RUNS_FOREVER; } else { msg = curl_multi_info_read(multi, &running); /* this should now contain a result code from the easy handle, get it */ if(msg) i = msg->data.result; fprintf(stderr, "all done\n"); } curl_multi_remove_handle(multi, p.curl); curl_easy_cleanup(p.curl); curl_multi_cleanup(multi); curl_global_cleanup(); free(p.accessinfoURL); return i; }
int test(char *URL) { int res = 0; CURL *curl = NULL; FILE *hd_src = NULL; int hd ; int error; struct_stat file_info; CURLM *m = NULL; struct ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}}; struct timeval timeout = {-1, 0}; int success = 0; start_test_timing(); if (!libtest_arg3) { fprintf(stderr, "Usage: lib582 [url] [filename] [username]\n"); return TEST_ERR_USAGE; } hd_src = fopen(libtest_arg2, "rb"); if(NULL == hd_src) { error = ERRNO; fprintf(stderr, "fopen() failed with error: %d (%s)\n", error, strerror(error)); fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2); return TEST_ERR_FOPEN; } /* get the file size of the local file */ hd = fstat(fileno(hd_src), &file_info); if(hd == -1) { /* can't open file, bail out */ error = ERRNO; fprintf(stderr, "fstat() failed with error: %d (%s)\n", error, strerror(error)); fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2); fclose(hd_src); return TEST_ERR_FSTAT; } fprintf(stderr, "Set to upload %d bytes\n", (int)file_info.st_size); res_global_init(CURL_GLOBAL_ALL); if(res) { fclose(hd_src); return res; } easy_init(curl); /* enable uploading */ easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ easy_setopt(curl,CURLOPT_URL, URL); /* go verbose */ easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* now specify which file to upload */ easy_setopt(curl, CURLOPT_READDATA, hd_src); easy_setopt(curl, CURLOPT_USERPWD, libtest_arg3); easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "curl_client_key.pub"); easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "curl_client_key"); easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); multi_init(m); multi_setopt(m, CURLMOPT_SOCKETFUNCTION, curlSocketCallback); multi_setopt(m, CURLMOPT_SOCKETDATA, &sockets); multi_setopt(m, CURLMOPT_TIMERFUNCTION, curlTimerCallback); multi_setopt(m, CURLMOPT_TIMERDATA, &timeout); multi_add_handle(m, curl); while (!checkForCompletion(m, &success)) { fd_set readSet, writeSet; curl_socket_t maxFd = 0; struct timeval tv = {10, 0}; FD_ZERO(&readSet); FD_ZERO(&writeSet); updateFdSet(&sockets.read, &readSet, &maxFd); updateFdSet(&sockets.write, &writeSet, &maxFd); if (timeout.tv_sec != -1) { int usTimeout = getMicroSecondTimeout(&timeout); tv.tv_sec = usTimeout / 1000000; tv.tv_usec = usTimeout % 1000000; } else if (maxFd <= 0) { tv.tv_sec = 0; tv.tv_usec = 100000; } select_test(maxFd, &readSet, &writeSet, NULL, &tv); /* Check the sockets for reading / writing */ checkFdSet(m, &sockets.read, &readSet, CURL_CSELECT_IN, "read"); checkFdSet(m, &sockets.write, &writeSet, CURL_CSELECT_OUT, "write"); if (timeout.tv_sec != -1 && getMicroSecondTimeout(&timeout) == 0) { /* Curl's timer has elapsed. */ notifyCurl(m, CURL_SOCKET_TIMEOUT, 0, "timeout"); } abort_on_test_timeout(); } if (!success) { fprintf(stderr, "Error uploading file.\n"); res = TEST_ERR_MAJOR_BAD; } test_cleanup: /* proper cleanup sequence - type PB */ curl_multi_remove_handle(m, curl); curl_easy_cleanup(curl); curl_multi_cleanup(m); curl_global_cleanup(); /* close the local file */ fclose(hd_src); /* free local memory */ free(sockets.read.sockets); free(sockets.write.sockets); return res; }
/* * Source code in here hugely as reported in bug report 651464 by * Christopher R. Palmer. * * Use multi interface to get document over proxy with bad port number. * This caused the interface to "hang" in libcurl 7.10.2. */ int test(char *URL) { CURL *c; int ret=0; CURLM *m; fd_set rd, wr, exc; CURLMcode res; char done = FALSE; int running; int max_fd; int rc; struct timeval ml_start; struct timeval mp_start; char ml_timedout = FALSE; char mp_timedout = FALSE; if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } if ((c = curl_easy_init()) == NULL) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* the point here being that there must not run anything on the given proxy port */ curl_easy_setopt(c, CURLOPT_PROXY, arg2); curl_easy_setopt(c, CURLOPT_URL, URL); curl_easy_setopt(c, CURLOPT_VERBOSE, 1); if ((m = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); curl_easy_cleanup(c); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } if ((res = curl_multi_add_handle(m, c)) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "with code %d\n", res); curl_multi_cleanup(m); curl_easy_cleanup(c); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } ml_timedout = FALSE; ml_start = curlx_tvnow(); while (!done) { struct timeval interval; interval.tv_sec = 1; interval.tv_usec = 0; if (curlx_tvdiff(curlx_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } mp_timedout = FALSE; mp_start = curlx_tvnow(); fprintf(stderr, "curl_multi_perform()\n"); res = CURLM_CALL_MULTI_PERFORM; while (res == CURLM_CALL_MULTI_PERFORM) { res = curl_multi_perform(m, &running); if (curlx_tvdiff(curlx_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } } if (mp_timedout) break; if(!running) { /* This is where this code is expected to reach */ int numleft; CURLMsg *msg = curl_multi_info_read(m, &numleft); fprintf(stderr, "Expected: not running\n"); if(msg && !numleft) ret = 100; /* this is where we should be */ else ret = 99; /* not correct */ break; } fprintf(stderr, "running == %d, res == %d\n", running, res); if (res != CURLM_OK) { ret = 2; break; } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); max_fd = 0; fprintf(stderr, "curl_multi_fdset()\n"); if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) { fprintf(stderr, "unexpected failured of fdset.\n"); ret = 3; break; } rc = select_test(max_fd+1, &rd, &wr, &exc, &interval); fprintf(stderr, "select returned %d\n", rc); } if (ml_timedout || mp_timedout) { if (ml_timedout) fprintf(stderr, "ml_timedout\n"); if (mp_timedout) fprintf(stderr, "mp_timedout\n"); fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); ret = TEST_ERR_RUNS_FOREVER; } curl_multi_remove_handle(m, c); curl_easy_cleanup(c); curl_multi_cleanup(m); curl_global_cleanup(); return ret; }
/* * Simply download a HTTPS file! * * This test was added after the HTTPS-using-multi-interface with OpenSSL * regression of 7.19.1 to hopefully prevent this embarassing mistake from * appearing again... Unfortunately the bug wasn't triggered by this test, * which presumably is because the connect to a local server is too * fast/different compared to the real/distant servers we saw the bug happen * with. */ int test(char *URL) { CURL *http_handle = NULL; CURLM *multi_handle = NULL; int res = 0; int still_running; /* keep number of running handles */ start_test_timing(); /* ** curl_global_init called indirectly from curl_easy_init. */ easy_init(http_handle); /* set options */ easy_setopt(http_handle, CURLOPT_URL, URL); easy_setopt(http_handle, CURLOPT_HEADER, 1L); easy_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L); easy_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L); /* init a multi stack */ multi_init(multi_handle); /* add the individual transfers */ multi_add_handle(multi_handle, http_handle); /* we start some action by calling perform right away */ multi_perform(multi_handle, &still_running); abort_on_test_timeout(); while(still_running) { struct timeval timeout; fd_set fdread; fd_set fdwrite; fd_set fdexcep; int maxfd = -99; FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); /* set a suitable timeout to play around with */ timeout.tv_sec = 1; timeout.tv_usec = 0; /* get file descriptors from the transfers */ multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); abort_on_test_timeout(); /* timeout or readable/writable sockets */ multi_perform(multi_handle, &still_running); abort_on_test_timeout(); } test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(multi_handle); curl_easy_cleanup(http_handle); curl_global_cleanup(); return res; }
int test(char *URL) { int res = 0; CURL *curl; int running; char done=FALSE; CURLM *m = NULL; struct timeval ml_start; struct timeval mp_start; char ml_timedout = FALSE; char mp_timedout = FALSE; if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } if ((curl = curl_easy_init()) == NULL) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_VERBOSE, 1); test_setopt(curl, CURLOPT_PROXY, libtest_arg2); test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4); if ((m = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); curl_easy_cleanup(curl); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "with code %d\n", res); curl_multi_cleanup(m); curl_easy_cleanup(curl); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } ml_timedout = FALSE; ml_start = tutil_tvnow(); fprintf(stderr, "Start at URL 0\n"); while (!done) { fd_set rd, wr, exc; int max_fd; struct timeval interval; interval.tv_sec = 1; interval.tv_usec = 0; if (tutil_tvdiff(tutil_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } mp_timedout = FALSE; mp_start = tutil_tvnow(); res = (int)curl_multi_perform(m, &running); if (tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } if (running <= 0) { done = TRUE; /* bail out */ break; } if (res != CURLM_OK) { fprintf(stderr, "not okay???\n"); break; } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); max_fd = 0; if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) { fprintf(stderr, "unexpected failured of fdset.\n"); res = 189; break; } if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) { fprintf(stderr, "bad select??\n"); res = 195; break; } } if (ml_timedout || mp_timedout) { if (ml_timedout) fprintf(stderr, "ml_timedout\n"); if (mp_timedout) fprintf(stderr, "mp_timedout\n"); fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); res = TEST_ERR_RUNS_FOREVER; } test_cleanup: curl_easy_cleanup(curl); if(m) curl_multi_cleanup(m); curl_global_cleanup(); return res; }
int test(char *URL) { int res = 0; CURL *curl; int running; char done=FALSE; CURLM *m; int current=0; struct timeval ml_start; struct timeval mp_start; char ml_timedout = FALSE; char mp_timedout = FALSE; if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } if ((curl = curl_easy_init()) == NULL) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } curl_easy_setopt(curl, CURLOPT_URL, URL); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); if ((m = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); curl_easy_cleanup(curl); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "with code %d\n", res); curl_multi_cleanup(m); curl_easy_cleanup(curl); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } ml_timedout = FALSE; ml_start = tutil_tvnow(); fprintf(stderr, "Start at URL 0\n"); while (!done) { fd_set rd, wr, exc; int max_fd; struct timeval interval; interval.tv_sec = 1; interval.tv_usec = 0; if (tutil_tvdiff(tutil_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } mp_timedout = FALSE; mp_start = tutil_tvnow(); while (res == CURLM_CALL_MULTI_PERFORM) { res = (int)curl_multi_perform(m, &running); if (tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } if (running <= 0) { if(!current++) { fprintf(stderr, "Advancing to URL 1\n"); /* remove the handle we use */ curl_multi_remove_handle(m, curl); /* make us re-use the same handle all the time, and try resetting the handle first too */ curl_easy_reset(curl); curl_easy_setopt(curl, CURLOPT_URL, arg2); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); /* re-add it */ res = (int)curl_multi_add_handle(m, curl); if(res) { fprintf(stderr, "add handle failed: %d.\n", res); res = 243; break; } } else done = TRUE; /* bail out */ break; } } if (mp_timedout || done) break; if (res != CURLM_OK) { fprintf(stderr, "not okay???\n"); break; } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); max_fd = 0; if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) { fprintf(stderr, "unexpected failured of fdset.\n"); res = 189; break; } if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) { fprintf(stderr, "bad select??\n"); res = 195; break; } res = CURLM_CALL_MULTI_PERFORM; } if (ml_timedout || mp_timedout) { if (ml_timedout) fprintf(stderr, "ml_timedout\n"); if (mp_timedout) fprintf(stderr, "mp_timedout\n"); fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); res = TEST_ERR_RUNS_FOREVER; } curl_easy_cleanup(curl); curl_multi_cleanup(m); curl_global_cleanup(); return res; }
int test(char *URL) { CURL *c = NULL; CURLM *m = NULL; int res = 0; int running; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(c); easy_setopt(c, CURLOPT_PROXY, libtest_arg2); /* set in first.c */ easy_setopt(c, CURLOPT_URL, URL); easy_setopt(c, CURLOPT_USERPWD, "test:ing"); easy_setopt(c, CURLOPT_PROXYUSERPWD, "test:ing"); easy_setopt(c, CURLOPT_HTTPPROXYTUNNEL, 1L); easy_setopt(c, CURLOPT_HEADER, 1L); easy_setopt(c, CURLOPT_VERBOSE, 1L); multi_init(m); multi_add_handle(m, c); for(;;) { struct timeval interval; fd_set rd, wr, exc; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; multi_perform(m, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: /* proper cleanup sequence - type PA */ curl_multi_remove_handle(m, c); curl_multi_cleanup(m); curl_easy_cleanup(c); curl_global_cleanup(); return res; }
int test(char *URL) { CURL *c; CURLM *m = NULL; int res = 0; int running; char done = FALSE; struct timeval ml_start; struct timeval mp_start; char ml_timedout = FALSE; char mp_timedout = FALSE; if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } if ((c = curl_easy_init()) == NULL) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(c, CURLOPT_PROXY, libtest_arg2); /* set in first.c */ test_setopt(c, CURLOPT_URL, URL); test_setopt(c, CURLOPT_USERPWD, "test:ing"); test_setopt(c, CURLOPT_PROXYUSERPWD, "test:ing"); test_setopt(c, CURLOPT_HTTPPROXYTUNNEL, 1L); test_setopt(c, CURLOPT_HEADER, 1L); if ((m = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); curl_easy_cleanup(c); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } if ((res = (int)curl_multi_add_handle(m, c)) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "with code %d\n", res); curl_multi_cleanup(m); curl_easy_cleanup(c); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } ml_timedout = FALSE; ml_start = tutil_tvnow(); while(!done) { fd_set rd, wr, exc; int max_fd; struct timeval interval; interval.tv_sec = 1; interval.tv_usec = 0; if (tutil_tvdiff(tutil_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } mp_timedout = FALSE; mp_start = tutil_tvnow(); while (res == CURLM_CALL_MULTI_PERFORM) { res = (int)curl_multi_perform(m, &running); if (tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } if (running <= 0) { done = TRUE; break; } } if (mp_timedout || done) break; if (res != CURLM_OK) { fprintf(stderr, "not okay???\n"); break; } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); max_fd = 0; if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) { fprintf(stderr, "unexpected failured of fdset.\n"); res = 89; break; } if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) { fprintf(stderr, "bad select??\n"); res = 95; break; } res = CURLM_CALL_MULTI_PERFORM; } if (ml_timedout || mp_timedout) { if (ml_timedout) fprintf(stderr, "ml_timedout\n"); if (mp_timedout) fprintf(stderr, "mp_timedout\n"); fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); res = TEST_ERR_RUNS_FOREVER; } test_cleanup: if(m) { curl_multi_remove_handle(m, c); curl_multi_cleanup(m); } curl_easy_cleanup(c); curl_global_cleanup(); return res; }
int test(char *URL) { CURL *handle = NULL; CURL *duphandle = NULL; CURLM *mhandle = NULL; int res = 0; int still_running = 0; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(handle); easy_setopt(handle, CURLOPT_URL, URL); easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L); easy_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; multi_init(mhandle); multi_add_handle(mhandle, handle); multi_perform(mhandle, &still_running); abort_on_test_timeout(); while(still_running) { struct timeval timeout; fd_set fdread; fd_set fdwrite; fd_set fdexcep; int maxfd = -99; timeout.tv_sec = 0; timeout.tv_usec = 100000L; /* 100 ms */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); abort_on_test_timeout(); multi_perform(mhandle, &still_running); abort_on_test_timeout(); } test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(mhandle); curl_easy_cleanup(handle); curl_global_cleanup(); return res; }
int test(char *URL) { CURL* curls; CURLM* multi; int still_running; int i = -1; CURLMsg *msg; CURLMcode res; struct timeval ml_start; struct timeval mp_start; char ml_timedout = FALSE; char mp_timedout = FALSE; if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } if ((multi = curl_multi_init()) == NULL) { fprintf(stderr, "curl_multi_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } if ((curls = curl_easy_init()) == NULL) { fprintf(stderr, "curl_easy_init() failed\n"); curl_multi_cleanup(multi); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } curl_easy_setopt(curls, CURLOPT_URL, URL); if ((res = curl_multi_add_handle(multi, curls)) != CURLM_OK) { fprintf(stderr, "curl_multi_add_handle() failed, " "with code %d\n", res); curl_easy_cleanup(curls); curl_multi_cleanup(multi); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } mp_timedout = FALSE; mp_start = tutil_tvnow(); do { res = curl_multi_perform(multi, &still_running); if (tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } } while (res == CURLM_CALL_MULTI_PERFORM); ml_timedout = FALSE; ml_start = tutil_tvnow(); while ((!ml_timedout) && (!mp_timedout) && (still_running)) { struct timeval timeout; int rc; fd_set fdread; fd_set fdwrite; fd_set fdexcep; int maxfd; FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); timeout.tv_sec = 1; timeout.tv_usec = 0; if (tutil_tvdiff(tutil_tvnow(), ml_start) > MAIN_LOOP_HANG_TIMEOUT) { ml_timedout = TRUE; break; } curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); rc = select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); switch(rc) { case -1: break; case 0: default: mp_timedout = FALSE; mp_start = tutil_tvnow(); do { res = curl_multi_perform(multi, &still_running); if (tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { mp_timedout = TRUE; break; } } while (res == CURLM_CALL_MULTI_PERFORM); break; } } if (ml_timedout || mp_timedout) { if (ml_timedout) fprintf(stderr, "ml_timedout\n"); if (mp_timedout) fprintf(stderr, "mp_timedout\n"); fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); i = TEST_ERR_RUNS_FOREVER; } else { msg = curl_multi_info_read(multi, &still_running); if(msg) /* this should now contain a result code from the easy handle, get it */ i = msg->data.result; } curl_multi_cleanup(multi); curl_easy_cleanup(curls); curl_global_cleanup(); return i; /* return the final return code */ }