asyn.h 5.9 KB

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