00001 #ifndef HEADER_CURL_ASYN_H 00002 #define HEADER_CURL_ASYN_H 00003 /*************************************************************************** 00004 * _ _ ____ _ 00005 * Project ___| | | | _ \| | 00006 * / __| | | | |_) | | 00007 * | (__| |_| | _ <| |___ 00008 * \___|\___/|_| \_\_____| 00009 * 00010 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. 00011 * 00012 * This software is licensed as described in the file COPYING, which 00013 * you should have received as part of this distribution. The terms 00014 * are also available at https://curl.haxx.se/docs/copyright.html. 00015 * 00016 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 00017 * copies of the Software, and permit persons to whom the Software is 00018 * furnished to do so, under the terms of the COPYING file. 00019 * 00020 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 00021 * KIND, either express or implied. 00022 * 00023 ***************************************************************************/ 00024 00025 #include "curl_setup.h" 00026 #include "curl_addrinfo.h" 00027 00028 struct addrinfo; 00029 struct hostent; 00030 struct Curl_easy; 00031 struct connectdata; 00032 struct Curl_dns_entry; 00033 00034 /* 00035 * This header defines all functions in the internal asynch resolver interface. 00036 * All asynch resolvers need to provide these functions. 00037 * asyn-ares.c and asyn-thread.c are the current implementations of asynch 00038 * resolver backends. 00039 */ 00040 00041 /* 00042 * Curl_resolver_global_init() 00043 * 00044 * Called from curl_global_init() to initialize global resolver environment. 00045 * Returning anything else than CURLE_OK fails curl_global_init(). 00046 */ 00047 int Curl_resolver_global_init(void); 00048 00049 /* 00050 * Curl_resolver_global_cleanup() 00051 * Called from curl_global_cleanup() to destroy global resolver environment. 00052 */ 00053 void Curl_resolver_global_cleanup(void); 00054 00055 /* 00056 * Curl_resolver_init() 00057 * Called from curl_easy_init() -> Curl_open() to initialize resolver 00058 * URL-state specific environment ('resolver' member of the UrlState 00059 * structure). Should fill the passed pointer by the initialized handler. 00060 * Returning anything else than CURLE_OK fails curl_easy_init() with the 00061 * correspondent code. 00062 */ 00063 CURLcode Curl_resolver_init(void **resolver); 00064 00065 /* 00066 * Curl_resolver_cleanup() 00067 * Called from curl_easy_cleanup() -> Curl_close() to cleanup resolver 00068 * URL-state specific environment ('resolver' member of the UrlState 00069 * structure). Should destroy the handler and free all resources connected to 00070 * it. 00071 */ 00072 void Curl_resolver_cleanup(void *resolver); 00073 00074 /* 00075 * Curl_resolver_duphandle() 00076 * Called from curl_easy_duphandle() to duplicate resolver URL-state specific 00077 * environment ('resolver' member of the UrlState structure). Should 00078 * duplicate the 'from' handle and pass the resulting handle to the 'to' 00079 * pointer. Returning anything else than CURLE_OK causes failed 00080 * curl_easy_duphandle() call. 00081 */ 00082 int Curl_resolver_duphandle(void **to, void *from); 00083 00084 /* 00085 * Curl_resolver_cancel(). 00086 * 00087 * It is called from inside other functions to cancel currently performing 00088 * resolver request. Should also free any temporary resources allocated to 00089 * perform a request. 00090 */ 00091 void Curl_resolver_cancel(struct connectdata *conn); 00092 00093 /* Curl_resolver_getsock() 00094 * 00095 * This function is called from the multi_getsock() function. 'sock' is a 00096 * pointer to an array to hold the file descriptors, with 'numsock' being the 00097 * size of that array (in number of entries). This function is supposed to 00098 * return bitmask indicating what file descriptors (referring to array indexes 00099 * in the 'sock' array) to wait for, read/write. 00100 */ 00101 int Curl_resolver_getsock(struct connectdata *conn, curl_socket_t *sock, 00102 int numsocks); 00103 00104 /* 00105 * Curl_resolver_is_resolved() 00106 * 00107 * Called repeatedly to check if a previous name resolve request has 00108 * completed. It should also make sure to time-out if the operation seems to 00109 * take too long. 00110 * 00111 * Returns normal CURLcode errors. 00112 */ 00113 CURLcode Curl_resolver_is_resolved(struct connectdata *conn, 00114 struct Curl_dns_entry **dns); 00115 00116 /* 00117 * Curl_resolver_wait_resolv() 00118 * 00119 * waits for a resolve to finish. This function should be avoided since using 00120 * this risk getting the multi interface to "hang". 00121 * 00122 * If 'entry' is non-NULL, make it point to the resolved dns entry 00123 * 00124 * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved, and 00125 * CURLE_OPERATION_TIMEDOUT if a time-out occurred. 00126 00127 */ 00128 CURLcode Curl_resolver_wait_resolv(struct connectdata *conn, 00129 struct Curl_dns_entry **dnsentry); 00130 00131 /* 00132 * Curl_resolver_getaddrinfo() - when using this resolver 00133 * 00134 * Returns name information about the given hostname and port number. If 00135 * successful, the 'hostent' is returned and the forth argument will point to 00136 * memory we need to free after use. That memory *MUST* be freed with 00137 * Curl_freeaddrinfo(), nothing else. 00138 * 00139 * Each resolver backend must of course make sure to return data in the 00140 * correct format to comply with this. 00141 */ 00142 Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn, 00143 const char *hostname, 00144 int port, 00145 int *waitp); 00146 00147 #ifndef CURLRES_ASYNCH 00148 /* convert these functions if an asynch resolver isn't used */ 00149 #define Curl_resolver_cancel(x) Curl_nop_stmt 00150 #define Curl_resolver_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST 00151 #define Curl_resolver_wait_resolv(x,y) CURLE_COULDNT_RESOLVE_HOST 00152 #define Curl_resolver_getsock(x,y,z) 0 00153 #define Curl_resolver_duphandle(x,y) CURLE_OK 00154 #define Curl_resolver_init(x) CURLE_OK 00155 #define Curl_resolver_global_init() CURLE_OK 00156 #define Curl_resolver_global_cleanup() Curl_nop_stmt 00157 #define Curl_resolver_cleanup(x) Curl_nop_stmt 00158 #endif 00159 00160 #ifdef CURLRES_ASYNCH 00161 #define Curl_resolver_asynch() 1 00162 #else 00163 #define Curl_resolver_asynch() 0 00164 #endif 00165 00166 00167 /********** end of generic resolver interface functions *****************/ 00168 #endif /* HEADER_CURL_ASYN_H */