lib1531.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 "testutil.h"
00025 #include "warnless.h"
00026 #include "memdebug.h"
00027 
00028 #define TEST_HANG_TIMEOUT 60 * 1000
00029 
00030 char const testData[] = ".abc\0xyz";
00031 off_t const testDataSize = sizeof(testData) - 1;
00032 
00033 int test(char *URL)
00034 {
00035   CURL *easy;
00036   CURLM *multi_handle;
00037   int still_running; /* keep number of running handles */
00038   CURLMsg *msg; /* for picking up messages with the transfer status */
00039   int msgs_left; /* how many messages are left */
00040 
00041   /* Allocate one CURL handle per transfer */
00042   easy = curl_easy_init();
00043 
00044   /* init a multi stack */
00045   multi_handle = curl_multi_init();
00046 
00047   /* add the individual transfer */
00048   curl_multi_add_handle(multi_handle, easy);
00049 
00050   /* set the options (I left out a few, you'll get the point anyway) */
00051   curl_easy_setopt(easy, CURLOPT_URL, URL);
00052   curl_easy_setopt(easy, CURLOPT_POSTFIELDSIZE_LARGE,
00053                    (curl_off_t)testDataSize);
00054   curl_easy_setopt(easy, CURLOPT_POSTFIELDS, testData);
00055 
00056   /* we start some action by calling perform right away */
00057   curl_multi_perform(multi_handle, &still_running);
00058 
00059   do {
00060     struct timeval timeout;
00061     int rc; /* select() return code */
00062     CURLMcode mc; /* curl_multi_fdset() return code */
00063 
00064     fd_set fdread;
00065     fd_set fdwrite;
00066     fd_set fdexcep;
00067     int maxfd = -1;
00068 
00069     long curl_timeo = -1;
00070 
00071     FD_ZERO(&fdread);
00072     FD_ZERO(&fdwrite);
00073     FD_ZERO(&fdexcep);
00074 
00075     /* set a suitable timeout to play around with */
00076     timeout.tv_sec = 1;
00077     timeout.tv_usec = 0;
00078 
00079     curl_multi_timeout(multi_handle, &curl_timeo);
00080     if(curl_timeo >= 0) {
00081       timeout.tv_sec = curl_timeo / 1000;
00082       if(timeout.tv_sec > 1)
00083         timeout.tv_sec = 1;
00084       else
00085         timeout.tv_usec = (curl_timeo % 1000) * 1000;
00086     }
00087 
00088     /* get file descriptors from the transfers */
00089     mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
00090 
00091     if(mc != CURLM_OK) {
00092       fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
00093       break;
00094     }
00095 
00096     /* On success the value of maxfd is guaranteed to be >= -1. We call
00097        select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
00098        no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
00099        to sleep 100ms, which is the minimum suggested value in the
00100        curl_multi_fdset() doc. */
00101 
00102     if(maxfd == -1) {
00103 #ifdef _WIN32
00104       Sleep(100);
00105       rc = 0;
00106 #else
00107       /* Portable sleep for platforms other than Windows. */
00108       struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
00109       rc = select(0, NULL, NULL, NULL, &wait);
00110 #endif
00111     }
00112     else {
00113       /* Note that on some platforms 'timeout' may be modified by select().
00114          If you need access to the original value save a copy beforehand. */
00115       rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00116     }
00117 
00118     switch(rc) {
00119     case -1:
00120       /* select error */
00121       break;
00122     case 0: /* timeout */
00123     default: /* action */
00124       curl_multi_perform(multi_handle, &still_running);
00125       break;
00126     }
00127   } while(still_running);
00128 
00129   /* See how the transfers went */
00130   while((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
00131     if(msg->msg == CURLMSG_DONE) {
00132       printf("HTTP transfer completed with status %d\n", msg->data.result);
00133       break;
00134     }
00135   }
00136 
00137   curl_multi_cleanup(multi_handle);
00138 
00139   /* Free the CURL handles */
00140   curl_easy_cleanup(easy);
00141 
00142   return 0;
00143 }
00144 


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