lib530.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
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];
00036   int running;
00037   CURLM *m = NULL;
00038   int i;
00039   char target_url[256];
00040   int handles_added = 0;
00041 
00042   for(i=0; i < NUM_HANDLES; i++)
00043     curl[i] = NULL;
00044 
00045   start_test_timing();
00046 
00047   global_init(CURL_GLOBAL_ALL);
00048 
00049   multi_init(m);
00050 
00051   /* get NUM_HANDLES easy handles */
00052   for(i=0; i < NUM_HANDLES; i++) {
00053     /* get an easy handle */
00054     easy_init(curl[i]);
00055     /* specify target */
00056     snprintf(target_url, sizeof(target_url), "%s%04i", URL, i + 1);
00057     target_url[sizeof(target_url) - 1] = '\0';
00058     easy_setopt(curl[i], CURLOPT_URL, target_url);
00059     /* go verbose */
00060     easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
00061     /* include headers */
00062     easy_setopt(curl[i], CURLOPT_HEADER, 1L);
00063   }
00064 
00065   /* Add the first handle to multi. We do this to let libcurl detect
00066      that the server can do pipelining. The rest of the handles will be
00067      added later. */
00068   multi_add_handle(m, curl[handles_added++]);
00069 
00070   multi_setopt(m, CURLMOPT_PIPELINING, 1L);
00071 
00072   fprintf(stderr, "Start at URL 0\n");
00073 
00074   for(;;) {
00075     struct timeval interval;
00076     fd_set rd, wr, exc;
00077     int maxfd = -99;
00078 
00079     interval.tv_sec = 1;
00080     interval.tv_usec = 0;
00081 
00082     multi_perform(m, &running);
00083 
00084     abort_on_test_timeout();
00085 
00086     if(!running) {
00087       if(handles_added >= NUM_HANDLES)
00088         break; /* done */
00089 
00090       /* Add the rest of the handles now that the first handle has completed
00091          its request. */
00092       while(handles_added < NUM_HANDLES)
00093         multi_add_handle(m, curl[handles_added++]);
00094     }
00095 
00096     FD_ZERO(&rd);
00097     FD_ZERO(&wr);
00098     FD_ZERO(&exc);
00099 
00100     multi_fdset(m, &rd, &wr, &exc, &maxfd);
00101 
00102     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
00103 
00104     select_test(maxfd+1, &rd, &wr, &exc, &interval);
00105 
00106     abort_on_test_timeout();
00107   }
00108 
00109 test_cleanup:
00110 
00111   /* proper cleanup sequence - type PB */
00112 
00113   for(i=0; i < NUM_HANDLES; i++) {
00114     curl_multi_remove_handle(m, curl[i]);
00115     curl_easy_cleanup(curl[i]);
00116   }
00117 
00118   curl_multi_cleanup(m);
00119   curl_global_cleanup();
00120 
00121   return res;
00122 }


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