connect.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef HEADER_CURL_CONNECT_H
  2. #define HEADER_CURL_CONNECT_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 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 "nonblock.h" /* for curlx_nonblock(), formerly Curl_nonblock() */
  28. #include "sockaddr.h"
  29. #include "timeval.h"
  30. struct Curl_dns_entry;
  31. struct ip_quadruple;
  32. /* generic function that returns how much time there's left to run, according
  33. to the timeouts set */
  34. timediff_t Curl_timeleft(struct Curl_easy *data,
  35. struct curltime *nowp,
  36. bool duringconnect);
  37. #define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */
  38. #define DEFAULT_SHUTDOWN_TIMEOUT_MS (2 * 1000)
  39. void Curl_shutdown_start(struct Curl_easy *data, int sockindex,
  40. struct curltime *nowp);
  41. /* return how much time there's left to shutdown the connection at
  42. * sockindex. */
  43. timediff_t Curl_shutdown_timeleft(struct connectdata *conn, int sockindex,
  44. struct curltime *nowp);
  45. void Curl_shutdown_clear(struct Curl_easy *data, int sockindex);
  46. /* TRUE iff shutdown has been started */
  47. bool Curl_shutdown_started(struct Curl_easy *data, int sockindex);
  48. /*
  49. * Used to extract socket and connectdata struct for the most recent
  50. * transfer on the given Curl_easy.
  51. *
  52. * The returned socket will be CURL_SOCKET_BAD in case of failure!
  53. */
  54. curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
  55. struct connectdata **connp);
  56. bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
  57. char *addr, int *port);
  58. void Curl_persistconninfo(struct Curl_easy *data, struct connectdata *conn,
  59. struct ip_quadruple *ip);
  60. /*
  61. * Curl_conncontrol() marks the end of a connection/stream. The 'closeit'
  62. * argument specifies if it is the end of a connection or a stream.
  63. *
  64. * For stream-based protocols (such as HTTP/2), a stream close will not cause
  65. * a connection close. Other protocols will close the connection for both
  66. * cases.
  67. *
  68. * It sets the bit.close bit to TRUE (with an explanation for debug builds),
  69. * when the connection will close.
  70. */
  71. #define CONNCTRL_KEEP 0 /* undo a marked closure */
  72. #define CONNCTRL_CONNECTION 1
  73. #define CONNCTRL_STREAM 2
  74. void Curl_conncontrol(struct connectdata *conn,
  75. int closeit
  76. #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
  77. , const char *reason
  78. #endif
  79. );
  80. #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
  81. #define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM, y)
  82. #define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y)
  83. #define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP, y)
  84. #else /* if !DEBUGBUILD || CURL_DISABLE_VERBOSE_STRINGS */
  85. #define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM)
  86. #define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION)
  87. #define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP)
  88. #endif
  89. /**
  90. * Create a cfilter for making an "ip" connection to the
  91. * given address, using parameters from `conn`. The "ip" connection
  92. * can be a TCP socket, a UDP socket or even a QUIC connection.
  93. *
  94. * It MUST use only the supplied `ai` for its connection attempt.
  95. *
  96. * Such a filter may be used in "happy eyeball" scenarios, and its
  97. * `connect` implementation needs to support non-blocking. Once connected,
  98. * it MAY be installed in the connection filter chain to serve transfers.
  99. */
  100. typedef CURLcode cf_ip_connect_create(struct Curl_cfilter **pcf,
  101. struct Curl_easy *data,
  102. struct connectdata *conn,
  103. const struct Curl_addrinfo *ai,
  104. int transport);
  105. CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at,
  106. struct Curl_easy *data,
  107. const struct Curl_dns_entry *remotehost,
  108. int transport,
  109. int ssl_mode);
  110. /**
  111. * Setup the cfilters at `sockindex` in connection `conn`.
  112. * If no filter chain is installed yet, inspects the configuration
  113. * in `data` and `conn? to install a suitable filter chain.
  114. */
  115. CURLcode Curl_conn_setup(struct Curl_easy *data,
  116. struct connectdata *conn,
  117. int sockindex,
  118. const struct Curl_dns_entry *remotehost,
  119. int ssl_mode);
  120. extern struct Curl_cftype Curl_cft_happy_eyeballs;
  121. extern struct Curl_cftype Curl_cft_setup;
  122. #ifdef UNITTESTS
  123. void Curl_debug_set_transport_provider(int transport,
  124. cf_ip_connect_create *cf_create);
  125. #endif
  126. #endif /* HEADER_CURL_CONNECT_H */