1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: curl_multi_info_read 5Section: 3 6Source: libcurl 7See-also: 8 - curl_multi_cleanup (3) 9 - curl_multi_init (3) 10 - curl_multi_perform (3) 11--- 12 13# NAME 14 15curl_multi_info_read - read multi stack information 16 17# SYNOPSIS 18 19~~~c 20#include <curl/curl.h> 21 22CURLMsg *curl_multi_info_read(CURLM *multi_handle, int *msgs_in_queue); 23~~~ 24 25# DESCRIPTION 26 27Ask the multi handle if there are any messages from the individual 28transfers. Messages may include information such as an error code from the 29transfer or just the fact that a transfer is completed. More details on these 30should be written down as well. 31 32Repeated calls to this function returns a new struct each time, until a NULL 33is returned as a signal that there is no more to get at this point. The 34integer pointed to with *msgs_in_queue* contains the number of remaining 35messages after this function was called. 36 37When you fetch a message using this function, it is removed from the internal 38queue so calling this function again does not return the same message 39again. It instead returns new messages at each new invoke until the queue is 40emptied. 41 42**WARNING:** The data the returned pointer points to does not survive 43calling curl_multi_cleanup(3), curl_multi_remove_handle(3) or 44curl_easy_cleanup(3). 45 46The *CURLMsg* struct is simple and only contains basic information. If 47more involved information is wanted, the particular "easy handle" is present 48in that struct and can be used in subsequent regular 49curl_easy_getinfo(3) calls (or similar): 50 51~~~c 52 struct CURLMsg { 53 CURLMSG msg; /* what this message means */ 54 CURL *easy_handle; /* the handle it concerns */ 55 union { 56 void *whatever; /* message-specific data */ 57 CURLcode result; /* return code for transfer */ 58 } data; 59 }; 60~~~ 61When **msg** is *CURLMSG_DONE*, the message identifies a transfer that 62is done, and then **result** contains the return code for the easy handle 63that just completed. 64 65At this point, there are no other **msg** types defined. 66 67# EXAMPLE 68 69~~~c 70int main(void) 71{ 72 CURLM *multi = curl_multi_init(); 73 CURL *curl = curl_easy_init(); 74 if(curl) { 75 struct CURLMsg *m; 76 77 /* call curl_multi_perform or curl_multi_socket_action first, then loop 78 through and check if there are any transfers that have completed */ 79 80 do { 81 int msgq = 0; 82 m = curl_multi_info_read(multi, &msgq); 83 if(m && (m->msg == CURLMSG_DONE)) { 84 CURL *e = m->easy_handle; 85 /* m->data.result holds the error code for the transfer */ 86 curl_multi_remove_handle(multi, e); 87 curl_easy_cleanup(e); 88 } 89 } while(m); 90 } 91} 92~~~ 93 94# AVAILABILITY 95 96Added in 7.9.6 97 98# RETURN VALUE 99 100A pointer to a filled-in struct, or NULL if it failed or ran out of 101structs. It also writes the number of messages left in the queue (after this 102read) in the integer the second argument points to. 103