lib526.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2011, 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 /*
00023  * This code sets up multiple easy handles that transfer a single file from
00024  * the same URL, in a serial manner after each other. Due to the connection
00025  * sharing within the multi handle all transfers are performed on the same
00026  * persistent connection.
00027  *
00028  * This source code is used for lib526, lib527 and lib532 with only #ifdefs
00029  * controlling the small differences.
00030  *
00031  * - lib526 closes all easy handles after
00032  *   they all have transfered the file over the single connection
00033  * - lib527 closes each easy handle after each single transfer.
00034  * - lib532 uses only a single easy handle that is removed, reset and then
00035  *   re-added for each transfer
00036  *
00037  * Test case 526, 527 and 532 use FTP, while test 528 uses the lib526 tool but
00038  * with HTTP.
00039  */
00040 
00041 #include "test.h"
00042 
00043 #include <fcntl.h>
00044 
00045 #include "testutil.h"
00046 #include "warnless.h"
00047 #include "memdebug.h"
00048 
00049 #define TEST_HANG_TIMEOUT 60 * 1000
00050 
00051 #define NUM_HANDLES 4
00052 
00053 int test(char *URL)
00054 {
00055   int res = 0;
00056   CURL *curl[NUM_HANDLES];
00057   int running;
00058   CURLM *m = NULL;
00059   int current = 0;
00060   int i;
00061 
00062   for(i=0; i < NUM_HANDLES; i++)
00063     curl[i] = NULL;
00064 
00065   start_test_timing();
00066 
00067   global_init(CURL_GLOBAL_ALL);
00068 
00069   /* get NUM_HANDLES easy handles */
00070   for(i=0; i < NUM_HANDLES; i++) {
00071     easy_init(curl[i]);
00072     /* specify target */
00073     easy_setopt(curl[i], CURLOPT_URL, URL);
00074     /* go verbose */
00075     easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
00076   }
00077 
00078   multi_init(m);
00079 
00080   multi_add_handle(m, curl[current]);
00081 
00082   fprintf(stderr, "Start at URL 0\n");
00083 
00084   for(;;) {
00085     struct timeval interval;
00086     fd_set rd, wr, exc;
00087     int maxfd = -99;
00088 
00089     interval.tv_sec = 1;
00090     interval.tv_usec = 0;
00091 
00092     multi_perform(m, &running);
00093 
00094     abort_on_test_timeout();
00095 
00096     if(!running) {
00097 #ifdef LIB527
00098       /* NOTE: this code does not remove the handle from the multi handle
00099          here, which would be the nice, sane and documented way of working.
00100          This however tests that the API survives this abuse gracefully. */
00101       curl_easy_cleanup(curl[current]);
00102       curl[current] = NULL;
00103 #endif
00104       if(++current < NUM_HANDLES) {
00105         fprintf(stderr, "Advancing to URL %d\n", current);
00106 #ifdef LIB532
00107         /* first remove the only handle we use */
00108         curl_multi_remove_handle(m, curl[0]);
00109 
00110         /* make us re-use the same handle all the time, and try resetting
00111            the handle first too */
00112         curl_easy_reset(curl[0]);
00113         easy_setopt(curl[0], CURLOPT_URL, URL);
00114         /* go verbose */
00115         easy_setopt(curl[0], CURLOPT_VERBOSE, 1L);
00116 
00117         /* re-add it */
00118         multi_add_handle(m, curl[0]);
00119 #else
00120         multi_add_handle(m, curl[current]);
00121 #endif
00122       }
00123       else {
00124         break; /* done */
00125       }
00126     }
00127 
00128     FD_ZERO(&rd);
00129     FD_ZERO(&wr);
00130     FD_ZERO(&exc);
00131 
00132     multi_fdset(m, &rd, &wr, &exc, &maxfd);
00133 
00134     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
00135 
00136     select_test(maxfd+1, &rd, &wr, &exc, &interval);
00137 
00138     abort_on_test_timeout();
00139   }
00140 
00141 test_cleanup:
00142 
00143 #if defined(LIB526)
00144 
00145   /* test 526 and 528 */
00146   /* proper cleanup sequence - type PB */
00147 
00148   for(i=0; i < NUM_HANDLES; i++) {
00149     curl_multi_remove_handle(m, curl[i]);
00150     curl_easy_cleanup(curl[i]);
00151   }
00152   curl_multi_cleanup(m);
00153   curl_global_cleanup();
00154 
00155 #elif defined(LIB527)
00156 
00157   /* test 527 */
00158 
00159   /* Upon non-failure test flow the easy's have already been cleanup'ed. In
00160      case there is a failure we arrive here with easy's that have not been
00161      cleanup'ed yet, in this case we have to cleanup them or otherwise these
00162      will be leaked, let's use undocumented cleanup sequence - type UB */
00163 
00164   if(res)
00165     for(i=0; i < NUM_HANDLES; i++)
00166       curl_easy_cleanup(curl[i]);
00167 
00168   curl_multi_cleanup(m);
00169   curl_global_cleanup();
00170 
00171 #elif defined(LIB532)
00172 
00173   /* test 532 */
00174   /* undocumented cleanup sequence - type UB */
00175 
00176   for(i=0; i < NUM_HANDLES; i++)
00177     curl_easy_cleanup(curl[i]);
00178   curl_multi_cleanup(m);
00179   curl_global_cleanup();
00180 
00181 #endif
00182 
00183   return res;
00184 }


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