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