1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, 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 https://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 struct transfer_status {
31 int counter; /* count write callback invokes */
32 int please; /* number of times xferinfo is called while halted */
35 static int please_continue(void *userp,
41 struct transfer_status *st = (struct transfer_status *)userp;
49 /* waited enough, unpause! */
50 curl_easy_pause(st->easy, CURLPAUSE_CONT);
53 fprintf(stderr, "xferinfo: paused %d\n", st->halted);
57 static size_t header_callback(void *ptr, size_t size, size_t nmemb,
60 size_t len = size * nmemb;
62 (void)fwrite(ptr, size, nmemb, stdout);
66 static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp)
68 struct transfer_status *st = (struct transfer_status *)userp;
69 size_t len = size * nmemb;
72 /* the first call puts us on pause, so subsequent calls are after
74 fwrite(ptr, size, nmemb, stdout);
77 printf("Got %d bytes but pausing!\n", (int)len);
79 return CURL_WRITEFUNC_PAUSE;
82 #define TEST_HANG_TIMEOUT 60 * 1000
89 struct transfer_status st;
93 memset(&st, 0, sizeof(st));
95 global_init(CURL_GLOBAL_ALL);
98 st.easy = curls; /* to allow callbacks access */
100 easy_setopt(curls, CURLOPT_URL, URL);
101 easy_setopt(curls, CURLOPT_WRITEFUNCTION, write_callback);
102 easy_setopt(curls, CURLOPT_WRITEDATA, &st);
103 easy_setopt(curls, CURLOPT_HEADERFUNCTION, header_callback);
104 easy_setopt(curls, CURLOPT_HEADERDATA, &st);
106 easy_setopt(curls, CURLOPT_XFERINFOFUNCTION, please_continue);
107 easy_setopt(curls, CURLOPT_XFERINFODATA, &st);
108 easy_setopt(curls, CURLOPT_NOPROGRESS, 0L);
110 res = curl_easy_perform(curls);
114 curl_easy_cleanup(curls);
115 curl_global_cleanup();
120 return i; /* return the final return code */