lib597.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 #ifdef HAVE_LIMITS_H
00025 #include <limits.h>
00026 #endif
00027 
00028 #include "testutil.h"
00029 #include "warnless.h"
00030 #include "memdebug.h"
00031 
00032 #define TEST_HANG_TIMEOUT 5 * 1000
00033 
00034 /*
00035  * Test case for below scenario:
00036  *   - Connect to an FTP server using CONNECT_ONLY option
00037  *   - transfer some files with re-using the connection (omitted in test case)
00038  *   - Disconnect from FTP server with sending QUIT command
00039  *
00040  * The test case originated for verifying CONNECT_ONLY option shall not
00041  * block after protocol connect is done, but it returns the message
00042  * with function curl_multi_info_read().
00043  */
00044 
00045 enum {
00046   CONNECT_ONLY_PHASE = 0,
00047   QUIT_PHASE,
00048   LAST_PHASE
00049 };
00050 
00051 int test(char *URL)
00052 {
00053   CURL *easy = NULL;
00054   CURLM *multi = NULL;
00055   int res = 0;
00056   int running;
00057   int msgs_left;
00058   int phase;
00059   CURLMsg *msg;
00060 
00061   start_test_timing();
00062 
00063   res_global_init(CURL_GLOBAL_ALL);
00064   if(res) {
00065     return res;
00066   }
00067 
00068   easy_init(easy);
00069 
00070   multi_init(multi);
00071 
00072   for(phase = CONNECT_ONLY_PHASE; phase < LAST_PHASE; ++phase) {
00073     /* go verbose */
00074     easy_setopt(easy, CURLOPT_VERBOSE, 1L);
00075 
00076     /* specify target */
00077     easy_setopt(easy, CURLOPT_URL, URL);
00078 
00079     /* enable 'CONNECT_ONLY' option when in connect phase */
00080     if(phase == CONNECT_ONLY_PHASE)
00081       easy_setopt(easy, CURLOPT_CONNECT_ONLY, 1L);
00082 
00083     /* enable 'NOBODY' option to send 'QUIT' command in quit phase */
00084     if(phase == QUIT_PHASE) {
00085       easy_setopt(easy, CURLOPT_CONNECT_ONLY, 0L);
00086       easy_setopt(easy, CURLOPT_NOBODY, 1L);
00087       easy_setopt(easy, CURLOPT_FORBID_REUSE, 1L);
00088     }
00089 
00090     multi_add_handle(multi, easy);
00091 
00092     for(;;) {
00093       struct timeval interval;
00094       fd_set fdread;
00095       fd_set fdwrite;
00096       fd_set fdexcep;
00097       long timeout = -99;
00098       int maxfd = -99;
00099 
00100       multi_perform(multi, &running);
00101 
00102       abort_on_test_timeout();
00103 
00104       if(!running)
00105         break; /* done */
00106 
00107       FD_ZERO(&fdread);
00108       FD_ZERO(&fdwrite);
00109       FD_ZERO(&fdexcep);
00110 
00111       multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
00112 
00113       /* At this point, maxfd is guaranteed to be greater or equal than -1. */
00114 
00115       multi_timeout(multi, &timeout);
00116 
00117       /* At this point, timeout is guaranteed to be greater or equal than
00118          -1. */
00119 
00120       if(timeout != -1L) {
00121         int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
00122         interval.tv_sec = itimeout/1000;
00123         interval.tv_usec = (itimeout%1000)*1000;
00124       }
00125       else {
00126         interval.tv_sec = TEST_HANG_TIMEOUT/1000+1;
00127         interval.tv_usec = 0;
00128       }
00129 
00130       select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval);
00131 
00132       abort_on_test_timeout();
00133     }
00134 
00135     msg = curl_multi_info_read(multi, &msgs_left);
00136     if(msg)
00137       res = msg->data.result;
00138 
00139     multi_remove_handle(multi, easy);
00140   }
00141 
00142 test_cleanup:
00143 
00144   /* undocumented cleanup sequence - type UA */
00145 
00146   curl_multi_cleanup(multi);
00147   curl_easy_cleanup(easy);
00148   curl_global_cleanup();
00149 
00150   return res;
00151 }


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