Annotation of embedaddon/curl/tests/libtest/lib597.c, revision 1.1

1.1     ! misho       1: /***************************************************************************
        !             2:  *                                  _   _ ____  _
        !             3:  *  Project                     ___| | | |  _ \| |
        !             4:  *                             / __| | | | |_) | |
        !             5:  *                            | (__| |_| |  _ <| |___
        !             6:  *                             \___|\___/|_| \_\_____|
        !             7:  *
        !             8:  * Copyright (C) 1998 - 2019, 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.haxx.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:  ***************************************************************************/
        !            22: #include "test.h"
        !            23: 
        !            24: #include <limits.h>
        !            25: 
        !            26: #include "testutil.h"
        !            27: #include "warnless.h"
        !            28: #include "memdebug.h"
        !            29: 
        !            30: #define TEST_HANG_TIMEOUT 5 * 1000
        !            31: 
        !            32: /*
        !            33:  * Test case for below scenario:
        !            34:  *   - Connect to an FTP server using CONNECT_ONLY option
        !            35:  *
        !            36:  * The test case originated for verifying CONNECT_ONLY option shall not
        !            37:  * block after protocol connect is done, but it returns the message
        !            38:  * with function curl_multi_info_read().
        !            39:  */
        !            40: 
        !            41: int test(char *URL)
        !            42: {
        !            43:   CURL *easy = NULL;
        !            44:   CURLM *multi = NULL;
        !            45:   int res = 0;
        !            46:   int running;
        !            47:   int msgs_left;
        !            48:   CURLMsg *msg;
        !            49: 
        !            50:   start_test_timing();
        !            51: 
        !            52:   global_init(CURL_GLOBAL_ALL);
        !            53: 
        !            54:   easy_init(easy);
        !            55: 
        !            56:   multi_init(multi);
        !            57: 
        !            58:   /* go verbose */
        !            59:   easy_setopt(easy, CURLOPT_VERBOSE, 1L);
        !            60: 
        !            61:   /* specify target */
        !            62:   easy_setopt(easy, CURLOPT_URL, URL);
        !            63: 
        !            64:   easy_setopt(easy, CURLOPT_CONNECT_ONLY, 1L);
        !            65: 
        !            66:   multi_add_handle(multi, easy);
        !            67: 
        !            68:   for(;;) {
        !            69:     struct timeval interval;
        !            70:     fd_set fdread;
        !            71:     fd_set fdwrite;
        !            72:     fd_set fdexcep;
        !            73:     long timeout = -99;
        !            74:     int maxfd = -99;
        !            75: 
        !            76:     multi_perform(multi, &running);
        !            77: 
        !            78:     abort_on_test_timeout();
        !            79: 
        !            80:     if(!running)
        !            81:       break; /* done */
        !            82: 
        !            83:     FD_ZERO(&fdread);
        !            84:     FD_ZERO(&fdwrite);
        !            85:     FD_ZERO(&fdexcep);
        !            86: 
        !            87:     multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
        !            88: 
        !            89:     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
        !            90: 
        !            91:     multi_timeout(multi, &timeout);
        !            92: 
        !            93:     /* At this point, timeout is guaranteed to be greater or equal than
        !            94:        -1. */
        !            95: 
        !            96:     if(timeout != -1L) {
        !            97:       int itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
        !            98:       interval.tv_sec = itimeout/1000;
        !            99:       interval.tv_usec = (itimeout%1000)*1000;
        !           100:     }
        !           101:     else {
        !           102:       interval.tv_sec = TEST_HANG_TIMEOUT/1000 + 1;
        !           103:       interval.tv_usec = 0;
        !           104:     }
        !           105: 
        !           106:     select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval);
        !           107: 
        !           108:     abort_on_test_timeout();
        !           109:   }
        !           110: 
        !           111:   msg = curl_multi_info_read(multi, &msgs_left);
        !           112:   if(msg)
        !           113:     res = msg->data.result;
        !           114: 
        !           115:   multi_remove_handle(multi, easy);
        !           116: 
        !           117: test_cleanup:
        !           118: 
        !           119:   /* undocumented cleanup sequence - type UA */
        !           120: 
        !           121:   curl_multi_cleanup(multi);
        !           122:   curl_easy_cleanup(easy);
        !           123:   curl_global_cleanup();
        !           124: 
        !           125:   return res;
        !           126: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>