lib1506.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 2013, Linus Nielsen Feltzing <linus@haxx.se>
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "test.h"
00023 
00024 #include "testutil.h"
00025 #include "warnless.h"
00026 #include "memdebug.h"
00027 
00028 #define TEST_HANG_TIMEOUT 60 * 1000
00029 
00030 #define NUM_HANDLES 4
00031 
00032 int test(char *URL)
00033 {
00034   int res = 0;
00035   CURL *curl[NUM_HANDLES] = {0};
00036   int running;
00037   CURLM *m = NULL;
00038   int i;
00039   char target_url[256];
00040   char dnsentry[256];
00041   struct curl_slist *slist = NULL, *slist2;
00042   char *port = libtest_arg3;
00043   char *address = libtest_arg2;
00044 
00045   (void)URL;
00046 
00047   /* Create fake DNS entries for serverX.example.com for all handles */
00048   for(i=0; i < NUM_HANDLES; i++) {
00049     snprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s",
00050              i + 1, port, address);
00051     printf("%s\n", dnsentry);
00052     slist2 = curl_slist_append(slist, dnsentry);
00053     if(!slist2) {
00054       fprintf(stderr, "curl_slist_append() failed\n");
00055       goto test_cleanup;
00056     }
00057     slist = slist2;
00058   }
00059 
00060   start_test_timing();
00061 
00062   global_init(CURL_GLOBAL_ALL);
00063 
00064   multi_init(m);
00065 
00066   multi_setopt(m, CURLMOPT_MAXCONNECTS, 3L);
00067 
00068   /* get NUM_HANDLES easy handles */
00069   for(i=0; i < NUM_HANDLES; i++) {
00070     /* get an easy handle */
00071     easy_init(curl[i]);
00072     /* specify target */
00073     snprintf(target_url, sizeof(target_url),
00074              "http://server%d.example.com:%s/path/1506%04i",
00075              i + 1, port, i + 1);
00076     target_url[sizeof(target_url) - 1] = '\0';
00077     easy_setopt(curl[i], CURLOPT_URL, target_url);
00078     /* go verbose */
00079     easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
00080     /* include headers */
00081     easy_setopt(curl[i], CURLOPT_HEADER, 1L);
00082 
00083     easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
00084   }
00085 
00086   fprintf(stderr, "Start at URL 0\n");
00087 
00088   for(i=0; i < NUM_HANDLES; i++) {
00089     /* add handle to multi */
00090     multi_add_handle(m, curl[i]);
00091 
00092     for(;;) {
00093       struct timeval interval;
00094       fd_set rd, wr, exc;
00095       int maxfd = -99;
00096 
00097       interval.tv_sec = 1;
00098       interval.tv_usec = 0;
00099 
00100       multi_perform(m, &running);
00101 
00102       abort_on_test_timeout();
00103 
00104       if(!running)
00105         break; /* done */
00106 
00107       FD_ZERO(&rd);
00108       FD_ZERO(&wr);
00109       FD_ZERO(&exc);
00110 
00111       multi_fdset(m, &rd, &wr, &exc, &maxfd);
00112 
00113       /* At this point, maxfd is guaranteed to be greater or equal than -1. */
00114 
00115       select_test(maxfd+1, &rd, &wr, &exc, &interval);
00116 
00117       abort_on_test_timeout();
00118     }
00119     wait_ms(1); /* to ensure different end times */
00120   }
00121 
00122 test_cleanup:
00123 
00124   /* proper cleanup sequence - type PB */
00125 
00126   for(i=0; i < NUM_HANDLES; i++) {
00127     curl_multi_remove_handle(m, curl[i]);
00128     curl_easy_cleanup(curl[i]);
00129   }
00130 
00131   curl_slist_free_all(slist);
00132 
00133   curl_multi_cleanup(m);
00134   curl_global_cleanup();
00135 
00136   return res;
00137 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05