curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

help: curl_multi_info_read always return NULL

From: peng xu via curl-library <curl-library_at_cool.haxx.se>
Date: Thu, 19 Dec 2019 12:17:27 +0800 (CST)

What I did is to make a http2 post request, the code is below:
```
curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
bool support = (info->features & CURL_VERSION_HTTP2);

//create multi handle
CURLM *multi_handle = curl_multi_init();
//create sub handle
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
data_chunk_t chunk;
chunk.data = malloc(1); /* will be grown as needed by the realloc above */
chunk.size = 0; /* no data at this point */
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, &chunk);
/* set the same URL */
curl_easy_setopt(hnd, CURLOPT_URL, "ai-test.xfyousheng.com:91");

struct curl_slist* head = NULL;
head = curl_slist_append(head, boundary);
head = curl_slist_append(head, "Content-Disposition: form-data; name=\"metadata\"");
head = curl_slist_append(head, "Content-Type: application/json;charset=UTF-8");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, head);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, request_json->data);

/* please be verbose */
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(hnd, CURLOPT_DEBUGFUNCTION, my_trace);

/* HTTP/2 please */
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);

/* we use a self-signed test server, skip verification during debugging */
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);

/* wait for pipe connection to confirm */
curl_easy_setopt(hnd, CURLOPT_PIPEWAIT, 1L);

/* add the individual transfer */
curl_multi_add_handle(multi_handle, hnd);
curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
/* We do HTTP/2 so let's stick to one connection per host */
curl_multi_setopt(multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, 1L);
/* we start some action by calling perform right away */
int still_running = 0;
CURLMcode code = curl_multi_perform(multi_handle, &still_running);

struct CURLMsg *m;
do {
int msgq = 0;
m = curl_multi_info_read(multi_handle, &msgq);
if (m && (m->msg == CURLMSG_DONE)) {
CURL *e = m->easy_handle;
curl_multi_remove_handle(multi_handle, e);
curl_easy_cleanup(e);
}
} while (m);
```

The first two lines code showed me that this curl supports http2.
My question is in the while loop, curl_multi_info_read always return NULL, and my callback never get chance to be executed? What have I done ? And how to amend it?
Thanks very much

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-12-19