lib591.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2012, 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 /* lib591 is used for test cases 591, 592, 593 and 594 */
00025 
00026 #ifdef HAVE_LIMITS_H
00027 #include <limits.h>
00028 #endif
00029 
00030 #include <fcntl.h>
00031 
00032 #include "testutil.h"
00033 #include "warnless.h"
00034 #include "memdebug.h"
00035 
00036 #define TEST_HANG_TIMEOUT 60 * 1000
00037 
00038 int test(char *URL)
00039 {
00040   CURL *easy = NULL;
00041   CURLM *multi = NULL;
00042   int res = 0;
00043   int running;
00044   int msgs_left;
00045   CURLMsg *msg;
00046   FILE *upload = NULL;
00047   int error;
00048 
00049   start_test_timing();
00050 
00051   upload = fopen(libtest_arg3, "rb");
00052   if(!upload) {
00053     error = ERRNO;
00054     fprintf(stderr, "fopen() failed with error: %d (%s)\n",
00055             error, strerror(error));
00056     fprintf(stderr, "Error opening file: (%s)\n", libtest_arg3);
00057     return TEST_ERR_FOPEN;
00058   }
00059 
00060   res_global_init(CURL_GLOBAL_ALL);
00061   if(res) {
00062     fclose(upload);
00063     return res;
00064   }
00065 
00066   easy_init(easy);
00067 
00068   /* go verbose */
00069   easy_setopt(easy, CURLOPT_VERBOSE, 1L);
00070 
00071   /* specify target */
00072   easy_setopt(easy, CURLOPT_URL, URL);
00073 
00074   /* enable uploading */
00075   easy_setopt(easy, CURLOPT_UPLOAD, 1L);
00076 
00077   /* data pointer for the file read function */
00078   easy_setopt(easy, CURLOPT_READDATA, upload);
00079 
00080   /* use active mode FTP */
00081   easy_setopt(easy, CURLOPT_FTPPORT, "-");
00082 
00083   /* server connection timeout */
00084   easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS,
00085               strtol(libtest_arg2, NULL, 10)*1000);
00086 
00087   multi_init(multi);
00088 
00089   multi_add_handle(multi, easy);
00090 
00091   for(;;) {
00092     struct timeval interval;
00093     fd_set fdread;
00094     fd_set fdwrite;
00095     fd_set fdexcep;
00096     long timeout = -99;
00097     int maxfd = -99;
00098 
00099     multi_perform(multi, &running);
00100 
00101     abort_on_test_timeout();
00102 
00103     if(!running)
00104       break; /* done */
00105 
00106     FD_ZERO(&fdread);
00107     FD_ZERO(&fdwrite);
00108     FD_ZERO(&fdexcep);
00109 
00110     multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
00111 
00112     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
00113 
00114     multi_timeout(multi, &timeout);
00115 
00116     /* At this point, timeout is guaranteed to be greater or equal than -1. */
00117 
00118     if(timeout != -1L) {
00119       int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
00120       interval.tv_sec = itimeout/1000;
00121       interval.tv_usec = (itimeout%1000)*1000;
00122     }
00123     else {
00124       interval.tv_sec = 0;
00125       interval.tv_usec = 100000L; /* 100 ms */
00126     }
00127 
00128     select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval);
00129 
00130     abort_on_test_timeout();
00131   }
00132 
00133   msg = curl_multi_info_read(multi, &msgs_left);
00134   if(msg)
00135     res = msg->data.result;
00136 
00137 test_cleanup:
00138 
00139   /* undocumented cleanup sequence - type UA */
00140 
00141   curl_multi_cleanup(multi);
00142   curl_easy_cleanup(easy);
00143   curl_global_cleanup();
00144 
00145   /* close the local file */
00146   fclose(upload);
00147 
00148   return res;
00149 }


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