mirror of
https://github.com/curl/curl.git
synced 2026-06-01 20:14:15 +03:00
tests/client: use curl_mfprintf()
Replacing `fprintf()`. `curl_mfprintf()` is a public libcurl API.
Following the same change made for libtests.
Follow-up to 255aac56f9 #17253
Closes #17651
This commit is contained in:
parent
a4a13c96ca
commit
af309fb17b
11 changed files with 186 additions and 181 deletions
|
|
@ -29,7 +29,7 @@ int main(int argc, char **argv)
|
|||
size_t tmp;
|
||||
|
||||
if(argc < 2) {
|
||||
fprintf(stderr, "Pass clientname as first argument\n");
|
||||
curl_mfprintf(stderr, "Pass clientname as first argument\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if(!entry_func) {
|
||||
fprintf(stderr, "Test '%s' not found.\n", entry_name);
|
||||
curl_mfprintf(stderr, "Test '%s' not found.\n", entry_name);
|
||||
return 99;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ struct entry_s {
|
|||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <stdio.h> /* for fprintf() */
|
||||
#include <stdlib.h> /* for calloc(), free(), strtol() */
|
||||
#include <string.h> /* for strchr(), strcmp() */
|
||||
|
||||
|
|
@ -47,10 +46,10 @@ struct entry_s {
|
|||
#include <cextdecs.h(PROCESS_DELAY_)> /* for usleep() logic */
|
||||
#endif
|
||||
|
||||
#define ERR() \
|
||||
do { \
|
||||
fprintf(stderr, "something unexpected went wrong - bailing out!\n"); \
|
||||
return 2; \
|
||||
#define ERR() \
|
||||
do { \
|
||||
curl_mfprintf(stderr, "something unexpected went wrong - bailing out!\n");\
|
||||
return 2; \
|
||||
} while(0)
|
||||
|
||||
static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
|
||||
|
|
@ -63,7 +62,7 @@ static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
|
|||
"* ", "< ", "> ", "{ ", "} ", "{ ", "} "
|
||||
};
|
||||
if(idsbuf && *idsbuf)
|
||||
fprintf(log, "%s%s", idsbuf, s_infotype[type]);
|
||||
curl_mfprintf(log, "%s%s", idsbuf, s_infotype[type]);
|
||||
else
|
||||
fputs(s_infotype[type], log);
|
||||
}
|
||||
|
|
@ -136,7 +135,7 @@ static int debug_cb(CURL *handle, curl_infotype type,
|
|||
if(!traced_data) {
|
||||
if(!newl)
|
||||
log_line_start(output, idsbuf, type);
|
||||
fprintf(output, "[%ld bytes data]\n", (long)size);
|
||||
curl_mfprintf(output, "[%ld bytes data]\n", (long)size);
|
||||
newl = 0;
|
||||
traced_data = 1;
|
||||
}
|
||||
|
|
@ -161,18 +160,18 @@ static void dump(const char *text, unsigned char *ptr, size_t size, char nohex)
|
|||
/* without the hex output, we can fit more on screen */
|
||||
width = 0x40;
|
||||
|
||||
fprintf(stderr, "%s, %lu bytes (0x%lx)\n",
|
||||
text, (unsigned long)size, (unsigned long)size);
|
||||
curl_mfprintf(stderr, "%s, %lu bytes (0x%lx)\n",
|
||||
text, (unsigned long)size, (unsigned long)size);
|
||||
|
||||
for(i = 0; i < size; i += width) {
|
||||
|
||||
fprintf(stderr, "%4.4lx: ", (unsigned long)i);
|
||||
curl_mfprintf(stderr, "%4.4lx: ", (unsigned long)i);
|
||||
|
||||
if(!nohex) {
|
||||
/* hex not disabled, show it */
|
||||
for(c = 0; c < width; c++)
|
||||
if(i + c < size)
|
||||
fprintf(stderr, "%02x ", ptr[i + c]);
|
||||
curl_mfprintf(stderr, "%02x ", ptr[i + c]);
|
||||
else
|
||||
fputs(" ", stderr);
|
||||
}
|
||||
|
|
@ -184,8 +183,8 @@ static void dump(const char *text, unsigned char *ptr, size_t size, char nohex)
|
|||
i += (c + 2 - width);
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "%c",
|
||||
(ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80) ? ptr[i + c] : '.');
|
||||
curl_mfprintf(stderr, "%c",
|
||||
(ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80) ? ptr[i + c] : '.');
|
||||
/* check again for 0D0A, to avoid an extra \n if it's at width */
|
||||
if(nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D &&
|
||||
ptr[i + c + 2] == 0x0A) {
|
||||
|
|
@ -204,8 +203,8 @@ static void websocket_close(CURL *curl)
|
|||
size_t sent;
|
||||
CURLcode result =
|
||||
curl_ws_send(curl, "", 0, &sent, 0, CURLWS_CLOSE);
|
||||
fprintf(stderr,
|
||||
"ws: curl_ws_send returned %u, sent %u\n", (int)result, (int)sent);
|
||||
curl_mfprintf(stderr, "ws: curl_ws_send returned %u, sent %u\n",
|
||||
(int)result, (int)sent);
|
||||
}
|
||||
#endif /* CURL_DISABLE_WEBSOCKETS */
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
static void usage_h2_pausing(const char *msg)
|
||||
{
|
||||
if(msg)
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fprintf(stderr,
|
||||
curl_mfprintf(stderr, "%s\n", msg);
|
||||
curl_mfprintf(stderr,
|
||||
"usage: [options] url\n"
|
||||
" pause downloads with following options:\n"
|
||||
" -V http_version (http/1.1, h2, h3) http version to use\n"
|
||||
|
|
@ -61,19 +61,19 @@ static size_t cb(char *data, size_t size, size_t nmemb, void *clientp)
|
|||
|
||||
if(!handle->resumed) {
|
||||
++handle->paused;
|
||||
fprintf(stderr, "INFO: [%d] write, PAUSING %d time on %lu bytes\n",
|
||||
(int)handle->idx, handle->paused, (long)realsize);
|
||||
curl_mfprintf(stderr, "INFO: [%d] write, PAUSING %d time on %lu bytes\n",
|
||||
(int)handle->idx, handle->paused, (long)realsize);
|
||||
assert(handle->paused == 1);
|
||||
return CURL_WRITEFUNC_PAUSE;
|
||||
}
|
||||
if(handle->fail_write) {
|
||||
++handle->errored;
|
||||
fprintf(stderr, "INFO: [%d] FAIL write of %lu bytes, %d time\n",
|
||||
(int)handle->idx, (long)realsize, handle->errored);
|
||||
curl_mfprintf(stderr, "INFO: [%d] FAIL write of %lu bytes, %d time\n",
|
||||
(int)handle->idx, (long)realsize, handle->errored);
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
}
|
||||
fprintf(stderr, "INFO: [%d] write, accepting %lu bytes\n",
|
||||
(int)handle->idx, (long)realsize);
|
||||
curl_mfprintf(stderr, "INFO: [%d] write, accepting %lu bytes\n",
|
||||
(int)handle->idx, (long)realsize);
|
||||
return realsize;
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ static int test_h2_pausing(int argc, char *argv[])
|
|||
argv += coptind;
|
||||
|
||||
if(argc != 1) {
|
||||
fprintf(stderr, "ERROR: need URL as argument\n");
|
||||
curl_mfprintf(stderr, "ERROR: need URL as argument\n");
|
||||
return 2;
|
||||
}
|
||||
url = argv[0];
|
||||
|
|
@ -132,19 +132,19 @@ static int test_h2_pausing(int argc, char *argv[])
|
|||
|
||||
cu = curl_url();
|
||||
if(!cu) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
curl_mfprintf(stderr, "out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
if(curl_url_set(cu, CURLUPART_URL, url, 0)) {
|
||||
fprintf(stderr, "not a URL: '%s'\n", url);
|
||||
curl_mfprintf(stderr, "not a URL: '%s'\n", url);
|
||||
return 1;
|
||||
}
|
||||
if(curl_url_get(cu, CURLUPART_HOST, &host, 0)) {
|
||||
fprintf(stderr, "could not get host of '%s'\n", url);
|
||||
curl_mfprintf(stderr, "could not get host of '%s'\n", url);
|
||||
return 1;
|
||||
}
|
||||
if(curl_url_get(cu, CURLUPART_PORT, &port, 0)) {
|
||||
fprintf(stderr, "could not get port of '%s'\n", url);
|
||||
curl_mfprintf(stderr, "could not get port of '%s'\n", url);
|
||||
return 1;
|
||||
}
|
||||
memset(&resolve, 0, sizeof(resolve));
|
||||
|
|
@ -186,36 +186,36 @@ static int test_h2_pausing(int argc, char *argv[])
|
|||
}
|
||||
|
||||
for(rounds = 0;; rounds++) {
|
||||
fprintf(stderr, "INFO: multi_perform round %d\n", rounds);
|
||||
curl_mfprintf(stderr, "INFO: multi_perform round %d\n", rounds);
|
||||
if(curl_multi_perform(multi_handle, &still_running) != CURLM_OK)
|
||||
ERR();
|
||||
|
||||
if(!still_running) {
|
||||
int as_expected = 1;
|
||||
fprintf(stderr, "INFO: no more handles running\n");
|
||||
curl_mfprintf(stderr, "INFO: no more handles running\n");
|
||||
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
|
||||
if(!handles[i].paused) {
|
||||
fprintf(stderr, "ERROR: [%d] NOT PAUSED\n", (int)i);
|
||||
curl_mfprintf(stderr, "ERROR: [%d] NOT PAUSED\n", (int)i);
|
||||
as_expected = 0;
|
||||
}
|
||||
else if(handles[i].paused != 1) {
|
||||
fprintf(stderr, "ERROR: [%d] PAUSED %d times!\n",
|
||||
(int)i, handles[i].paused);
|
||||
curl_mfprintf(stderr, "ERROR: [%d] PAUSED %d times!\n",
|
||||
(int)i, handles[i].paused);
|
||||
as_expected = 0;
|
||||
}
|
||||
else if(!handles[i].resumed) {
|
||||
fprintf(stderr, "ERROR: [%d] NOT resumed!\n", (int)i);
|
||||
curl_mfprintf(stderr, "ERROR: [%d] NOT resumed!\n", (int)i);
|
||||
as_expected = 0;
|
||||
}
|
||||
else if(handles[i].errored != 1) {
|
||||
fprintf(stderr, "ERROR: [%d] NOT errored once, %d instead!\n",
|
||||
(int)i, handles[i].errored);
|
||||
curl_mfprintf(stderr, "ERROR: [%d] NOT errored once, %d instead!\n",
|
||||
(int)i, handles[i].errored);
|
||||
as_expected = 0;
|
||||
}
|
||||
}
|
||||
if(!as_expected) {
|
||||
fprintf(stderr, "ERROR: handles not in expected state "
|
||||
"after %d rounds\n", rounds);
|
||||
curl_mfprintf(stderr, "ERROR: handles not in expected state "
|
||||
"after %d rounds\n", rounds);
|
||||
rc = 1;
|
||||
}
|
||||
break;
|
||||
|
|
@ -230,9 +230,9 @@ static int test_h2_pausing(int argc, char *argv[])
|
|||
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
|
||||
if(msg->easy_handle == handles[i].h) {
|
||||
if(handles[i].paused != 1 || !handles[i].resumed) {
|
||||
fprintf(stderr, "ERROR: [%d] done, pauses=%d, resumed=%d, "
|
||||
"result %d - wtf?\n", (int)i, handles[i].paused,
|
||||
handles[i].resumed, msg->data.result);
|
||||
curl_mfprintf(stderr, "ERROR: [%d] done, pauses=%d, resumed=%d, "
|
||||
"result %d - wtf?\n", (int)i, handles[i].paused,
|
||||
handles[i].resumed, msg->data.result);
|
||||
rc = 1;
|
||||
goto out;
|
||||
}
|
||||
|
|
@ -250,7 +250,7 @@ static int test_h2_pausing(int argc, char *argv[])
|
|||
}
|
||||
all_paused = (i == CURL_ARRAYSIZE(handles));
|
||||
if(all_paused) {
|
||||
fprintf(stderr, "INFO: all transfers paused\n");
|
||||
curl_mfprintf(stderr, "INFO: all transfers paused\n");
|
||||
/* give transfer some rounds to mess things up */
|
||||
resume_round = rounds + 2;
|
||||
}
|
||||
|
|
@ -258,7 +258,7 @@ static int test_h2_pausing(int argc, char *argv[])
|
|||
if(resume_round > 0 && rounds == resume_round) {
|
||||
/* time to resume */
|
||||
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
|
||||
fprintf(stderr, "INFO: [%d] resumed\n", (int)i);
|
||||
curl_mfprintf(stderr, "INFO: [%d] resumed\n", (int)i);
|
||||
handles[i].resumed = 1;
|
||||
curl_easy_pause(handles[i].h, CURLPAUSE_CONT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ static int my_trace(CURL *handle, curl_infotype type,
|
|||
(void)userp;
|
||||
switch(type) {
|
||||
case CURLINFO_TEXT:
|
||||
fprintf(stderr, "== Info: %s", data);
|
||||
curl_mfprintf(stderr, "== Info: %s", data);
|
||||
return 0;
|
||||
case CURLINFO_HEADER_OUT:
|
||||
text = "=> Send header";
|
||||
|
|
@ -104,7 +104,7 @@ static int server_push_callback(CURL *parent,
|
|||
out = fopen(filename, "wb");
|
||||
if(!out) {
|
||||
/* if we cannot save it, deny it */
|
||||
fprintf(stderr, "Failed to create output file for push\n");
|
||||
curl_mfprintf(stderr, "Failed to create output file for push\n");
|
||||
rv = CURL_PUSH_DENY;
|
||||
goto out;
|
||||
}
|
||||
|
|
@ -112,17 +112,18 @@ static int server_push_callback(CURL *parent,
|
|||
/* write to this file */
|
||||
curl_easy_setopt(easy, CURLOPT_WRITEDATA, out);
|
||||
|
||||
fprintf(stderr, "**** push callback approves stream %u, got %lu headers!\n",
|
||||
count, (unsigned long)num_headers);
|
||||
curl_mfprintf(stderr, "**** push callback approves stream %u, "
|
||||
"got %lu headers!\n", count, (unsigned long)num_headers);
|
||||
|
||||
for(i = 0; i < num_headers; i++) {
|
||||
headp = curl_pushheader_bynum(headers, i);
|
||||
fprintf(stderr, "**** header %lu: %s\n", (unsigned long)i, headp);
|
||||
curl_mfprintf(stderr, "**** header %lu: %s\n", (unsigned long)i, headp);
|
||||
}
|
||||
|
||||
headp = curl_pushheader_byname(headers, ":path");
|
||||
if(headp) {
|
||||
fprintf(stderr, "**** The PATH is %s\n", headp /* skip :path + colon */);
|
||||
curl_mfprintf(stderr, "**** The PATH is %s\n",
|
||||
headp /* skip :path + colon */);
|
||||
}
|
||||
|
||||
(*transfers)++; /* one more */
|
||||
|
|
@ -144,7 +145,7 @@ static int test_h2_serverpush(int argc, char *argv[])
|
|||
const char *url;
|
||||
|
||||
if(argc != 2) {
|
||||
fprintf(stderr, "need URL as argument\n");
|
||||
curl_mfprintf(stderr, "need URL as argument\n");
|
||||
return 2;
|
||||
}
|
||||
url = argv[1];
|
||||
|
|
@ -156,7 +157,7 @@ static int test_h2_serverpush(int argc, char *argv[])
|
|||
|
||||
easy = curl_easy_init();
|
||||
if(setup_h2_serverpush(easy, url)) {
|
||||
fprintf(stderr, "failed\n");
|
||||
curl_mfprintf(stderr, "failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,14 +42,14 @@ static int test_h2_upgrade_extreme(int argc, char *argv[])
|
|||
int exitcode = 1;
|
||||
|
||||
if(argc != 2) {
|
||||
fprintf(stderr, "%s URL\n", argv[0]);
|
||||
curl_mfprintf(stderr, "%s URL\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
url = argv[1];
|
||||
multi = curl_multi_init();
|
||||
if(!multi) {
|
||||
fprintf(stderr, "curl_multi_init failed\n");
|
||||
curl_mfprintf(stderr, "curl_multi_init failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ static int test_h2_upgrade_extreme(int argc, char *argv[])
|
|||
if(start_count) {
|
||||
easy = curl_easy_init();
|
||||
if(!easy) {
|
||||
fprintf(stderr, "curl_easy_init failed\n");
|
||||
curl_mfprintf(stderr, "curl_easy_init failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
|
||||
|
|
@ -80,8 +80,8 @@ static int test_h2_upgrade_extreme(int argc, char *argv[])
|
|||
|
||||
mc = curl_multi_add_handle(multi, easy);
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi_add_handle: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
curl_mfprintf(stderr, "curl_multi_add_handle: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
curl_easy_cleanup(easy);
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
@ -90,16 +90,16 @@ static int test_h2_upgrade_extreme(int argc, char *argv[])
|
|||
|
||||
mc = curl_multi_perform(multi, &running_handles);
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi_perform: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
curl_mfprintf(stderr, "curl_multi_perform: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(running_handles) {
|
||||
mc = curl_multi_poll(multi, NULL, 0, 1000000, &numfds);
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi_poll: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
curl_mfprintf(stderr, "curl_multi_poll: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
|
@ -135,12 +135,12 @@ static int test_h2_upgrade_extreme(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "running_handles=%d, yet_to_start=%d\n",
|
||||
running_handles, start_count);
|
||||
curl_mfprintf(stderr, "running_handles=%d, yet_to_start=%d\n",
|
||||
running_handles, start_count);
|
||||
|
||||
} while(running_handles > 0 || start_count);
|
||||
|
||||
fprintf(stderr, "exiting\n");
|
||||
curl_mfprintf(stderr, "exiting\n");
|
||||
exitcode = 0;
|
||||
|
||||
cleanup:
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ static size_t my_write_d_cb(char *buf, size_t nitems, size_t buflen,
|
|||
size_t blen = (nitems * buflen);
|
||||
size_t nwritten;
|
||||
|
||||
fprintf(stderr, "[t-%d] RECV %ld bytes, total=%ld, pause_at=%ld\n",
|
||||
t->idx, (long)blen, (long)t->recv_size, (long)t->pause_at);
|
||||
curl_mfprintf(stderr, "[t-%d] RECV %ld bytes, total=%ld, pause_at=%ld\n",
|
||||
t->idx, (long)blen, (long)t->recv_size, (long)t->pause_at);
|
||||
if(!t->out) {
|
||||
curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%u.data",
|
||||
t->idx);
|
||||
|
|
@ -74,20 +74,20 @@ static size_t my_write_d_cb(char *buf, size_t nitems, size_t buflen,
|
|||
if(!t->resumed &&
|
||||
t->recv_size < t->pause_at &&
|
||||
((t->recv_size + (curl_off_t)blen) >= t->pause_at)) {
|
||||
fprintf(stderr, "[t-%d] PAUSE\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] PAUSE\n", t->idx);
|
||||
t->paused = 1;
|
||||
return CURL_WRITEFUNC_PAUSE;
|
||||
}
|
||||
|
||||
nwritten = fwrite(buf, nitems, buflen, t->out);
|
||||
if(nwritten < blen) {
|
||||
fprintf(stderr, "[t-%d] write failure\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] write failure\n", t->idx);
|
||||
return 0;
|
||||
}
|
||||
t->recv_size += (curl_off_t)nwritten;
|
||||
if(t->fail_at > 0 && t->recv_size >= t->fail_at) {
|
||||
fprintf(stderr, "[t-%d] FAIL by write callback at %ld bytes\n",
|
||||
t->idx, (long)t->recv_size);
|
||||
curl_mfprintf(stderr, "[t-%d] FAIL by write callback at %ld bytes\n",
|
||||
t->idx, (long)t->recv_size);
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
}
|
||||
|
||||
|
|
@ -103,8 +103,8 @@ static int my_progress_d_cb(void *userdata,
|
|||
(void)ulnow;
|
||||
(void)dltotal;
|
||||
if(t->abort_at > 0 && dlnow >= t->abort_at) {
|
||||
fprintf(stderr, "[t-%d] ABORT by progress_cb at %ld bytes\n",
|
||||
t->idx, (long)dlnow);
|
||||
curl_mfprintf(stderr, "[t-%d] ABORT by progress_cb at %ld bytes\n",
|
||||
t->idx, (long)dlnow);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -151,8 +151,8 @@ static int setup_hx_download(CURL *hnd, const char *url, struct transfer_d *t,
|
|||
static void usage_hx_download(const char *msg)
|
||||
{
|
||||
if(msg)
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fprintf(stderr,
|
||||
curl_mfprintf(stderr, "%s\n", msg);
|
||||
curl_mfprintf(stderr,
|
||||
"usage: [options] url\n"
|
||||
" download a url with following options:\n"
|
||||
" -a abort paused transfer\n"
|
||||
|
|
@ -160,7 +160,7 @@ static void usage_hx_download(const char *msg)
|
|||
" -e use TLS early data when possible\n"
|
||||
" -f forbid connection reuse\n"
|
||||
" -n number total downloads\n");
|
||||
fprintf(stderr,
|
||||
curl_mfprintf(stderr,
|
||||
" -A number abort transfer after `number` response bytes\n"
|
||||
" -F number fail writing response after `number` response bytes\n"
|
||||
" -M number max concurrent connections to a host\n"
|
||||
|
|
@ -277,7 +277,7 @@ static int test_hx_download(int argc, char *argv[])
|
|||
|
||||
share = curl_share_init();
|
||||
if(!share) {
|
||||
fprintf(stderr, "error allocating share\n");
|
||||
curl_mfprintf(stderr, "error allocating share\n");
|
||||
result = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
@ -290,7 +290,7 @@ static int test_hx_download(int argc, char *argv[])
|
|||
|
||||
transfer_d = calloc(transfer_count_d, sizeof(*transfer_d));
|
||||
if(!transfer_d) {
|
||||
fprintf(stderr, "error allocating transfer structs\n");
|
||||
curl_mfprintf(stderr, "error allocating transfer structs\n");
|
||||
result = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
@ -318,14 +318,14 @@ static int test_hx_download(int argc, char *argv[])
|
|||
if(!t->easy ||
|
||||
setup_hx_download(t->easy, url, t, http_version, host, share,
|
||||
use_earlydata, fresh_connect)) {
|
||||
fprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
curl_mfprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
result = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
curl_multi_add_handle(multi_handle, t->easy);
|
||||
t->started = 1;
|
||||
++active_transfers;
|
||||
fprintf(stderr, "[t-%d] STARTED\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] STARTED\n", t->idx);
|
||||
}
|
||||
|
||||
do {
|
||||
|
|
@ -351,17 +351,18 @@ static int test_hx_download(int argc, char *argv[])
|
|||
if(t) {
|
||||
t->done = 1;
|
||||
t->result = m->data.result;
|
||||
fprintf(stderr, "[t-%d] FINISHED with result %d\n",
|
||||
t->idx, t->result);
|
||||
curl_mfprintf(stderr, "[t-%d] FINISHED with result %d\n",
|
||||
t->idx, t->result);
|
||||
if(use_earlydata) {
|
||||
curl_off_t sent;
|
||||
curl_easy_getinfo(e, CURLINFO_EARLYDATA_SENT_T, &sent);
|
||||
fprintf(stderr, "[t-%d] EarlyData: %ld\n", t->idx, (long)sent);
|
||||
curl_mfprintf(stderr, "[t-%d] EarlyData: %ld\n", t->idx,
|
||||
(long)sent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
curl_easy_cleanup(e);
|
||||
fprintf(stderr, "unknown FINISHED???\n");
|
||||
curl_mfprintf(stderr, "unknown FINISHED???\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -374,7 +375,7 @@ static int test_hx_download(int argc, char *argv[])
|
|||
curl_multi_remove_handle(multi_handle, t->easy);
|
||||
t->done = 1;
|
||||
active_transfers--;
|
||||
fprintf(stderr, "[t-%d] ABORTED\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] ABORTED\n", t->idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -386,7 +387,7 @@ static int test_hx_download(int argc, char *argv[])
|
|||
t->resumed = 1;
|
||||
t->paused = 0;
|
||||
curl_easy_pause(t->easy, CURLPAUSE_CONT);
|
||||
fprintf(stderr, "[t-%d] RESUMED\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] RESUMED\n", t->idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -400,14 +401,14 @@ static int test_hx_download(int argc, char *argv[])
|
|||
if(!t->easy ||
|
||||
setup_hx_download(t->easy, url, t, http_version, host, share,
|
||||
use_earlydata, fresh_connect)) {
|
||||
fprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
curl_mfprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
result = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
curl_multi_add_handle(multi_handle, t->easy);
|
||||
t->started = 1;
|
||||
++active_transfers;
|
||||
fprintf(stderr, "[t-%d] STARTED\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] STARTED\n", t->idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ static size_t my_write_u_cb(char *buf, size_t nitems, size_t buflen,
|
|||
size_t blen = (nitems * buflen);
|
||||
size_t nwritten;
|
||||
|
||||
fprintf(stderr, "[t-%d] RECV %ld bytes, total=%ld, pause_at=%ld\n",
|
||||
t->idx, (long)blen, (long)t->recv_size, (long)t->pause_at);
|
||||
curl_mfprintf(stderr, "[t-%d] RECV %ld bytes, total=%ld, pause_at=%ld\n",
|
||||
t->idx, (long)blen, (long)t->recv_size, (long)t->pause_at);
|
||||
if(!t->out) {
|
||||
curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%u.data",
|
||||
t->idx);
|
||||
|
|
@ -75,7 +75,7 @@ static size_t my_write_u_cb(char *buf, size_t nitems, size_t buflen,
|
|||
|
||||
nwritten = fwrite(buf, nitems, buflen, t->out);
|
||||
if(nwritten < blen) {
|
||||
fprintf(stderr, "[t-%d] write failure\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] write failure\n", t->idx);
|
||||
return 0;
|
||||
}
|
||||
t->recv_size += (curl_off_t)nwritten;
|
||||
|
|
@ -96,13 +96,13 @@ static size_t my_read_cb(char *buf, size_t nitems, size_t buflen,
|
|||
else
|
||||
nread = blen;
|
||||
|
||||
fprintf(stderr, "[t-%d] SEND %ld bytes, total=%ld, pause_at=%ld\n",
|
||||
t->idx, (long)nread, (long)t->send_total, (long)t->pause_at);
|
||||
curl_mfprintf(stderr, "[t-%d] SEND %ld bytes, total=%ld, pause_at=%ld\n",
|
||||
t->idx, (long)nread, (long)t->send_total, (long)t->pause_at);
|
||||
|
||||
if(!t->resumed &&
|
||||
t->send_size < t->pause_at &&
|
||||
((t->send_size + (curl_off_t)blen) >= t->pause_at)) {
|
||||
fprintf(stderr, "[t-%d] PAUSE\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] PAUSE\n", t->idx);
|
||||
t->paused = 1;
|
||||
return CURL_READFUNC_PAUSE;
|
||||
}
|
||||
|
|
@ -110,8 +110,8 @@ static size_t my_read_cb(char *buf, size_t nitems, size_t buflen,
|
|||
memset(buf, 'x', nread);
|
||||
t->send_size += (curl_off_t)nread;
|
||||
if(t->fail_at > 0 && t->send_size >= t->fail_at) {
|
||||
fprintf(stderr, "[t-%d] ABORT by read callback at %ld bytes\n",
|
||||
t->idx, (long)t->send_size);
|
||||
curl_mfprintf(stderr, "[t-%d] ABORT by read callback at %ld bytes\n",
|
||||
t->idx, (long)t->send_size);
|
||||
return CURL_READFUNC_ABORT;
|
||||
}
|
||||
return (size_t)nread;
|
||||
|
|
@ -126,8 +126,8 @@ static int my_progress_u_cb(void *userdata,
|
|||
(void)dlnow;
|
||||
(void)dltotal;
|
||||
if(t->abort_at > 0 && ulnow >= t->abort_at) {
|
||||
fprintf(stderr, "[t-%d] ABORT by progress_cb at %ld bytes sent\n",
|
||||
t->idx, (long)ulnow);
|
||||
curl_mfprintf(stderr, "[t-%d] ABORT by progress_cb at %ld bytes sent\n",
|
||||
t->idx, (long)ulnow);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -155,7 +155,7 @@ static int setup_hx_upload(CURL *hnd, const char *url, struct transfer_u *t,
|
|||
else if(!strcmp("POST", t->method))
|
||||
curl_easy_setopt(hnd, CURLOPT_POST, 1L);
|
||||
else {
|
||||
fprintf(stderr, "unsupported method '%s'\n", t->method);
|
||||
curl_mfprintf(stderr, "unsupported method '%s'\n", t->method);
|
||||
return 1;
|
||||
}
|
||||
curl_easy_setopt(hnd, CURLOPT_READFUNCTION, my_read_cb);
|
||||
|
|
@ -186,8 +186,8 @@ static int setup_hx_upload(CURL *hnd, const char *url, struct transfer_u *t,
|
|||
static void usage_hx_upload(const char *msg)
|
||||
{
|
||||
if(msg)
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fprintf(stderr,
|
||||
curl_mfprintf(stderr, "%s\n", msg);
|
||||
curl_mfprintf(stderr,
|
||||
"usage: [options] url\n"
|
||||
" upload to a url with following options:\n"
|
||||
" -a abort paused transfer\n"
|
||||
|
|
@ -312,7 +312,7 @@ static int test_hx_upload(int argc, char *argv[])
|
|||
|
||||
share = curl_share_init();
|
||||
if(!share) {
|
||||
fprintf(stderr, "error allocating share\n");
|
||||
curl_mfprintf(stderr, "error allocating share\n");
|
||||
return 1;
|
||||
}
|
||||
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
|
||||
|
|
@ -324,7 +324,7 @@ static int test_hx_upload(int argc, char *argv[])
|
|||
|
||||
transfer_u = calloc(transfer_count_u, sizeof(*transfer_u));
|
||||
if(!transfer_u) {
|
||||
fprintf(stderr, "error allocating transfer structs\n");
|
||||
curl_mfprintf(stderr, "error allocating transfer structs\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -343,7 +343,7 @@ static int test_hx_upload(int argc, char *argv[])
|
|||
CURL *easy = curl_easy_init();
|
||||
CURLcode rc = CURLE_OK;
|
||||
if(!easy) {
|
||||
fprintf(stderr, "failed to init easy handle\n");
|
||||
curl_mfprintf(stderr, "failed to init easy handle\n");
|
||||
return 1;
|
||||
}
|
||||
for(i = 0; i < transfer_count_u; ++i) {
|
||||
|
|
@ -351,13 +351,13 @@ static int test_hx_upload(int argc, char *argv[])
|
|||
t->easy = easy;
|
||||
if(setup_hx_upload(t->easy, url, t, http_version, host, share,
|
||||
use_earlydata, announce_length)) {
|
||||
fprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
curl_mfprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "[t-%d] STARTING\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] STARTING\n", t->idx);
|
||||
rc = curl_easy_perform(easy);
|
||||
fprintf(stderr, "[t-%d] DONE -> %d\n", t->idx, rc);
|
||||
curl_mfprintf(stderr, "[t-%d] DONE -> %d\n", t->idx, rc);
|
||||
t->easy = NULL;
|
||||
curl_easy_reset(easy);
|
||||
}
|
||||
|
|
@ -373,13 +373,13 @@ static int test_hx_upload(int argc, char *argv[])
|
|||
t->easy = curl_easy_init();
|
||||
if(!t->easy || setup_hx_upload(t->easy, url, t, http_version, host,
|
||||
share, use_earlydata, announce_length)) {
|
||||
fprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
curl_mfprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
return 1;
|
||||
}
|
||||
curl_multi_add_handle(multi_handle, t->easy);
|
||||
t->started = 1;
|
||||
++active_transfers;
|
||||
fprintf(stderr, "[t-%d] STARTED\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] STARTED\n", t->idx);
|
||||
}
|
||||
|
||||
do {
|
||||
|
|
@ -407,17 +407,18 @@ static int test_hx_upload(int argc, char *argv[])
|
|||
long res_status;
|
||||
curl_easy_getinfo(e, CURLINFO_RESPONSE_CODE, &res_status);
|
||||
t->done = 1;
|
||||
fprintf(stderr, "[t-%d] FINISHED, result=%d, response=%ld\n",
|
||||
t->idx, m->data.result, res_status);
|
||||
curl_mfprintf(stderr, "[t-%d] FINISHED, result=%d, response=%ld\n",
|
||||
t->idx, m->data.result, res_status);
|
||||
if(use_earlydata) {
|
||||
curl_off_t sent;
|
||||
curl_easy_getinfo(e, CURLINFO_EARLYDATA_SENT_T, &sent);
|
||||
fprintf(stderr, "[t-%d] EarlyData: %ld\n", t->idx, (long)sent);
|
||||
curl_mfprintf(stderr, "[t-%d] EarlyData: %ld\n", t->idx,
|
||||
(long)sent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
curl_easy_cleanup(e);
|
||||
fprintf(stderr, "unknown FINISHED???\n");
|
||||
curl_mfprintf(stderr, "unknown FINISHED???\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -431,7 +432,7 @@ static int test_hx_upload(int argc, char *argv[])
|
|||
curl_multi_remove_handle(multi_handle, t->easy);
|
||||
t->done = 1;
|
||||
active_transfers--;
|
||||
fprintf(stderr, "[t-%d] ABORTED\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] ABORTED\n", t->idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -443,7 +444,7 @@ static int test_hx_upload(int argc, char *argv[])
|
|||
t->resumed = 1;
|
||||
t->paused = 0;
|
||||
curl_easy_pause(t->easy, CURLPAUSE_CONT);
|
||||
fprintf(stderr, "[t-%d] RESUMED\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] RESUMED\n", t->idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -457,13 +458,13 @@ static int test_hx_upload(int argc, char *argv[])
|
|||
if(!t->easy || setup_hx_upload(t->easy, url, t, http_version,
|
||||
host, share, use_earlydata,
|
||||
announce_length)) {
|
||||
fprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
curl_mfprintf(stderr, "[t-%d] FAILED setup\n", (int)i);
|
||||
return 1;
|
||||
}
|
||||
curl_multi_add_handle(multi_handle, t->easy);
|
||||
t->started = 1;
|
||||
++active_transfers;
|
||||
fprintf(stderr, "[t-%d] STARTED\n", t->idx);
|
||||
curl_mfprintf(stderr, "[t-%d] STARTED\n", t->idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ static int add_transfer(CURLM *multi, CURLSH *share,
|
|||
|
||||
easy = curl_easy_init();
|
||||
if(!easy) {
|
||||
fprintf(stderr, "curl_easy_init failed\n");
|
||||
curl_mfprintf(stderr, "curl_easy_init failed\n");
|
||||
return 1;
|
||||
}
|
||||
curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
|
||||
|
|
@ -59,8 +59,8 @@ static int add_transfer(CURLM *multi, CURLSH *share,
|
|||
|
||||
mc = curl_multi_add_handle(multi, easy);
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi_add_handle: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
curl_mfprintf(stderr, "curl_multi_add_handle: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
curl_easy_cleanup(easy);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ static int test_tls_session_reuse(int argc, char *argv[])
|
|||
int exitcode = 1;
|
||||
|
||||
if(argc != 3) {
|
||||
fprintf(stderr, "%s proto URL\n", argv[0]);
|
||||
curl_mfprintf(stderr, "%s proto URL\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
|
@ -97,19 +97,19 @@ static int test_tls_session_reuse(int argc, char *argv[])
|
|||
url = argv[2];
|
||||
cu = curl_url();
|
||||
if(!cu) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
curl_mfprintf(stderr, "out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
if(curl_url_set(cu, CURLUPART_URL, url, 0)) {
|
||||
fprintf(stderr, "not a URL: '%s'\n", url);
|
||||
curl_mfprintf(stderr, "not a URL: '%s'\n", url);
|
||||
goto cleanup;
|
||||
}
|
||||
if(curl_url_get(cu, CURLUPART_HOST, &host, 0)) {
|
||||
fprintf(stderr, "could not get host of '%s'\n", url);
|
||||
curl_mfprintf(stderr, "could not get host of '%s'\n", url);
|
||||
goto cleanup;
|
||||
}
|
||||
if(curl_url_get(cu, CURLUPART_PORT, &port, 0)) {
|
||||
fprintf(stderr, "could not get port of '%s'\n", url);
|
||||
curl_mfprintf(stderr, "could not get port of '%s'\n", url);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
|
@ -119,13 +119,13 @@ static int test_tls_session_reuse(int argc, char *argv[])
|
|||
|
||||
multi = curl_multi_init();
|
||||
if(!multi) {
|
||||
fprintf(stderr, "curl_multi_init failed\n");
|
||||
curl_mfprintf(stderr, "curl_multi_init failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
share = curl_share_init();
|
||||
if(!share) {
|
||||
fprintf(stderr, "curl_share_init failed\n");
|
||||
curl_mfprintf(stderr, "curl_share_init failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
|
||||
|
|
@ -139,16 +139,16 @@ static int test_tls_session_reuse(int argc, char *argv[])
|
|||
do {
|
||||
mc = curl_multi_perform(multi, &running_handles);
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi_perform: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
curl_mfprintf(stderr, "curl_multi_perform: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(running_handles) {
|
||||
mc = curl_multi_poll(multi, NULL, 0, 1000000, &numfds);
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi_poll: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
curl_mfprintf(stderr, "curl_multi_poll: %s\n",
|
||||
curl_multi_strerror(mc));
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
|
@ -197,12 +197,12 @@ static int test_tls_session_reuse(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "running_handles=%d, yet_to_start=%d\n",
|
||||
running_handles, add_more);
|
||||
curl_mfprintf(stderr, "running_handles=%d, yet_to_start=%d\n",
|
||||
running_handles, add_more);
|
||||
|
||||
} while(ongoing || add_more);
|
||||
|
||||
fprintf(stderr, "exiting\n");
|
||||
curl_mfprintf(stderr, "exiting\n");
|
||||
exitcode = 0;
|
||||
|
||||
cleanup:
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb,
|
|||
(void)nmemb;
|
||||
(void)userdata;
|
||||
if(total_read >= PAUSE_READ_AFTER) {
|
||||
fprintf(stderr, "read_callback, return PAUSE\n");
|
||||
curl_mfprintf(stderr, "read_callback, return PAUSE\n");
|
||||
return CURL_READFUNC_PAUSE;
|
||||
}
|
||||
else {
|
||||
ptr[0] = '\n';
|
||||
++total_read;
|
||||
fprintf(stderr, "read_callback, return 1 byte\n");
|
||||
curl_mfprintf(stderr, "read_callback, return 1 byte\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -70,8 +70,8 @@ static int progress_callback(void *clientp,
|
|||
static void usage_upload_pausing(const char *msg)
|
||||
{
|
||||
if(msg)
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fprintf(stderr,
|
||||
curl_mfprintf(stderr, "%s\n", msg);
|
||||
curl_mfprintf(stderr,
|
||||
"usage: [options] url\n"
|
||||
" upload and pause, options:\n"
|
||||
" -V http_version (http/1.1, h2, h3) http version to use\n"
|
||||
|
|
@ -123,19 +123,19 @@ static int test_upload_pausing(int argc, char *argv[])
|
|||
|
||||
cu = curl_url();
|
||||
if(!cu) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
curl_mfprintf(stderr, "out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
if(curl_url_set(cu, CURLUPART_URL, url, 0)) {
|
||||
fprintf(stderr, "not a URL: '%s'\n", url);
|
||||
curl_mfprintf(stderr, "not a URL: '%s'\n", url);
|
||||
return 1;
|
||||
}
|
||||
if(curl_url_get(cu, CURLUPART_HOST, &host, 0)) {
|
||||
fprintf(stderr, "could not get host of '%s'\n", url);
|
||||
curl_mfprintf(stderr, "could not get host of '%s'\n", url);
|
||||
return 1;
|
||||
}
|
||||
if(curl_url_get(cu, CURLUPART_PORT, &port, 0)) {
|
||||
fprintf(stderr, "could not get port of '%s'\n", url);
|
||||
curl_mfprintf(stderr, "could not get port of '%s'\n", url);
|
||||
return 1;
|
||||
}
|
||||
memset(&resolve, 0, sizeof(resolve));
|
||||
|
|
@ -145,7 +145,7 @@ static int test_upload_pausing(int argc, char *argv[])
|
|||
|
||||
curl = curl_easy_init();
|
||||
if(!curl) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
curl_mfprintf(stderr, "out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
/* We want to use our own read function. */
|
||||
|
|
|
|||
|
|
@ -30,30 +30,31 @@ static CURLcode check_recv(const struct curl_ws_frame *frame,
|
|||
return CURLE_OK;
|
||||
|
||||
if(frame->flags & CURLWS_CLOSE) {
|
||||
fprintf(stderr, "recv_data: unexpected CLOSE frame from server, "
|
||||
"got %ld bytes, offset=%ld, rflags %x\n",
|
||||
(long)nread, (long)r_offset, frame->flags);
|
||||
curl_mfprintf(stderr, "recv_data: unexpected CLOSE frame from server, "
|
||||
"got %ld bytes, offset=%ld, rflags %x\n",
|
||||
(long)nread, (long)r_offset, frame->flags);
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
if(!r_offset && !(frame->flags & CURLWS_BINARY)) {
|
||||
fprintf(stderr, "recv_data: wrong frame, got %ld bytes, offset=%ld, "
|
||||
"rflags %x\n",
|
||||
(long)nread, (long)r_offset, frame->flags);
|
||||
curl_mfprintf(stderr, "recv_data: wrong frame, got %ld bytes, offset=%ld, "
|
||||
"rflags %x\n",
|
||||
(long)nread, (long)r_offset, frame->flags);
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
if(frame->offset != (curl_off_t)r_offset) {
|
||||
fprintf(stderr, "recv_data: frame offset, expected %ld, got %ld\n",
|
||||
(long)r_offset, (long)frame->offset);
|
||||
curl_mfprintf(stderr, "recv_data: frame offset, expected %ld, got %ld\n",
|
||||
(long)r_offset, (long)frame->offset);
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
if(frame->bytesleft != (curl_off_t)(exp_len - r_offset - nread)) {
|
||||
fprintf(stderr, "recv_data: frame bytesleft, expected %ld, got %ld\n",
|
||||
(long)(exp_len - r_offset - nread), (long)frame->bytesleft);
|
||||
curl_mfprintf(stderr, "recv_data: frame bytesleft, "
|
||||
"expected %ld, got %ld\n",
|
||||
(long)(exp_len - r_offset - nread), (long)frame->bytesleft);
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
if(r_offset + nread > exp_len) {
|
||||
fprintf(stderr, "recv_data: data length, expected %ld, now at %ld\n",
|
||||
(long)exp_len, (long)(r_offset + nread));
|
||||
curl_mfprintf(stderr, "recv_data: data length, expected %ld, now at %ld\n",
|
||||
(long)exp_len, (long)(r_offset + nread));
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
return CURLE_OK;
|
||||
|
|
@ -91,9 +92,9 @@ static CURLcode data_echo(CURL *curl, size_t count,
|
|||
r = curl_ws_send(curl, sbuf, slen, &nwritten, 0, CURLWS_BINARY);
|
||||
sblock = (r == CURLE_AGAIN);
|
||||
if(!r || (r == CURLE_AGAIN)) {
|
||||
fprintf(stderr, "curl_ws_send(len=%ld) -> %d, %ld (%ld/%ld)\n",
|
||||
(long)slen, r, (long)nwritten,
|
||||
(long)(len - slen), (long)len);
|
||||
curl_mfprintf(stderr, "curl_ws_send(len=%ld) -> %d, %ld (%ld/%ld)\n",
|
||||
(long)slen, r, (long)nwritten,
|
||||
(long)(len - slen), (long)len);
|
||||
sbuf += nwritten;
|
||||
slen -= nwritten;
|
||||
}
|
||||
|
|
@ -112,8 +113,10 @@ static CURLcode data_echo(CURL *curl, size_t count,
|
|||
&nread, &frame);
|
||||
if(!r || (r == CURLE_AGAIN)) {
|
||||
rblock = (r == CURLE_AGAIN);
|
||||
fprintf(stderr, "curl_ws_recv(len=%ld) -> %d, %ld (%ld/%ld) \n",
|
||||
(long)rlen, r, (long)nread, (long)(len - rlen), (long)len);
|
||||
curl_mfprintf(stderr, "curl_ws_recv(len=%ld) -> %d, %ld (%ld/%ld) "
|
||||
"\n",
|
||||
(long)rlen, r, (long)nread, (long)(len - rlen),
|
||||
(long)len);
|
||||
if(!r) {
|
||||
r = check_recv(frame, len - rlen, nread, len);
|
||||
if(r)
|
||||
|
|
@ -132,7 +135,7 @@ static CURLcode data_echo(CURL *curl, size_t count,
|
|||
}
|
||||
|
||||
if(rblock && sblock) {
|
||||
fprintf(stderr, "EAGAIN, sleep, try again\n");
|
||||
curl_mfprintf(stderr, "EAGAIN, sleep, try again\n");
|
||||
#ifdef _WIN32
|
||||
Sleep(100);
|
||||
#elif defined(__TANDEM)
|
||||
|
|
@ -149,7 +152,7 @@ static CURLcode data_echo(CURL *curl, size_t count,
|
|||
}
|
||||
|
||||
if(memcmp(send_buf, recv_buf, len)) {
|
||||
fprintf(stderr, "recv_data: data differs\n");
|
||||
curl_mfprintf(stderr, "recv_data: data differs\n");
|
||||
dump("expected:", (unsigned char *)send_buf, len, 0);
|
||||
dump("received:", (unsigned char *)recv_buf, len, 0);
|
||||
r = CURLE_RECV_ERROR;
|
||||
|
|
@ -168,8 +171,8 @@ out:
|
|||
static void usage_ws_data(const char *msg)
|
||||
{
|
||||
if(msg)
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fprintf(stderr,
|
||||
curl_mfprintf(stderr, "%s\n", msg);
|
||||
curl_mfprintf(stderr,
|
||||
"usage: [options] url\n"
|
||||
" -m number minimum frame size\n"
|
||||
" -M number maximum frame size\n"
|
||||
|
|
@ -215,8 +218,8 @@ static int test_ws_data(int argc, char *argv[])
|
|||
plen_max = plen_min;
|
||||
|
||||
if(plen_max < plen_min) {
|
||||
fprintf(stderr, "maxlen must be >= minlen, got %ld-%ld\n",
|
||||
(long)plen_min, (long)plen_max);
|
||||
curl_mfprintf(stderr, "maxlen must be >= minlen, got %ld-%ld\n",
|
||||
(long)plen_min, (long)plen_max);
|
||||
res = CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
@ -239,7 +242,7 @@ static int test_ws_data(int argc, char *argv[])
|
|||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */
|
||||
res = curl_easy_perform(curl);
|
||||
fprintf(stderr, "curl_easy_perform() returned %u\n", (int)res);
|
||||
curl_mfprintf(stderr, "curl_easy_perform() returned %u\n", (int)res);
|
||||
if(res == CURLE_OK)
|
||||
res = data_echo(curl, count, plen_min, plen_max);
|
||||
|
||||
|
|
@ -254,7 +257,7 @@ cleanup:
|
|||
#else /* !CURL_DISABLE_WEBSOCKETS */
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
fprintf(stderr, "WebSockets not enabled in libcurl\n");
|
||||
curl_mfprintf(stderr, "WebSockets not enabled in libcurl\n");
|
||||
return 1;
|
||||
#endif /* CURL_DISABLE_WEBSOCKETS */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ static CURLcode ping(CURL *curl, const char *send_payload)
|
|||
CURLcode result =
|
||||
curl_ws_send(curl, send_payload, strlen(send_payload), &sent, 0,
|
||||
CURLWS_PING);
|
||||
fprintf(stderr,
|
||||
"ws: curl_ws_send returned %u, sent %u\n", (int)result, (int)sent);
|
||||
curl_mfprintf(stderr, "ws: curl_ws_send returned %u, sent %u\n",
|
||||
(int)result, (int)sent);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -42,24 +42,24 @@ static CURLcode recv_pong(CURL *curl, const char *expected_payload)
|
|||
char buffer[256];
|
||||
CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
|
||||
if(result) {
|
||||
fprintf(stderr, "ws: curl_ws_recv returned %u, received %ld\n",
|
||||
(int)result, (long)rlen);
|
||||
curl_mfprintf(stderr, "ws: curl_ws_recv returned %u, received %ld\n",
|
||||
(int)result, (long)rlen);
|
||||
return result;
|
||||
}
|
||||
|
||||
if(!(meta->flags & CURLWS_PONG)) {
|
||||
fprintf(stderr, "recv_pong: wrong frame, got %d bytes rflags %x\n",
|
||||
(int)rlen, meta->flags);
|
||||
curl_mfprintf(stderr, "recv_pong: wrong frame, got %d bytes rflags %x\n",
|
||||
(int)rlen, meta->flags);
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
|
||||
fprintf(stderr, "ws: got PONG back\n");
|
||||
curl_mfprintf(stderr, "ws: got PONG back\n");
|
||||
if(rlen == strlen(expected_payload) &&
|
||||
!memcmp(expected_payload, buffer, rlen)) {
|
||||
fprintf(stderr, "ws: got the same payload back\n");
|
||||
curl_mfprintf(stderr, "ws: got the same payload back\n");
|
||||
return CURLE_OK;
|
||||
}
|
||||
fprintf(stderr, "ws: did NOT get the same payload back\n");
|
||||
curl_mfprintf(stderr, "ws: did NOT get the same payload back\n");
|
||||
return CURLE_RECV_ERROR;
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ static CURLcode pingpong(CURL *curl, const char *payload)
|
|||
if(res)
|
||||
return res;
|
||||
for(i = 0; i < 10; ++i) {
|
||||
fprintf(stderr, "Receive pong\n");
|
||||
curl_mfprintf(stderr, "Receive pong\n");
|
||||
res = recv_pong(curl, payload);
|
||||
if(res == CURLE_AGAIN) {
|
||||
#ifdef _WIN32
|
||||
|
|
@ -106,7 +106,7 @@ static int test_ws_pingpong(int argc, char *argv[])
|
|||
const char *url, *payload;
|
||||
|
||||
if(argc != 3) {
|
||||
fprintf(stderr, "usage: ws-pingpong url payload\n");
|
||||
curl_mfprintf(stderr, "usage: ws-pingpong url payload\n");
|
||||
return 2;
|
||||
}
|
||||
url = argv[1];
|
||||
|
|
@ -123,7 +123,7 @@ static int test_ws_pingpong(int argc, char *argv[])
|
|||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */
|
||||
res = curl_easy_perform(curl);
|
||||
fprintf(stderr, "curl_easy_perform() returned %u\n", (int)res);
|
||||
curl_mfprintf(stderr, "curl_easy_perform() returned %u\n", (int)res);
|
||||
if(res == CURLE_OK)
|
||||
res = pingpong(curl, payload);
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ static int test_ws_pingpong(int argc, char *argv[])
|
|||
#else /* !CURL_DISABLE_WEBSOCKETS */
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
fprintf(stderr, "WebSockets not enabled in libcurl\n");
|
||||
curl_mfprintf(stderr, "WebSockets not enabled in libcurl\n");
|
||||
return 1;
|
||||
#endif /* CURL_DISABLE_WEBSOCKETS */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue