quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

lib591.c (3623B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      9  *
     10  * This software is licensed as described in the file COPYING, which
     11  * you should have received as part of this distribution. The terms
     12  * are also available at https://curl.se/docs/copyright.html.
     13  *
     14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     15  * copies of the Software, and permit persons to whom the Software is
     16  * furnished to do so, under the terms of the COPYING file.
     17  *
     18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     19  * KIND, either express or implied.
     20  *
     21  * SPDX-License-Identifier: curl
     22  *
     23  ***************************************************************************/
     24 /* lib591 is used for test cases 591, 592, 593 and 594 */
     25 
     26 #include "first.h"
     27 
     28 #include "memdebug.h"
     29 
     30 static CURLcode test_lib591(char *URL)
     31 {
     32   CURL *easy = NULL;
     33   CURLM *multi = NULL;
     34   CURLcode res = CURLE_OK;
     35   int running;
     36   int msgs_left;
     37   CURLMsg *msg;
     38   FILE *upload = NULL;
     39 
     40   start_test_timing();
     41 
     42   upload = fopen(libtest_arg3, "rb");
     43   if(!upload) {
     44     curl_mfprintf(stderr, "fopen() failed with error (%d) %s\n",
     45                   errno, strerror(errno));
     46     curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg3);
     47     return TEST_ERR_FOPEN;
     48   }
     49 
     50   res_global_init(CURL_GLOBAL_ALL);
     51   if(res) {
     52     fclose(upload);
     53     return res;
     54   }
     55 
     56   easy_init(easy);
     57 
     58   /* go verbose */
     59   easy_setopt(easy, CURLOPT_VERBOSE, 1L);
     60 
     61   /* specify target */
     62   easy_setopt(easy, CURLOPT_URL, URL);
     63 
     64   /* enable uploading */
     65   easy_setopt(easy, CURLOPT_UPLOAD, 1L);
     66 
     67   /* data pointer for the file read function */
     68   easy_setopt(easy, CURLOPT_READDATA, upload);
     69 
     70   /* use active mode FTP */
     71   easy_setopt(easy, CURLOPT_FTPPORT, "-");
     72 
     73   /* server connection timeout */
     74   easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS,
     75               strtol(libtest_arg2, NULL, 10)*1000);
     76 
     77   multi_init(multi);
     78 
     79   multi_add_handle(multi, easy);
     80 
     81   for(;;) {
     82     struct timeval interval;
     83     fd_set fdread;
     84     fd_set fdwrite;
     85     fd_set fdexcep;
     86     long timeout = -99;
     87     int maxfd = -99;
     88 
     89     multi_perform(multi, &running);
     90 
     91     abort_on_test_timeout();
     92 
     93     if(!running)
     94       break; /* done */
     95 
     96     FD_ZERO(&fdread);
     97     FD_ZERO(&fdwrite);
     98     FD_ZERO(&fdexcep);
     99 
    100     multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
    101 
    102     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
    103 
    104     multi_timeout(multi, &timeout);
    105 
    106     /* At this point, timeout is guaranteed to be greater or equal than -1. */
    107 
    108     if(timeout != -1L) {
    109       int itimeout;
    110 #if LONG_MAX > INT_MAX
    111       itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
    112 #else
    113       itimeout = (int)timeout;
    114 #endif
    115       interval.tv_sec = itimeout/1000;
    116       interval.tv_usec = (itimeout%1000)*1000;
    117     }
    118     else {
    119       interval.tv_sec = 0;
    120       interval.tv_usec = 100000L; /* 100 ms */
    121     }
    122 
    123     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);
    124 
    125     abort_on_test_timeout();
    126   }
    127 
    128   msg = curl_multi_info_read(multi, &msgs_left);
    129   if(msg)
    130     res = msg->data.result;
    131 
    132 test_cleanup:
    133 
    134   /* undocumented cleanup sequence - type UA */
    135 
    136   curl_multi_cleanup(multi);
    137   curl_easy_cleanup(easy);
    138   curl_global_cleanup();
    139 
    140   /* close the local file */
    141   fclose(upload);
    142 
    143   return res;
    144 }