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