1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
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 http://curl.haxx.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
28 #define TEST_HANG_TIMEOUT 60 * 1000
30 char const testData[] = ".abc\0xyz";
31 off_t const testDataSize = sizeof(testData) - 1;
37 int still_running; /* keep number of running handles */
38 CURLMsg *msg; /* for picking up messages with the transfer status */
39 int msgs_left; /* how many messages are left */
41 /* Allocate one CURL handle per transfer */
42 easy = curl_easy_init();
44 /* init a multi stack */
45 multi_handle = curl_multi_init();
47 /* add the individual transfer */
48 curl_multi_add_handle(multi_handle, easy);
50 /* set the options (I left out a few, you'll get the point anyway) */
51 curl_easy_setopt(easy, CURLOPT_URL, URL);
52 curl_easy_setopt(easy, CURLOPT_POSTFIELDSIZE_LARGE, testDataSize);
53 curl_easy_setopt(easy, CURLOPT_POSTFIELDS, testData);
55 /* we start some action by calling perform right away */
56 curl_multi_perform(multi_handle, &still_running);
59 struct timeval timeout;
60 int rc; /* select() return code */
61 CURLMcode mc; /* curl_multi_fdset() return code */
74 /* set a suitable timeout to play around with */
78 curl_multi_timeout(multi_handle, &curl_timeo);
80 timeout.tv_sec = curl_timeo / 1000;
81 if(timeout.tv_sec > 1)
84 timeout.tv_usec = (curl_timeo % 1000) * 1000;
87 /* get file descriptors from the transfers */
88 mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
92 fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
96 /* On success the value of maxfd is guaranteed to be >= -1. We call
97 select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
98 no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
99 to sleep 100ms, which is the minimum suggested value in the
100 curl_multi_fdset() doc. */
107 /* Portable sleep for platforms other than Windows. */
108 struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
109 rc = select(0, NULL, NULL, NULL, &wait);
113 /* Note that on some platforms 'timeout' may be modified by select().
114 If you need access to the original value save a copy beforehand. */
115 rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
122 case 0: /* timeout */
123 default: /* action */
124 curl_multi_perform(multi_handle, &still_running);
127 } while(still_running);
129 /* See how the transfers went */
130 while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
131 if (msg->msg == CURLMSG_DONE) {
132 printf("HTTP transfer completed with status %d\n", msg->data.result);
137 curl_multi_cleanup(multi_handle);
139 /* Free the CURL handles */
140 curl_easy_cleanup(easy);