xref: /curl/docs/libcurl/curl_multi_info_read.md (revision 5a488251)
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
13Added-in: 7.9.6
14---
15
16# NAME
17
18curl_multi_info_read - read multi stack information
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLMsg *curl_multi_info_read(CURLM *multi_handle, int *msgs_in_queue);
26~~~
27
28# DESCRIPTION
29
30Ask the multi handle if there are any messages from the individual
31transfers. Messages may include information such as an error code from the
32transfer or just the fact that a transfer is completed. More details on these
33should be written down as well.
34
35Repeated calls to this function returns a new struct each time, until a NULL
36is returned as a signal that there is no more to get at this point. The
37integer pointed to with *msgs_in_queue* contains the number of remaining
38messages after this function was called.
39
40When you fetch a message using this function, it is removed from the internal
41queue so calling this function again does not return the same message
42again. It instead returns new messages at each new invoke until the queue is
43emptied.
44
45**WARNING:** The data the returned pointer points to does not survive
46calling curl_multi_cleanup(3), curl_multi_remove_handle(3) or
47curl_easy_cleanup(3).
48
49The *CURLMsg* struct is simple and only contains basic information. If
50more involved information is wanted, the particular "easy handle" is present
51in that struct and can be used in subsequent regular
52curl_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~~~
64When **msg** is *CURLMSG_DONE*, the message identifies a transfer that
65is done, and then **result** contains the return code for the easy handle
66that just completed.
67
68At this point, there are no other **msg** types defined.
69
70# %PROTOCOLS%
71
72# EXAMPLE
73
74~~~c
75int 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
103A pointer to a filled-in struct, or NULL if it failed or ran out of
104structs. It also writes the number of messages left in the queue (after this
105read) in the integer the second argument points to.
106