1 | #ifndef HEADER_CURL_ASYN_H
|
---|
2 | #define HEADER_CURL_ASYN_H
|
---|
3 | /***************************************************************************
|
---|
4 | * _ _ ____ _
|
---|
5 | * Project ___| | | | _ \| |
|
---|
6 | * / __| | | | |_) | |
|
---|
7 | * | (__| |_| | _ <| |___
|
---|
8 | * \___|\___/|_| \_\_____|
|
---|
9 | *
|
---|
10 | * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
---|
11 | *
|
---|
12 | * This software is licensed as described in the file COPYING, which
|
---|
13 | * you should have received as part of this distribution. The terms
|
---|
14 | * are also available at https://curl.haxx.se/docs/copyright.html.
|
---|
15 | *
|
---|
16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
---|
17 | * copies of the Software, and permit persons to whom the Software is
|
---|
18 | * furnished to do so, under the terms of the COPYING file.
|
---|
19 | *
|
---|
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
---|
21 | * KIND, either express or implied.
|
---|
22 | *
|
---|
23 | ***************************************************************************/
|
---|
24 |
|
---|
25 | #include "curl_setup.h"
|
---|
26 | #include "curl_addrinfo.h"
|
---|
27 |
|
---|
28 | struct addrinfo;
|
---|
29 | struct hostent;
|
---|
30 | struct Curl_easy;
|
---|
31 | struct connectdata;
|
---|
32 | struct Curl_dns_entry;
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * This header defines all functions in the internal asynch resolver interface.
|
---|
36 | * All asynch resolvers need to provide these functions.
|
---|
37 | * asyn-ares.c and asyn-thread.c are the current implementations of asynch
|
---|
38 | * resolver backends.
|
---|
39 | */
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * Curl_resolver_global_init()
|
---|
43 | *
|
---|
44 | * Called from curl_global_init() to initialize global resolver environment.
|
---|
45 | * Returning anything else than CURLE_OK fails curl_global_init().
|
---|
46 | */
|
---|
47 | int Curl_resolver_global_init(void);
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * Curl_resolver_global_cleanup()
|
---|
51 | * Called from curl_global_cleanup() to destroy global resolver environment.
|
---|
52 | */
|
---|
53 | void Curl_resolver_global_cleanup(void);
|
---|
54 |
|
---|
55 | /*
|
---|
56 | * Curl_resolver_init()
|
---|
57 | * Called from curl_easy_init() -> Curl_open() to initialize resolver
|
---|
58 | * URL-state specific environment ('resolver' member of the UrlState
|
---|
59 | * structure). Should fill the passed pointer by the initialized handler.
|
---|
60 | * Returning anything else than CURLE_OK fails curl_easy_init() with the
|
---|
61 | * correspondent code.
|
---|
62 | */
|
---|
63 | CURLcode Curl_resolver_init(void **resolver);
|
---|
64 |
|
---|
65 | /*
|
---|
66 | * Curl_resolver_cleanup()
|
---|
67 | * Called from curl_easy_cleanup() -> Curl_close() to cleanup resolver
|
---|
68 | * URL-state specific environment ('resolver' member of the UrlState
|
---|
69 | * structure). Should destroy the handler and free all resources connected to
|
---|
70 | * it.
|
---|
71 | */
|
---|
72 | void Curl_resolver_cleanup(void *resolver);
|
---|
73 |
|
---|
74 | /*
|
---|
75 | * Curl_resolver_duphandle()
|
---|
76 | * Called from curl_easy_duphandle() to duplicate resolver URL-state specific
|
---|
77 | * environment ('resolver' member of the UrlState structure). Should
|
---|
78 | * duplicate the 'from' handle and pass the resulting handle to the 'to'
|
---|
79 | * pointer. Returning anything else than CURLE_OK causes failed
|
---|
80 | * curl_easy_duphandle() call.
|
---|
81 | */
|
---|
82 | int Curl_resolver_duphandle(void **to, void *from);
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * Curl_resolver_cancel().
|
---|
86 | *
|
---|
87 | * It is called from inside other functions to cancel currently performing
|
---|
88 | * resolver request. Should also free any temporary resources allocated to
|
---|
89 | * perform a request.
|
---|
90 | */
|
---|
91 | void Curl_resolver_cancel(struct connectdata *conn);
|
---|
92 |
|
---|
93 | /* Curl_resolver_getsock()
|
---|
94 | *
|
---|
95 | * This function is called from the multi_getsock() function. 'sock' is a
|
---|
96 | * pointer to an array to hold the file descriptors, with 'numsock' being the
|
---|
97 | * size of that array (in number of entries). This function is supposed to
|
---|
98 | * return bitmask indicating what file descriptors (referring to array indexes
|
---|
99 | * in the 'sock' array) to wait for, read/write.
|
---|
100 | */
|
---|
101 | int Curl_resolver_getsock(struct connectdata *conn, curl_socket_t *sock,
|
---|
102 | int numsocks);
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * Curl_resolver_is_resolved()
|
---|
106 | *
|
---|
107 | * Called repeatedly to check if a previous name resolve request has
|
---|
108 | * completed. It should also make sure to time-out if the operation seems to
|
---|
109 | * take too long.
|
---|
110 | *
|
---|
111 | * Returns normal CURLcode errors.
|
---|
112 | */
|
---|
113 | CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
|
---|
114 | struct Curl_dns_entry **dns);
|
---|
115 |
|
---|
116 | /*
|
---|
117 | * Curl_resolver_wait_resolv()
|
---|
118 | *
|
---|
119 | * waits for a resolve to finish. This function should be avoided since using
|
---|
120 | * this risk getting the multi interface to "hang".
|
---|
121 | *
|
---|
122 | * If 'entry' is non-NULL, make it point to the resolved dns entry
|
---|
123 | *
|
---|
124 | * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved, and
|
---|
125 | * CURLE_OPERATION_TIMEDOUT if a time-out occurred.
|
---|
126 |
|
---|
127 | */
|
---|
128 | CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
|
---|
129 | struct Curl_dns_entry **dnsentry);
|
---|
130 |
|
---|
131 | /*
|
---|
132 | * Curl_resolver_getaddrinfo() - when using this resolver
|
---|
133 | *
|
---|
134 | * Returns name information about the given hostname and port number. If
|
---|
135 | * successful, the 'hostent' is returned and the forth argument will point to
|
---|
136 | * memory we need to free after use. That memory *MUST* be freed with
|
---|
137 | * Curl_freeaddrinfo(), nothing else.
|
---|
138 | *
|
---|
139 | * Each resolver backend must of course make sure to return data in the
|
---|
140 | * correct format to comply with this.
|
---|
141 | */
|
---|
142 | Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
|
---|
143 | const char *hostname,
|
---|
144 | int port,
|
---|
145 | int *waitp);
|
---|
146 |
|
---|
147 | #ifndef CURLRES_ASYNCH
|
---|
148 | /* convert these functions if an asynch resolver isn't used */
|
---|
149 | #define Curl_resolver_cancel(x) Curl_nop_stmt
|
---|
150 | #define Curl_resolver_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
|
---|
151 | #define Curl_resolver_wait_resolv(x,y) CURLE_COULDNT_RESOLVE_HOST
|
---|
152 | #define Curl_resolver_getsock(x,y,z) 0
|
---|
153 | #define Curl_resolver_duphandle(x,y) CURLE_OK
|
---|
154 | #define Curl_resolver_init(x) CURLE_OK
|
---|
155 | #define Curl_resolver_global_init() CURLE_OK
|
---|
156 | #define Curl_resolver_global_cleanup() Curl_nop_stmt
|
---|
157 | #define Curl_resolver_cleanup(x) Curl_nop_stmt
|
---|
158 | #endif
|
---|
159 |
|
---|
160 | #ifdef CURLRES_ASYNCH
|
---|
161 | #define Curl_resolver_asynch() 1
|
---|
162 | #else
|
---|
163 | #define Curl_resolver_asynch() 0
|
---|
164 | #endif
|
---|
165 |
|
---|
166 |
|
---|
167 | /********** end of generic resolver interface functions *****************/
|
---|
168 | #endif /* HEADER_CURL_ASYN_H */
|
---|