lib1501.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 #include <fcntl.h>
00025 
00026 #include "testutil.h"
00027 #include "warnless.h"
00028 #include "memdebug.h"
00029 
00030 #define TEST_HANG_TIMEOUT 30 * 1000
00031 
00032 /* 500 milliseconds allowed. An extreme number but lets be really conservative
00033    to allow old and slow machines to run this test too */
00034 #define MAX_BLOCKED_TIME_US 500000
00035 
00036 /* return the number of microseconds between two time stamps */
00037 static int elapsed(struct timeval *before,
00038                    struct timeval *after)
00039 {
00040   ssize_t result;
00041 
00042   result = (after->tv_sec - before->tv_sec) * 1000000 +
00043     after->tv_usec - before->tv_usec;
00044   if(result < 0)
00045     result = 0;
00046 
00047   return curlx_sztosi(result);
00048 }
00049 
00050 
00051 int test(char *URL)
00052 {
00053   CURL *handle = NULL;
00054   CURLM *mhandle = NULL;
00055   int res = 0;
00056   int still_running = 0;
00057 
00058   start_test_timing();
00059 
00060   global_init(CURL_GLOBAL_ALL);
00061 
00062   easy_init(handle);
00063 
00064   easy_setopt(handle, CURLOPT_URL, URL);
00065   easy_setopt(handle, CURLOPT_VERBOSE, 1L);
00066 
00067   multi_init(mhandle);
00068 
00069   multi_add_handle(mhandle, handle);
00070 
00071   multi_perform(mhandle, &still_running);
00072 
00073   abort_on_test_timeout();
00074 
00075   while(still_running) {
00076     struct timeval timeout;
00077     fd_set fdread;
00078     fd_set fdwrite;
00079     fd_set fdexcep;
00080     int maxfd = -99;
00081     struct timeval before;
00082     struct timeval after;
00083     int e;
00084 
00085     timeout.tv_sec = 0;
00086     timeout.tv_usec = 100000L; /* 100 ms */
00087 
00088     FD_ZERO(&fdread);
00089     FD_ZERO(&fdwrite);
00090     FD_ZERO(&fdexcep);
00091 
00092     multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
00093 
00094     /* At this point, maxfd is guaranteed to be greater or equal than -1. */
00095 
00096     select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00097 
00098     abort_on_test_timeout();
00099 
00100     fprintf(stderr, "ping\n");
00101     before = tutil_tvnow();
00102 
00103     multi_perform(mhandle, &still_running);
00104 
00105     abort_on_test_timeout();
00106 
00107     after = tutil_tvnow();
00108     e = elapsed(&before, &after);
00109     fprintf(stderr, "pong = %d\n", e);
00110 
00111     if(e > MAX_BLOCKED_TIME_US) {
00112       res = 100;
00113       break;
00114     }
00115   }
00116 
00117 test_cleanup:
00118 
00119   /* undocumented cleanup sequence - type UA */
00120 
00121   curl_multi_cleanup(mhandle);
00122   curl_easy_cleanup(handle);
00123   curl_global_cleanup();
00124 
00125   return res;
00126 }


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