asyn.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #ifndef HEADER_CURL_ASYN_H
  2. #define HEADER_CURL_ASYN_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2022, 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.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. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include "curl_setup.h"
  27. #include "curl_addrinfo.h"
  28. struct addrinfo;
  29. struct hostent;
  30. struct Curl_easy;
  31. struct connectdata;
  32. struct Curl_dns_entry;
  33. /*
  34. * This header defines all functions in the internal asynch resolver interface.
  35. * All asynch resolvers need to provide these functions.
  36. * asyn-ares.c and asyn-thread.c are the current implementations of asynch
  37. * resolver backends.
  38. */
  39. /*
  40. * Curl_resolver_global_init()
  41. *
  42. * Called from curl_global_init() to initialize global resolver environment.
  43. * Returning anything else than CURLE_OK fails curl_global_init().
  44. */
  45. int Curl_resolver_global_init(void);
  46. /*
  47. * Curl_resolver_global_cleanup()
  48. * Called from curl_global_cleanup() to destroy global resolver environment.
  49. */
  50. void Curl_resolver_global_cleanup(void);
  51. /*
  52. * Curl_resolver_init()
  53. * Called from curl_easy_init() -> Curl_open() to initialize resolver
  54. * URL-state specific environment ('resolver' member of the UrlState
  55. * structure). Should fill the passed pointer by the initialized handler.
  56. * Returning anything else than CURLE_OK fails curl_easy_init() with the
  57. * correspondent code.
  58. */
  59. CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver);
  60. /*
  61. * Curl_resolver_cleanup()
  62. * Called from curl_easy_cleanup() -> Curl_close() to cleanup resolver
  63. * URL-state specific environment ('resolver' member of the UrlState
  64. * structure). Should destroy the handler and free all resources connected to
  65. * it.
  66. */
  67. void Curl_resolver_cleanup(void *resolver);
  68. /*
  69. * Curl_resolver_duphandle()
  70. * Called from curl_easy_duphandle() to duplicate resolver URL-state specific
  71. * environment ('resolver' member of the UrlState structure). Should
  72. * duplicate the 'from' handle and pass the resulting handle to the 'to'
  73. * pointer. Returning anything else than CURLE_OK causes failed
  74. * curl_easy_duphandle() call.
  75. */
  76. CURLcode Curl_resolver_duphandle(struct Curl_easy *easy, void **to,
  77. void *from);
  78. /*
  79. * Curl_resolver_cancel().
  80. *
  81. * It is called from inside other functions to cancel currently performing
  82. * resolver request. Should also free any temporary resources allocated to
  83. * perform a request. This never waits for resolver threads to complete.
  84. *
  85. * It is safe to call this when conn is in any state.
  86. */
  87. void Curl_resolver_cancel(struct Curl_easy *data);
  88. /*
  89. * Curl_resolver_kill().
  90. *
  91. * This acts like Curl_resolver_cancel() except it will block until any threads
  92. * associated with the resolver are complete. This never blocks for resolvers
  93. * that do not use threads. This is intended to be the "last chance" function
  94. * that cleans up an in-progress resolver completely (before its owner is about
  95. * to die).
  96. *
  97. * It is safe to call this when conn is in any state.
  98. */
  99. void Curl_resolver_kill(struct Curl_easy *data);
  100. /* Curl_resolver_getsock()
  101. *
  102. * This function is called from the multi_getsock() function. 'sock' is a
  103. * pointer to an array to hold the file descriptors, with 'numsock' being the
  104. * size of that array (in number of entries). This function is supposed to
  105. * return bitmask indicating what file descriptors (referring to array indexes
  106. * in the 'sock' array) to wait for, read/write.
  107. */
  108. int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *sock);
  109. /*
  110. * Curl_resolver_is_resolved()
  111. *
  112. * Called repeatedly to check if a previous name resolve request has
  113. * completed. It should also make sure to time-out if the operation seems to
  114. * take too long.
  115. *
  116. * Returns normal CURLcode errors.
  117. */
  118. CURLcode Curl_resolver_is_resolved(struct Curl_easy *data,
  119. struct Curl_dns_entry **dns);
  120. /*
  121. * Curl_resolver_wait_resolv()
  122. *
  123. * Waits for a resolve to finish. This function should be avoided since using
  124. * this risk getting the multi interface to "hang".
  125. *
  126. * If 'entry' is non-NULL, make it point to the resolved dns entry
  127. *
  128. * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved,
  129. * CURLE_OPERATION_TIMEDOUT if a time-out occurred, or other errors.
  130. */
  131. CURLcode Curl_resolver_wait_resolv(struct Curl_easy *data,
  132. struct Curl_dns_entry **dnsentry);
  133. /*
  134. * Curl_resolver_getaddrinfo() - when using this resolver
  135. *
  136. * Returns name information about the given hostname and port number. If
  137. * successful, the 'hostent' is returned and the forth argument will point to
  138. * memory we need to free after use. That memory *MUST* be freed with
  139. * Curl_freeaddrinfo(), nothing else.
  140. *
  141. * Each resolver backend must of course make sure to return data in the
  142. * correct format to comply with this.
  143. */
  144. struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
  145. const char *hostname,
  146. int port,
  147. int *waitp);
  148. #ifndef CURLRES_ASYNCH
  149. /* convert these functions if an asynch resolver isn't used */
  150. #define Curl_resolver_cancel(x) Curl_nop_stmt
  151. #define Curl_resolver_kill(x) Curl_nop_stmt
  152. #define Curl_resolver_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
  153. #define Curl_resolver_wait_resolv(x,y) CURLE_COULDNT_RESOLVE_HOST
  154. #define Curl_resolver_duphandle(x,y,z) CURLE_OK
  155. #define Curl_resolver_init(x,y) CURLE_OK
  156. #define Curl_resolver_global_init() CURLE_OK
  157. #define Curl_resolver_global_cleanup() Curl_nop_stmt
  158. #define Curl_resolver_cleanup(x) Curl_nop_stmt
  159. #endif
  160. #ifdef CURLRES_ASYNCH
  161. #define Curl_resolver_asynch() 1
  162. #else
  163. #define Curl_resolver_asynch() 0
  164. #endif
  165. /********** end of generic resolver interface functions *****************/
  166. #endif /* HEADER_CURL_ASYN_H */